From b04685e6a482c93dcf357aac5991c13cf76989f6 Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Thu, 27 Jun 2024 09:07:57 -0300 Subject: [PATCH 1/3] fix(thumbnails) - fix thumbnails uploads and catch error when the thumbnail generation fails --- .../lib/src/ardrive_uploader.dart | 10 ++- .../ardrive_uploader/lib/src/constants.dart | 8 +++ .../lib/src/data_bundler.dart | 63 ++++++++++--------- .../lib/src/upload_dispatcher.dart | 5 +- 4 files changed, 53 insertions(+), 33 deletions(-) diff --git a/packages/ardrive_uploader/lib/src/ardrive_uploader.dart b/packages/ardrive_uploader/lib/src/ardrive_uploader.dart index 0b6fe6a371..0c62d26f7a 100644 --- a/packages/ardrive_uploader/lib/src/ardrive_uploader.dart +++ b/packages/ardrive_uploader/lib/src/ardrive_uploader.dart @@ -2,6 +2,7 @@ import 'dart:async'; import 'package:ardrive_io/ardrive_io.dart'; import 'package:ardrive_uploader/ardrive_uploader.dart'; +import 'package:ardrive_uploader/src/constants.dart'; import 'package:ardrive_uploader/src/upload_dispatcher.dart'; import 'package:ardrive_uploader/src/utils/logger.dart'; import 'package:ardrive_utils/ardrive_utils.dart'; @@ -161,7 +162,8 @@ class _ArDriveUploader implements ArDriveUploader { encryptionKey: driveKey, type: type, uploadThumbnail: - FileTypeHelper.isImage(file.contentType) && uploadThumbnail, + supportedImageTypesForThumbnails.contains(file.contentType) && + uploadThumbnail, ); uploadController.addTask(uploadTask); @@ -225,7 +227,8 @@ class _ArDriveUploader implements ArDriveUploader { encryptionKey: driveKey, type: type, uploadThumbnail: - FileTypeHelper.isImage(f.$2.contentType) && uploadThumbnail, + supportedImageTypesForThumbnails.contains(f.$2.contentType) && + uploadThumbnail, ); uploadController.addTask(fileTask); @@ -316,7 +319,8 @@ class _ArDriveUploader implements ArDriveUploader { content: [f.$1], type: type, uploadThumbnail: - FileTypeHelper.isImage(f.$2.contentType) && uploadThumbnail, + supportedImageTypesForThumbnails.contains(f.$2.contentType) && + uploadThumbnail, ); uploadController.addTask(fileTask); diff --git a/packages/ardrive_uploader/lib/src/constants.dart b/packages/ardrive_uploader/lib/src/constants.dart index 5510e3d5fb..4d98239f61 100644 --- a/packages/ardrive_uploader/lib/src/constants.dart +++ b/packages/ardrive_uploader/lib/src/constants.dart @@ -4,3 +4,11 @@ final int maxSizeSupportedByGCMEncryption = MiB(100).size; final uContractId = TransactionID('KTzTXT_ANmF84fWEKHzWURD1LWd9QaFR9yfYUwH2Lxw'); + +const List supportedImageTypesForThumbnails = [ + 'image/jpeg', + 'image/png', + 'image/gif', + 'image/webp', + 'image/bmp', +]; diff --git a/packages/ardrive_uploader/lib/src/data_bundler.dart b/packages/ardrive_uploader/lib/src/data_bundler.dart index df98024ed9..0482720a93 100644 --- a/packages/ardrive_uploader/lib/src/data_bundler.dart +++ b/packages/ardrive_uploader/lib/src/data_bundler.dart @@ -677,40 +677,45 @@ Future prepareDataItems({ /// Thumbnail generation if (addThumbnail) { - final thumbnailGenerationResult = await generateThumbnail( - await file.readAsBytes(), - ThumbnailSize.small, - ); + try { + final thumbnailGenerationResult = await generateThumbnail( + await file.readAsBytes(), + ThumbnailSize.small, + ); - thumbnailFile = await IOFile.fromData( - thumbnailGenerationResult.thumbnail, - name: 'thumbnail', - lastModifiedDate: DateTime.now(), - contentType: 'image/jpeg', - ); + thumbnailFile = await IOFile.fromData( + thumbnailGenerationResult.thumbnail, + name: 'thumbnail', + lastModifiedDate: DateTime.now(), + contentType: 'image/jpeg', + ); - final thumbnailMetadata = ThumbnailUploadMetadata( - height: thumbnailGenerationResult.height, - width: thumbnailGenerationResult.width, - size: thumbnailGenerationResult.thumbnail.length, - name: thumbnailGenerationResult.name, - relatesTo: metadata.dataTxId!, - contentType: 'image/jpeg', - originalFileId: metadata.id, - ); + final thumbnailMetadata = ThumbnailUploadMetadata( + height: thumbnailGenerationResult.height, + width: thumbnailGenerationResult.width, + size: thumbnailGenerationResult.thumbnail.length, + name: thumbnailGenerationResult.name, + relatesTo: metadata.dataTxId!, + contentType: 'image/jpeg', + originalFileId: metadata.id, + ); - thumbnailDataItem = await createDataItemForThumbnail( - file: thumbnailFile, - metadata: thumbnailMetadata, - wallet: wallet, - encryptionKey: key, - fileId: metadata.id, - ); + thumbnailDataItem = await createDataItemForThumbnail( + file: thumbnailFile, + metadata: thumbnailMetadata, + wallet: wallet, + encryptionKey: key, + fileId: metadata.id, + ); - thumbnailMetadata.setTxId = thumbnailDataItem.id; + thumbnailMetadata.setTxId = thumbnailDataItem.id; - /// needs to be `variants` - metadata.updateThumbnailInfo([thumbnailMetadata]); + /// needs to be `variants` + metadata.updateThumbnailInfo([thumbnailMetadata]); + } catch (e) { + logger.e( + 'Error generating thumbnail. We will proceed with the upload.', e); + } } onStartMetadataCreation?.call(); diff --git a/packages/ardrive_uploader/lib/src/upload_dispatcher.dart b/packages/ardrive_uploader/lib/src/upload_dispatcher.dart index d2b3a7865d..83e634aea9 100644 --- a/packages/ardrive_uploader/lib/src/upload_dispatcher.dart +++ b/packages/ardrive_uploader/lib/src/upload_dispatcher.dart @@ -91,7 +91,10 @@ class UploadDispatcher { verifyCancel: verifyCancel, ); } catch (e) { - logger.e('Error uploading thumbnail: $e'); + logger.e( + 'Error uploading thumbnail. The file upload wont be affected.', + e, + ); } } From 8475ec4baeb608ae76c43e62b08515e63ed95466 Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Thu, 27 Jun 2024 09:15:00 -0300 Subject: [PATCH 2/3] Update data_bundler.dart --- packages/ardrive_uploader/lib/src/data_bundler.dart | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/ardrive_uploader/lib/src/data_bundler.dart b/packages/ardrive_uploader/lib/src/data_bundler.dart index 0482720a93..202982b00d 100644 --- a/packages/ardrive_uploader/lib/src/data_bundler.dart +++ b/packages/ardrive_uploader/lib/src/data_bundler.dart @@ -710,7 +710,6 @@ Future prepareDataItems({ thumbnailMetadata.setTxId = thumbnailDataItem.id; - /// needs to be `variants` metadata.updateThumbnailInfo([thumbnailMetadata]); } catch (e) { logger.e( From 6bab5759173b4261c2e3daa9c293014d497b8483 Mon Sep 17 00:00:00 2001 From: Thiago Carvalho <32248947+thiagocarvalhodev@users.noreply.github.com> Date: Thu, 27 Jun 2024 09:25:18 -0300 Subject: [PATCH 3/3] delete empty file and bump version --- android/fastlane/metadata/android/en-US/changelogs/132.txt | 1 + lib/utils/file_type_helper.dart | 0 pubspec.yaml | 2 +- 3 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 android/fastlane/metadata/android/en-US/changelogs/132.txt delete mode 100644 lib/utils/file_type_helper.dart diff --git a/android/fastlane/metadata/android/en-US/changelogs/132.txt b/android/fastlane/metadata/android/en-US/changelogs/132.txt new file mode 100644 index 0000000000..d687770186 --- /dev/null +++ b/android/fastlane/metadata/android/en-US/changelogs/132.txt @@ -0,0 +1 @@ +- Fixes an issue with creating thumbnails for non-supported image extensions \ No newline at end of file diff --git a/lib/utils/file_type_helper.dart b/lib/utils/file_type_helper.dart deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/pubspec.yaml b/pubspec.yaml index a775ec289a..4ac3bfa4e5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -3,7 +3,7 @@ description: Secure, permanent storage publish_to: 'none' -version: 2.48.0 +version: 2.48.1 environment: sdk: '>=3.2.0 <4.0.0'