From 6340d9f64616b7c25e477eece2f00d8e9ffc305b Mon Sep 17 00:00:00 2001 From: Neeraj Gupta <254676+ua741@users.noreply.github.com> Date: Fri, 4 Jul 2025 09:37:17 +0530 Subject: [PATCH] Simplify --- mobile/lib/utils/file_uploader.dart | 14 +++--- mobile/lib/utils/upload_metadata.dart | 66 ++++++++++++++------------- 2 files changed, 40 insertions(+), 40 deletions(-) diff --git a/mobile/lib/utils/file_uploader.dart b/mobile/lib/utils/file_uploader.dart index ae72ab906b..1fa970e6e8 100644 --- a/mobile/lib/utils/file_uploader.dart +++ b/mobile/lib/utils/file_uploader.dart @@ -707,7 +707,6 @@ class FileUploader { await getMetadata(mediaUploadData, exifTime, file); final Map pubMetadata = buildPublicMagicData(mediaUploadData, exifTime, file.rAsset); - MetadataRequest? pubMetadataRequest; final encryptedMetadataResult = await CryptoUtil.encryptChaCha( utf8.encode(jsonEncode(metadata)), @@ -719,13 +718,12 @@ class FileUploader { final metadataDecryptionHeader = CryptoUtil.bin2base64(encryptedMetadataResult.header!); - if (pubMetadata.isNotEmpty) { - pubMetadataRequest = await getPubMetadataRequest( - file, - pubMetadata, - fileEncryptResult.key!, - ); - } + final MetadataRequest? pubMetadataRequest = await getPubMetadataRequest( + file, + pubMetadata, + fileEncryptResult.key!, + ); + final fileDecryptionHeader = CryptoUtil.bin2base64(fileEncryptResult.header!); final thumbnailDecryptionHeader = diff --git a/mobile/lib/utils/upload_metadata.dart b/mobile/lib/utils/upload_metadata.dart index 2eb6da7a59..5ea5c5c12e 100644 --- a/mobile/lib/utils/upload_metadata.dart +++ b/mobile/lib/utils/upload_metadata.dart @@ -235,44 +235,46 @@ Future> getMetadata( } Map buildPublicMagicData( - MediaUploadData mediaUploadData, - ParsedExifDateTime? exifTime, - RemoteAsset? rAsset, - ) { - final Map pubMetadata = {}; - if ((mediaUploadData.height ?? 0) != 0 && - (mediaUploadData.width ?? 0) != 0) { - pubMetadata[heightKey] = mediaUploadData.height; - pubMetadata[widthKey] = mediaUploadData.width; - } - pubMetadata[mediaTypeKey] = mediaUploadData.isPanorama == true ? 1 : 0; - if (mediaUploadData.motionPhotoStartIndex != null) { - pubMetadata[motionVideoIndexKey] = mediaUploadData.motionPhotoStartIndex; - } - if (mediaUploadData.thumbnail == null) { - pubMetadata[noThumbKey] = true; - } - if (exifTime != null) { - if (exifTime.dateTime != null) { - pubMetadata[dateTimeKey] = exifTime.dateTime; - } - if (exifTime.offsetTime != null) { - pubMetadata[offsetTimeKey] = exifTime.offsetTime; - } - } - final Map jsonToUpdate = - rAsset?.publicMetadata?.data ?? {}; - pubMetadata.forEach((key, value) { - jsonToUpdate[key] = value; - }); - return jsonToUpdate; + MediaUploadData mediaUploadData, + ParsedExifDateTime? exifTime, + RemoteAsset? rAsset, +) { + final Map pubMetadata = {}; + if ((mediaUploadData.height ?? 0) != 0 && (mediaUploadData.width ?? 0) != 0) { + pubMetadata[heightKey] = mediaUploadData.height; + pubMetadata[widthKey] = mediaUploadData.width; } + pubMetadata[mediaTypeKey] = mediaUploadData.isPanorama == true ? 1 : 0; + if (mediaUploadData.motionPhotoStartIndex != null) { + pubMetadata[motionVideoIndexKey] = mediaUploadData.motionPhotoStartIndex; + } + if (mediaUploadData.thumbnail == null) { + pubMetadata[noThumbKey] = true; + } + if (exifTime != null) { + if (exifTime.dateTime != null) { + pubMetadata[dateTimeKey] = exifTime.dateTime; + } + if (exifTime.offsetTime != null) { + pubMetadata[offsetTimeKey] = exifTime.offsetTime; + } + } + final Map jsonToUpdate = + rAsset?.publicMetadata?.data ?? {}; + pubMetadata.forEach((key, value) { + jsonToUpdate[key] = value; + }); + return jsonToUpdate; +} -Future getPubMetadataRequest( +Future getPubMetadataRequest( EnteFile file, Map jsonToUpdate, Uint8List fileKey, ) async { + if (jsonToUpdate.isEmpty) { + return null; + } final int currentVersion = (file.rAsset?.publicMetadata?.version ?? 0); final encryptedMMd = await CryptoUtil.encryptChaCha( utf8.encode(jsonEncode(jsonToUpdate)),