From 9934760fe341bb9fb81202f937fbe895061dd8d5 Mon Sep 17 00:00:00 2001 From: --global Date: Tue, 20 Aug 2024 10:29:49 +0700 Subject: [PATCH 1/8] TW-2001: upload thumbnail file instead of real file --- lib/presentation/extensions/send_file_web_extension.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/presentation/extensions/send_file_web_extension.dart b/lib/presentation/extensions/send_file_web_extension.dart index a2a9a66afb..50746391fd 100644 --- a/lib/presentation/extensions/send_file_web_extension.dart +++ b/lib/presentation/extensions/send_file_web_extension.dart @@ -169,7 +169,7 @@ extension SendFileWebExtension on Room { : null; if (uploadThumbnail != null && uploadThumbnail.bytes != null) { final uploadThumbnailResponse = await mediaApi.uploadFileWeb( - file: file, + file: uploadThumbnail, cancelToken: cancelToken, onSendProgress: (receive, total) { uploadStreamController?.add( From de354b053dc815f43d477e9ae1fb641b713236bb Mon Sep 17 00:00:00 2001 From: --global Date: Tue, 20 Aug 2024 10:30:45 +0700 Subject: [PATCH 2/8] TW-2001: add mimeType for thumbnail when sending video --- .../extensions/send_file_extension.dart | 10 ++++++++-- .../extensions/send_file_web_extension.dart | 14 ++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/presentation/extensions/send_file_extension.dart b/lib/presentation/extensions/send_file_extension.dart index 0dd435204d..61a89d88fb 100644 --- a/lib/presentation/extensions/send_file_extension.dart +++ b/lib/presentation/extensions/send_file_extension.dart @@ -25,6 +25,7 @@ import 'package:image/image.dart' as img; import 'package:blurhash_dart/blurhash_dart.dart'; import 'package:flutter/foundation.dart'; import 'package:matrix/matrix.dart'; +import 'package:mime/mime.dart'; import 'package:path_provider/path_provider.dart'; import 'package:flutter_image_compress/flutter_image_compress.dart'; import 'package:video_thumbnail/video_thumbnail.dart'; @@ -628,10 +629,13 @@ extension SendFileExtension on Room { height = imageDimension.height.toInt(); } uploadStreamController?.add(const Right(GenerateThumbnailSuccess())); + final newFileName = + '${result.name}.${AppConfig.imageCompressFormmat.name}'; return ImageFileInfo( - '${result.name}.${AppConfig.imageCompressFormmat.name}', + newFileName, result.path, size, + customMimeType: lookupMimeType(newFileName) ?? 'image/jpeg', width: width, height: height, ); @@ -706,9 +710,11 @@ extension SendFileExtension on Room { } Logs().d('Video thumbnail generated', tempThumbnailFile.path); uploadStreamController?.add(const Right(GenerateThumbnailSuccess())); + final newFileName = '${tempThumbnailFile.path.split("/").last}.jpg'; final newThumbnail = ImageFileInfo( - tempThumbnailFile.path.split("/").last, + newFileName, tempThumbnailFile.path, + customMimeType: lookupMimeType(newFileName) ?? 'image/jpeg', fileSize, width: width, height: height, diff --git a/lib/presentation/extensions/send_file_web_extension.dart b/lib/presentation/extensions/send_file_web_extension.dart index 50746391fd..448e1a48a1 100644 --- a/lib/presentation/extensions/send_file_web_extension.dart +++ b/lib/presentation/extensions/send_file_web_extension.dart @@ -19,6 +19,7 @@ import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dar import 'package:flutter_image_compress/flutter_image_compress.dart'; import 'package:matrix/matrix.dart'; import 'package:image/image.dart'; +import 'package:mime/mime.dart'; import 'package:video_player/video_player.dart'; import 'package:video_thumbnail/video_thumbnail.dart'; @@ -109,7 +110,10 @@ extension SendFileWebExtension on Room { .unsigned![fileSendingStatusKey] = FileSendingStatus.generatingThumbnail.name; await handleImageFakeSync(fakeImageEvent); - thumbnail ??= await generateVideoThumbnail(file); + thumbnail ??= await generateVideoThumbnail( + file, + uploadStreamController: uploadStreamController, + ); } EncryptedFile? encryptedFile; @@ -442,11 +446,13 @@ extension SendFileWebExtension on Room { const Right(GenerateThumbnailSuccess()), ); + final thumbnailFileName = + '${originalFile.name}.${AppConfig.videoThumbnailFormat.name.toLowerCase()}'; + return MatrixImageFile( bytes: result, - name: - '${originalFile.name}.${AppConfig.videoThumbnailFormat.name.toLowerCase()}', - mimeType: originalFile.mimeType, + name: thumbnailFileName, + mimeType: lookupMimeType(thumbnailFileName) ?? 'image/jpeg', width: thumbnailBitmap?.width, height: thumbnailBitmap?.height, blurhash: blurHash, From f9dd0458bdae86159fee8c18f671145f988ec282 Mon Sep 17 00:00:00 2001 From: --global Date: Thu, 29 Aug 2024 13:46:31 +0700 Subject: [PATCH 3/8] fixup! TW-2001: add mimeType for thumbnail when sending video --- lib/presentation/extensions/send_file_web_extension.dart | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/presentation/extensions/send_file_web_extension.dart b/lib/presentation/extensions/send_file_web_extension.dart index 448e1a48a1..aded121a9e 100644 --- a/lib/presentation/extensions/send_file_web_extension.dart +++ b/lib/presentation/extensions/send_file_web_extension.dart @@ -110,10 +110,7 @@ extension SendFileWebExtension on Room { .unsigned![fileSendingStatusKey] = FileSendingStatus.generatingThumbnail.name; await handleImageFakeSync(fakeImageEvent); - thumbnail ??= await generateVideoThumbnail( - file, - uploadStreamController: uploadStreamController, - ); + thumbnail ??= await generateVideoThumbnail(file); } EncryptedFile? encryptedFile; From 549c174429764aba9555cfdce58bf38ca92b967a Mon Sep 17 00:00:00 2001 From: --global Date: Thu, 29 Aug 2024 15:23:13 +0700 Subject: [PATCH 4/8] fixup! fixup! TW-2001: add mimeType for thumbnail when sending video --- .../extensions/send_file_extension.dart | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/lib/presentation/extensions/send_file_extension.dart b/lib/presentation/extensions/send_file_extension.dart index 61a89d88fb..ddc025f802 100644 --- a/lib/presentation/extensions/send_file_extension.dart +++ b/lib/presentation/extensions/send_file_extension.dart @@ -94,17 +94,16 @@ extension SendFileExtension on Room { } final formattedDateTime = DateTime.now().getFormattedCurrentDateTime(); - final targetPath = - await File('${tempDir.path}/$formattedDateTime${fileInfo.fileName}') - .create(); - fileInfo = fileInfo as ImageFileInfo; + final fileName = + '$formattedDateTime${fileInfo.fileName}.${AppConfig.imageCompressFormmat.name}'; + final targetPath = await File('${tempDir.path}/$fileName').create(); await _generateThumbnail( - fileInfo, + fileInfo as ImageFileInfo, targetPath: targetPath.path, uploadStreamController: uploadStreamController, ); thumbnail = ImageFileInfo( - fileInfo.fileName, + fileName, targetPath.path, await targetPath.length(), width: fileInfo.width, @@ -629,13 +628,10 @@ extension SendFileExtension on Room { height = imageDimension.height.toInt(); } uploadStreamController?.add(const Right(GenerateThumbnailSuccess())); - final newFileName = - '${result.name}.${AppConfig.imageCompressFormmat.name}'; return ImageFileInfo( - newFileName, + result.name, result.path, size, - customMimeType: lookupMimeType(newFileName) ?? 'image/jpeg', width: width, height: height, ); From 9376f275e50538101cf8db77f875a0e4232365ec Mon Sep 17 00:00:00 2001 From: --global Date: Thu, 29 Aug 2024 16:07:26 +0700 Subject: [PATCH 5/8] fixup! fixup! fixup! TW-2001: add mimeType for thumbnail when sending video --- lib/presentation/extensions/send_file_extension.dart | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/presentation/extensions/send_file_extension.dart b/lib/presentation/extensions/send_file_extension.dart index ddc025f802..e2ee8a4c49 100644 --- a/lib/presentation/extensions/send_file_extension.dart +++ b/lib/presentation/extensions/send_file_extension.dart @@ -25,7 +25,6 @@ import 'package:image/image.dart' as img; import 'package:blurhash_dart/blurhash_dart.dart'; import 'package:flutter/foundation.dart'; import 'package:matrix/matrix.dart'; -import 'package:mime/mime.dart'; import 'package:path_provider/path_provider.dart'; import 'package:flutter_image_compress/flutter_image_compress.dart'; import 'package:video_thumbnail/video_thumbnail.dart'; @@ -706,11 +705,9 @@ extension SendFileExtension on Room { } Logs().d('Video thumbnail generated', tempThumbnailFile.path); uploadStreamController?.add(const Right(GenerateThumbnailSuccess())); - final newFileName = '${tempThumbnailFile.path.split("/").last}.jpg'; final newThumbnail = ImageFileInfo( - newFileName, + tempThumbnailFile.path.split('/').last, tempThumbnailFile.path, - customMimeType: lookupMimeType(newFileName) ?? 'image/jpeg', fileSize, width: width, height: height, From 9a6ed2d1c51772f78259aa1317eb86381ebed6d2 Mon Sep 17 00:00:00 2001 From: --global Date: Fri, 30 Aug 2024 17:57:06 +0700 Subject: [PATCH 6/8] fixup! fixup! fixup! fixup! TW-2001: add mimeType for thumbnail when sending video --- .../extensions/send_file_extension.dart | 14 ++++++++++---- .../extensions/send_file_web_extension.dart | 6 ++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/presentation/extensions/send_file_extension.dart b/lib/presentation/extensions/send_file_extension.dart index e2ee8a4c49..52d7f80c3b 100644 --- a/lib/presentation/extensions/send_file_extension.dart +++ b/lib/presentation/extensions/send_file_extension.dart @@ -93,9 +93,8 @@ extension SendFileExtension on Room { } final formattedDateTime = DateTime.now().getFormattedCurrentDateTime(); - final fileName = - '$formattedDateTime${fileInfo.fileName}.${AppConfig.imageCompressFormmat.name}'; - final targetPath = await File('${tempDir.path}/$fileName').create(); + final fileName = _generateThumbnailFileName(formattedDateTime, fileInfo); + final targetPath = await _getTargetParh(tempDir, fileName); await _generateThumbnail( fileInfo as ImageFileInfo, targetPath: targetPath.path, @@ -426,6 +425,13 @@ extension SendFileExtension on Room { return eventId; } + Future _getTargetParh(Directory tempDir, String fileName) async => + await File('${tempDir.path}/$fileName').create(); + + String _generateThumbnailFileName( + String formattedDateTime, FileInfo fileInfo,) => + '$formattedDateTime${fileInfo.fileName}.${AppConfig.imageCompressFormmat.name}'; + Future convertHeicToJpgImage(ImageFileInfo fileInfo) async { final convertedFilePath = StorageDirectoryManager.instance.convertFileExtension( @@ -706,7 +712,7 @@ extension SendFileExtension on Room { Logs().d('Video thumbnail generated', tempThumbnailFile.path); uploadStreamController?.add(const Right(GenerateThumbnailSuccess())); final newThumbnail = ImageFileInfo( - tempThumbnailFile.path.split('/').last, + tempThumbnailFile.path.split("/").last, tempThumbnailFile.path, fileSize, width: width, diff --git a/lib/presentation/extensions/send_file_web_extension.dart b/lib/presentation/extensions/send_file_web_extension.dart index aded121a9e..42f08ff02a 100644 --- a/lib/presentation/extensions/send_file_web_extension.dart +++ b/lib/presentation/extensions/send_file_web_extension.dart @@ -443,8 +443,7 @@ extension SendFileWebExtension on Room { const Right(GenerateThumbnailSuccess()), ); - final thumbnailFileName = - '${originalFile.name}.${AppConfig.videoThumbnailFormat.name.toLowerCase()}'; + final thumbnailFileName = _getVideoThumbnailFileName(originalFile); return MatrixImageFile( bytes: result, @@ -467,6 +466,9 @@ extension SendFileWebExtension on Room { } } + String _getVideoThumbnailFileName(MatrixVideoFile originalFile) => + '${originalFile.name}.${AppConfig.videoThumbnailFormat.name.toLowerCase()}'; + Future _getVideoDuration( MatrixVideoFile originalFile, ) async { From 3f46b2deca19573446999a208e7e15dfbd89e8cd Mon Sep 17 00:00:00 2001 From: --global Date: Fri, 30 Aug 2024 17:58:24 +0700 Subject: [PATCH 7/8] fixup! fixup! fixup! fixup! TW-2001: add mimeType for thumbnail when sending video --- lib/presentation/extensions/send_file_extension.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/presentation/extensions/send_file_extension.dart b/lib/presentation/extensions/send_file_extension.dart index 52d7f80c3b..c603e4fa63 100644 --- a/lib/presentation/extensions/send_file_extension.dart +++ b/lib/presentation/extensions/send_file_extension.dart @@ -429,7 +429,9 @@ extension SendFileExtension on Room { await File('${tempDir.path}/$fileName').create(); String _generateThumbnailFileName( - String formattedDateTime, FileInfo fileInfo,) => + String formattedDateTime, + FileInfo fileInfo, + ) => '$formattedDateTime${fileInfo.fileName}.${AppConfig.imageCompressFormmat.name}'; Future convertHeicToJpgImage(ImageFileInfo fileInfo) async { From adb0fd63eab35ceea008601b01fe484a60dd3dad Mon Sep 17 00:00:00 2001 From: --global Date: Wed, 4 Sep 2024 09:32:26 +0700 Subject: [PATCH 8/8] fixup! fixup! fixup! fixup! fixup! TW-2001: add mimeType for thumbnail when sending video --- lib/presentation/extensions/send_file_extension.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/presentation/extensions/send_file_extension.dart b/lib/presentation/extensions/send_file_extension.dart index c603e4fa63..45b60e38fb 100644 --- a/lib/presentation/extensions/send_file_extension.dart +++ b/lib/presentation/extensions/send_file_extension.dart @@ -94,7 +94,7 @@ extension SendFileExtension on Room { final formattedDateTime = DateTime.now().getFormattedCurrentDateTime(); final fileName = _generateThumbnailFileName(formattedDateTime, fileInfo); - final targetPath = await _getTargetParh(tempDir, fileName); + final targetPath = await _createThumbnailFile(tempDir, fileName); await _generateThumbnail( fileInfo as ImageFileInfo, targetPath: targetPath.path, @@ -425,7 +425,7 @@ extension SendFileExtension on Room { return eventId; } - Future _getTargetParh(Directory tempDir, String fileName) async => + Future _createThumbnailFile(Directory tempDir, String fileName) async => await File('${tempDir.path}/$fileName').create(); String _generateThumbnailFileName(