diff --git a/contact/pubspec.lock b/contact/pubspec.lock index ded701d809..beb8865df5 100644 --- a/contact/pubspec.lock +++ b/contact/pubspec.lock @@ -337,10 +337,10 @@ packages: dependency: transitive description: name: flutter_charset_detector - sha256: "45de8a4b4255c1ea850a30955e7456091899ed4ff8b75593e14ec59f629b4b56" + sha256: "5d4796d43dac2f37e14149b0f0c676fa08e8eb1ada8e99342a838d971d2fb9b1" url: "https://pub.dev" source: hosted - version: "2.0.0" + version: "3.0.0" flutter_charset_detector_android: dependency: transitive description: @@ -349,14 +349,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.1" - flutter_charset_detector_ios: + flutter_charset_detector_darwin: dependency: transitive description: - name: flutter_charset_detector_ios - sha256: e0e2c7b819cd1f7c9a50da94bf7f0e6d7a095eb64e81196ec758e77793903d43 + name: flutter_charset_detector_darwin + sha256: daac20390275efb92fbb14350fe11286c5e29c7b80d6b0867f52d760f0d69763 url: "https://pub.dev" source: hosted - version: "1.0.2" + version: "1.1.0" flutter_charset_detector_platform_interface: dependency: transitive description: @@ -365,6 +365,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" + flutter_charset_detector_web: + dependency: transitive + description: + name: flutter_charset_detector_web + sha256: d8495115abada771c75f9395aae3e5809ffd506e8fc8f62b403ae11fc29e1d2b + url: "https://pub.dev" + source: hosted + version: "1.0.2" flutter_image_compress: dependency: transitive description: diff --git a/core/lib/utils/file_utils.dart b/core/lib/utils/file_utils.dart index 9cd2708203..19dc48a824 100644 --- a/core/lib/utils/file_utils.dart +++ b/core/lib/utils/file_utils.dart @@ -9,7 +9,7 @@ import 'package:flutter_charset_detector/flutter_charset_detector.dart'; import 'package:path_provider/path_provider.dart'; class FileUtils { - static const String DEFAULT_CHARSET = 'UTF-8'; + static const String DEFAULT_CHARSET = 'uft-8'; static const String TEXT_PLAIN_MIME_TYPE = 'text/plain'; Future _getInternalStorageDirPath({ @@ -139,14 +139,13 @@ class FileUtils { } } - Future getFileCharset(String filePath) async { + Future getCharsetFromBytes(Uint8List bytes) async { try { - final file = File(filePath); - final decodingResult = await CharsetDetector.autoDecode(file.readAsBytesSync()); - logError('FileUtils::getFileCharset: FILE_CHARSET = ${decodingResult.charset}'); - return decodingResult.charset; + final decodedResult = await CharsetDetector.autoDecode(bytes); + log('FileUtils::getCharsetFromBytes: FILE_CHARSET = ${decodedResult.charset}'); + return decodedResult.charset; } catch (e) { - logError('FileUtils::getFileCharset: Exception: $e'); + logError('FileUtils::getCharsetFromBytes: Exception: $e'); return DEFAULT_CHARSET; } } diff --git a/core/lib/utils/web_renderer/canvas_kit_web.dart b/core/lib/utils/web_renderer/canvas_kit_web.dart index 94317ab2db..fd03937e5b 100644 --- a/core/lib/utils/web_renderer/canvas_kit_web.dart +++ b/core/lib/utils/web_renderer/canvas_kit_web.dart @@ -1,4 +1,4 @@ -import 'dart:js' as js; +import 'package:universal_html/js.dart' as js; /// Whether the CanvasKit renderer is being used on web. /// diff --git a/core/pubspec.lock b/core/pubspec.lock index 445594eb95..00d679e4ab 100644 --- a/core/pubspec.lock +++ b/core/pubspec.lock @@ -330,10 +330,10 @@ packages: dependency: "direct main" description: name: flutter_charset_detector - sha256: "45de8a4b4255c1ea850a30955e7456091899ed4ff8b75593e14ec59f629b4b56" + sha256: "5d4796d43dac2f37e14149b0f0c676fa08e8eb1ada8e99342a838d971d2fb9b1" url: "https://pub.dev" source: hosted - version: "2.0.0" + version: "3.0.0" flutter_charset_detector_android: dependency: transitive description: @@ -342,14 +342,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.1" - flutter_charset_detector_ios: + flutter_charset_detector_darwin: dependency: transitive description: - name: flutter_charset_detector_ios - sha256: e0e2c7b819cd1f7c9a50da94bf7f0e6d7a095eb64e81196ec758e77793903d43 + name: flutter_charset_detector_darwin + sha256: d17c1847366a0501449d95d18a43417585841afe10200ceefb4422e6b7fccefb url: "https://pub.dev" source: hosted - version: "1.0.2" + version: "1.0.0" flutter_charset_detector_platform_interface: dependency: transitive description: @@ -358,6 +358,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0" + flutter_charset_detector_web: + dependency: transitive + description: + name: flutter_charset_detector_web + sha256: d8495115abada771c75f9395aae3e5809ffd506e8fc8f62b403ae11fc29e1d2b + url: "https://pub.dev" + source: hosted + version: "1.0.2" flutter_image_compress: dependency: "direct main" description: diff --git a/core/pubspec.yaml b/core/pubspec.yaml index 4c59184b2f..0ebbc60a84 100644 --- a/core/pubspec.yaml +++ b/core/pubspec.yaml @@ -79,7 +79,7 @@ dependencies: fk_user_agent: 2.1.0 - flutter_charset_detector: 2.0.0 + flutter_charset_detector: 3.0.0 dev_dependencies: flutter_test: diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 304ba9ef93..d1d2b04611 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -90,8 +90,9 @@ PODS: - flutter_appauth (0.0.1): - AppAuth (= 1.7.4) - Flutter - - flutter_charset_detector_ios (0.0.1): + - flutter_charset_detector_darwin (0.0.1): - Flutter + - FlutterMacOS - UniversalDetector2 (= 2.0.1) - flutter_downloader (0.0.1): - Flutter @@ -205,7 +206,7 @@ DEPENDENCIES: - fk_user_agent (from `.symlinks/plugins/fk_user_agent/ios`) - Flutter (from `Flutter`) - flutter_appauth (from `.symlinks/plugins/flutter_appauth/ios`) - - flutter_charset_detector_ios (from `.symlinks/plugins/flutter_charset_detector_ios/ios`) + - flutter_charset_detector_darwin (from `.symlinks/plugins/flutter_charset_detector_darwin/darwin`) - flutter_downloader (from `.symlinks/plugins/flutter_downloader/ios`) - flutter_image_compress_common (from `.symlinks/plugins/flutter_image_compress_common/ios`) - flutter_inappwebview_ios (from `.symlinks/plugins/flutter_inappwebview_ios/ios`) @@ -273,8 +274,8 @@ EXTERNAL SOURCES: :path: Flutter flutter_appauth: :path: ".symlinks/plugins/flutter_appauth/ios" - flutter_charset_detector_ios: - :path: ".symlinks/plugins/flutter_charset_detector_ios/ios" + flutter_charset_detector_darwin: + :path: ".symlinks/plugins/flutter_charset_detector_darwin/darwin" flutter_downloader: :path: ".symlinks/plugins/flutter_downloader/ios" flutter_image_compress_common: @@ -333,7 +334,7 @@ SPEC CHECKSUMS: fk_user_agent: 1f47ec39291e8372b1d692b50084b0d54103c545 Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 flutter_appauth: 1ce438877bc111c5d8f42da47729909290624886 - flutter_charset_detector_ios: 5157d0104855b9deb78e1395515a287197bc2d55 + flutter_charset_detector_darwin: fb3692d6d72cb6afcce7b0dd1a9516be6e78556e flutter_downloader: b7301ae057deadd4b1650dc7c05375f10ff12c39 flutter_image_compress_common: ec1d45c362c9d30a3f6a0426c297f47c52007e3e flutter_inappwebview_ios: 97215cf7d4677db55df76782dbd2930c5e1c1ea0 diff --git a/lib/features/public_asset/presentation/public_asset_bindings.dart b/lib/features/public_asset/presentation/public_asset_bindings.dart index 8527be196a..714e28d71f 100644 --- a/lib/features/public_asset/presentation/public_asset_bindings.dart +++ b/lib/features/public_asset/presentation/public_asset_bindings.dart @@ -1,6 +1,7 @@ import 'package:core/data/network/dio_client.dart'; import 'package:core/data/network/download/download_client.dart'; import 'package:core/utils/application_manager.dart'; +import 'package:core/utils/file_utils.dart'; import 'package:get/get.dart'; import 'package:jmap_dart_client/http/http_client.dart'; import 'package:tmail_ui_user/features/base/base_bindings.dart'; @@ -38,7 +39,10 @@ class PublicAssetBindings extends BaseBindings { @override void dependencies() { Get.lazyPut( - () => FileUploader(Get.find(tag: BindingTag.isolateTag), Get.find()), + () => FileUploader( + Get.find(tag: BindingTag.isolateTag), + Get.find(), + Get.find()), tag: BindingTag.publicAssetBindingsTag); Get.lazyPut( () => PublicAssetApi(Get.find(), Get.find()), diff --git a/lib/features/upload/data/network/file_uploader.dart b/lib/features/upload/data/network/file_uploader.dart index 5d5d02d9ea..a424357fb7 100644 --- a/lib/features/upload/data/network/file_uploader.dart +++ b/lib/features/upload/data/network/file_uploader.dart @@ -123,11 +123,13 @@ class FileUploader { ); log('FileUploader::_handleUploadAttachmentAction(): RESULT_JSON = $resultJson'); if (argsUpload.mobileFileUpload.mimeType == FileUtils.TEXT_PLAIN_MIME_TYPE) { - final fileCharset = await argsUpload.fileUtils.getFileCharset(argsUpload.mobileFileUpload.filePath); + final fileCharset = await argsUpload.fileUtils.getCharsetFromBytes( + File(argsUpload.mobileFileUpload.filePath).readAsBytesSync() + ); return _parsingResponse( resultJson: resultJson, fileName: argsUpload.mobileFileUpload.fileName, - fileCharset: fileCharset); + fileCharset: fileCharset.toLowerCase()); } else { return _parsingResponse( resultJson: resultJson, @@ -140,7 +142,7 @@ class FileUploader { requestOptions: exception.requestOptions.copyWith(data: '')); } catch (exception) { logError('FileUploader::_handleUploadAttachmentAction():OtherException: $exception'); - + rethrow; } } @@ -181,8 +183,18 @@ class FileUploader { ); } ); - log('FileUploader::_handleUploadAttachmentActionOnWeb():resultJson: $resultJson'); - return _parsingResponse(resultJson: resultJson, fileName: fileInfo.fileName); + log('FileUploader::_handleUploadAttachmentActionOnWeb(): RESULT_JSON = $resultJson'); + if (fileInfo.mimeType == FileUtils.TEXT_PLAIN_MIME_TYPE) { + final fileCharset = await _fileUtils.getCharsetFromBytes(fileInfo.bytes!); + return _parsingResponse( + resultJson: resultJson, + fileName: fileInfo.fileName, + fileCharset: fileCharset.toLowerCase()); + } else { + return _parsingResponse( + resultJson: resultJson, + fileName: fileInfo.fileName); + } } static Attachment _parsingResponse({ diff --git a/model/pubspec.lock b/model/pubspec.lock index d2938fe2f5..37f9ab77ca 100644 --- a/model/pubspec.lock +++ b/model/pubspec.lock @@ -337,10 +337,10 @@ packages: dependency: transitive description: name: flutter_charset_detector - sha256: "45de8a4b4255c1ea850a30955e7456091899ed4ff8b75593e14ec59f629b4b56" + sha256: "5d4796d43dac2f37e14149b0f0c676fa08e8eb1ada8e99342a838d971d2fb9b1" url: "https://pub.dev" source: hosted - version: "2.0.0" + version: "3.0.0" flutter_charset_detector_android: dependency: transitive description: @@ -349,14 +349,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.1.1" - flutter_charset_detector_ios: + flutter_charset_detector_darwin: dependency: transitive description: - name: flutter_charset_detector_ios - sha256: e0e2c7b819cd1f7c9a50da94bf7f0e6d7a095eb64e81196ec758e77793903d43 + name: flutter_charset_detector_darwin + sha256: daac20390275efb92fbb14350fe11286c5e29c7b80d6b0867f52d760f0d69763 url: "https://pub.dev" source: hosted - version: "1.0.2" + version: "1.1.0" flutter_charset_detector_platform_interface: dependency: transitive description: @@ -365,6 +365,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.1.0" + flutter_charset_detector_web: + dependency: transitive + description: + name: flutter_charset_detector_web + sha256: d8495115abada771c75f9395aae3e5809ffd506e8fc8f62b403ae11fc29e1d2b + url: "https://pub.dev" + source: hosted + version: "1.0.2" flutter_image_compress: dependency: transitive description: diff --git a/pubspec.lock b/pubspec.lock index c08731e4f1..7032bc7477 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -659,10 +659,10 @@ packages: dependency: transitive description: name: flutter_charset_detector - sha256: "45de8a4b4255c1ea850a30955e7456091899ed4ff8b75593e14ec59f629b4b56" + sha256: "5d4796d43dac2f37e14149b0f0c676fa08e8eb1ada8e99342a838d971d2fb9b1" url: "https://pub.dev" source: hosted - version: "2.0.0" + version: "3.0.0" flutter_charset_detector_android: dependency: transitive description: @@ -671,14 +671,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.0.1" - flutter_charset_detector_ios: + flutter_charset_detector_darwin: dependency: transitive description: - name: flutter_charset_detector_ios - sha256: e0e2c7b819cd1f7c9a50da94bf7f0e6d7a095eb64e81196ec758e77793903d43 + name: flutter_charset_detector_darwin + sha256: d17c1847366a0501449d95d18a43417585841afe10200ceefb4422e6b7fccefb url: "https://pub.dev" source: hosted - version: "1.0.2" + version: "1.0.0" flutter_charset_detector_platform_interface: dependency: transitive description: @@ -687,6 +687,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0" + flutter_charset_detector_web: + dependency: transitive + description: + name: flutter_charset_detector_web + sha256: d8495115abada771c75f9395aae3e5809ffd506e8fc8f62b403ae11fc29e1d2b + url: "https://pub.dev" + source: hosted + version: "1.0.2" flutter_colorpicker: dependency: transitive description: diff --git a/test/features/identity_creator/presentation/identity_creator_controller_test.dart b/test/features/identity_creator/presentation/identity_creator_controller_test.dart index 3a00dcf15f..2040407d43 100644 --- a/test/features/identity_creator/presentation/identity_creator_controller_test.dart +++ b/test/features/identity_creator/presentation/identity_creator_controller_test.dart @@ -7,6 +7,7 @@ import 'package:core/presentation/utils/responsive_utils.dart'; import 'package:core/utils/application_manager.dart'; import 'package:core/utils/platform_info.dart'; import 'package:dartz/dartz.dart' hide State; +import 'package:core/utils/file_utils.dart'; import 'package:flutter/widgets.dart' hide State; import 'package:flutter_test/flutter_test.dart'; import 'package:get/get.dart'; @@ -74,6 +75,7 @@ import 'identity_creator_controller_test.mocks.dart'; MockSpec(), MockSpec(), MockSpec(), + MockSpec(), MockSpec(), MockSpec(), MockSpec(), @@ -155,6 +157,7 @@ void main() { Get.put(MockDioClient(), tag: BindingTag.isolateTag); Get.put(MockExecutor()); + Get.put(MockFileUtils()); Get.put(MockRemoteExceptionThrower()); Get.put(MockDownloadClient()); Get.put(MockHtmlAnalyzer()); @@ -182,7 +185,7 @@ void main() { true, {CapabilityIdentifier.jmapPublicAsset: DefaultCapability({})}); final session = Session( - {}, + {}, {accountId: account}, {}, UserName('value'), Uri(), Uri(), Uri(), Uri(), State('value')); @@ -271,14 +274,14 @@ void main() { final context = MockBuildContext(); identityCreatorController.updateNameIdentity(context, identityName); identityCreatorController.updateContentHtmlEditor(htmlContent); - + identityCreatorController.onUnloadBrowserListener(Event('')); await untilCalled(mockSaveIdentityCacheOnWebInteractor.execute( any, any, identityCache: anyNamed('identityCache'), )); - + // assert verify(mockSaveIdentityCacheOnWebInteractor.execute( accountId, @@ -321,14 +324,14 @@ void main() { final context = MockBuildContext(); identityCreatorController.updateNameIdentity(context, identityName); identityCreatorController.updateContentHtmlEditor(htmlContent); - + identityCreatorController.onBeforeReconnect(); await untilCalled(mockSaveIdentityCacheOnWebInteractor.execute( any, any, identityCache: anyNamed('identityCache'), )); - + // assert verify(mockSaveIdentityCacheOnWebInteractor.execute( accountId, diff --git a/web/index.html b/web/index.html index 16d48b3d38..c54b494cc0 100644 --- a/web/index.html +++ b/web/index.html @@ -36,6 +36,7 @@ +