Skip to content

Commit

Permalink
Merge pull request #1771 from ardriveapp/PE-6360-continue-uploads-des…
Browse files Browse the repository at this point in the history
…pite-thumbnail-generation-failures

PE-6360: fix(thumbnails)
  • Loading branch information
thiagocarvalhodev authored Jun 27, 2024
2 parents 9de0338 + 6bab575 commit 733d615
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 34 deletions.
1 change: 1 addition & 0 deletions android/fastlane/metadata/android/en-US/changelogs/132.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixes an issue with creating thumbnails for non-supported image extensions
Empty file removed lib/utils/file_type_helper.dart
Empty file.
10 changes: 7 additions & 3 deletions packages/ardrive_uploader/lib/src/ardrive_uploader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 8 additions & 0 deletions packages/ardrive_uploader/lib/src/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,11 @@ final int maxSizeSupportedByGCMEncryption = MiB(100).size;

final uContractId =
TransactionID('KTzTXT_ANmF84fWEKHzWURD1LWd9QaFR9yfYUwH2Lxw');

const List<String> supportedImageTypesForThumbnails = [
'image/jpeg',
'image/png',
'image/gif',
'image/webp',
'image/bmp',
];
62 changes: 33 additions & 29 deletions packages/ardrive_uploader/lib/src/data_bundler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -677,40 +677,44 @@ Future<UploadFilePreparation> 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]);
metadata.updateThumbnailInfo([thumbnailMetadata]);
} catch (e) {
logger.e(
'Error generating thumbnail. We will proceed with the upload.', e);
}
}

onStartMetadataCreation?.call();
Expand Down
5 changes: 4 additions & 1 deletion packages/ardrive_uploader/lib/src/upload_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 733d615

Please sign in to comment.