π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
[mob] Refactor
Neeraj Guptaff72dae40808
diff --git a/mobile/lib/models/file/file.dart b/mobile/lib/models/file/file.dartindex 937bee0cb1..9f3d561315 100644--- a/mobile/lib/models/file/file.dart+++ b/mobile/lib/models/file/file.dart@@ -175,10 +175,10 @@ class EnteFile {final exifData = await getExifFromSourceFile(mediaUploadData.sourceFile!);if (exifData != null) {if (fileType == FileType.image) {- final exifTime = await getCreationTimeFromEXIF(null, exifData);- if (exifTime != null) {+ final dateResult = await tryParseExifDateTime(null, exifData);+ if (dateResult != null && dateResult.time != null) {hasExifTime = true;- creationTime = exifTime.microsecondsSinceEpoch;+ creationTime = dateResult.time!.microsecondsSinceEpoch;}mediaUploadData.isPanorama = checkPanoramaFromEXIF(null, exifData);diff --git a/mobile/lib/utils/exif_util.dart b/mobile/lib/utils/exif_util.dartindex 45741f07b6..940ffed644 100644--- a/mobile/lib/utils/exif_util.dart+++ b/mobile/lib/utils/exif_util.dart@@ -125,7 +125,14 @@ bool? checkPanoramaFromEXIF(File? file, Map<String, IfdTag>? exifData) {return element?.printable == "6";}-Future<DateTime?> getCreationTimeFromEXIF(+class ParsedExifDateTime {+ final DateTime? time;+ final String? dateTime;+ final String? offsetTime;+ ParsedExifDateTime(this.time, this.dateTime, this.offsetTime);+}++Future<ParsedExifDateTime?> tryParseExifDateTime(File? file,Map<String, IfdTag>? exifData,) async {@@ -153,28 +160,38 @@ Future<DateTime?> getCreationTimeFromEXIF(return null;}-DateTime getDateTimeInDeviceTimezone(String exifTime, String? offsetString) {+ParsedExifDateTime getDateTimeInDeviceTimezone(+ String exifTime,+ String? offsetString,+) {final shouldParseDateInUTCTimeZone = offsetString != null;final DateTime result = DateFormat(kExifDateTimePattern).parse(exifTime, shouldParseDateInUTCTimeZone);- if (offsetString == null) {- return result;- }- try {- final List<String> splitHHMM = offsetString.split(":");- final int offsetHours = int.parse(splitHHMM[0]);- final int offsetMinutes =- int.parse(splitHHMM[1]) * (offsetHours.isNegative ? -1 : 1);- // Adjust the date for the offset to get the photo's correct UTC time- final photoUtcDate =- result.add(Duration(hours: -offsetHours, minutes: -offsetMinutes));- // Convert the UTC time to the device's local time- final deviceLocalTime = photoUtcDate.toLocal();- return deviceLocalTime;- } catch (e, s) {- _logger.severe("tz offset adjust failed $offsetString", e, s);+ if (offsetString != null && (offsetString ?? '').toUpperCase() != "Z") {+ try {+ final List<String> splitHHMM = offsetString.split(":");+ final int offsetHours = int.parse(splitHHMM[0]);+ final int offsetMinutes =+ int.parse(splitHHMM[1]) * (offsetHours.isNegative ? -1 : 1);+ // Adjust the date for the offset to get the photo's correct UTC time+ final photoUtcDate =+ result.add(Duration(hours: -offsetHours, minutes: -offsetMinutes));+ // Convert the UTC time to the device's local time+ final deviceLocalTime = photoUtcDate.toLocal();+ return ParsedExifDateTime(+ deviceLocalTime,+ result.toIso8601String(),+ offsetString,+ );+ } catch (e, s) {+ _logger.severe("tz offset adjust failed $offsetString", e, s);+ }}- return result;+ return ParsedExifDateTime(+ result,+ result.toIso8601String(),+ (offsetString ?? '').toUpperCase() == 'Z' ? 'Z' : null,+ );}Location? locationFromExif(Map<String, IfdTag> exif) {diff --git a/mobile/lib/utils/share_util.dart b/mobile/lib/utils/share_util.dartindex c39d1733b9..3ec147798d 100644--- a/mobile/lib/utils/share_util.dart+++ b/mobile/lib/utils/share_util.dart@@ -165,9 +165,9 @@ Future<List<EnteFile>> convertIncomingSharedMediaToFile(enteFile.fileType =media.type == SharedMediaType.image ? FileType.image : FileType.video;if (enteFile.fileType == FileType.image) {- final exifTime = await getCreationTimeFromEXIF(ioFile, null);- if (exifTime != null) {- enteFile.creationTime = exifTime.microsecondsSinceEpoch;+ final dateResult = await tryParseExifDateTime(ioFile, null);+ if (dateResult != null && dateResult.time != null) {+ enteFile.creationTime = dateResult.time!.microsecondsSinceEpoch;}} else if (enteFile.fileType == FileType.video) {enteFile.duration = (media.duration ?? 0) ~/ 1000;