TF-2644 Handle total size exceeded maximum size when drag & drop multiple file to composer
This commit is contained in:
@@ -0,0 +1 @@
|
||||
class PickFileCanceledException implements Exception {}
|
||||
@@ -3,5 +3,15 @@ import 'package:model/upload/file_info.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/model/mobile_file_upload.dart';
|
||||
|
||||
extension FileInfoExtension on FileInfo {
|
||||
MobileFileUpload toMobileFileUpload() => MobileFileUpload(fileName, filePath, fileSize, mimeType);
|
||||
MobileFileUpload toMobileFileUpload() => MobileFileUpload(fileName, filePath!, fileSize, mimeType);
|
||||
|
||||
FileInfo withInline() => FileInfo(
|
||||
fileName: fileName,
|
||||
fileSize: fileSize,
|
||||
filePath: filePath,
|
||||
bytes: bytes,
|
||||
readStream: readStream,
|
||||
type: type,
|
||||
isInline: true,
|
||||
isShared: isShared);
|
||||
}
|
||||
@@ -3,5 +3,5 @@ import 'package:model/upload/file_info.dart';
|
||||
extension ListFileInfoExtension on List<FileInfo> {
|
||||
List<int> get listSize => map((file) => file.fileSize).toList();
|
||||
|
||||
num get totalSize => listSize.reduce((sum, size) => sum + size);
|
||||
num get totalSize => listSize.isEmpty ? 0 : listSize.reduce((sum, size) => sum + size);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import 'package:core/domain/extensions/media_type_extension.dart';
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
|
||||
extension MediaTypeExtension on MediaType {
|
||||
String getIcon(ImagePaths imagePaths, {String? fileName}) {
|
||||
if (validatePDFIcon(fileName: fileName) == true) {
|
||||
return imagePaths.icFilePdf;
|
||||
} else if (isDocFile()) {
|
||||
return imagePaths.icFileDocx;
|
||||
} else if (isExcelFile()) {
|
||||
return imagePaths.icFileXlsx;
|
||||
} else if (isPowerPointFile()) {
|
||||
return imagePaths.icFilePptx;
|
||||
} else if (isPdfFile()) {
|
||||
return imagePaths.icFilePdf;
|
||||
} else if (isZipFile()) {
|
||||
return imagePaths.icFileZip;
|
||||
} else if (isImageFile()) {
|
||||
return imagePaths.icFilePng;
|
||||
} else {
|
||||
return imagePaths.icFileEPup;
|
||||
}
|
||||
}
|
||||
|
||||
bool validatePDFIcon({required String? fileName}) => mimeType == 'application/pdf' ||
|
||||
(mimeType == 'application/octet-stream' && fileName?.endsWith('.pdf') == true);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:model/upload/file_info.dart';
|
||||
|
||||
extension PlatformFileExtension on PlatformFile {
|
||||
FileInfo toFileInfo() => FileInfo(
|
||||
fileName: name,
|
||||
fileSize: size,
|
||||
filePath: PlatformInfo.isWeb ? '' : path ?? '',
|
||||
bytes: bytes,
|
||||
readStream: readStream
|
||||
);
|
||||
}
|
||||
@@ -31,15 +31,11 @@ class SuccessAttachmentUploadState extends Success {
|
||||
final UploadTaskId uploadId;
|
||||
final Attachment attachment;
|
||||
final FileInfo fileInfo;
|
||||
final bool fromFileShared;
|
||||
|
||||
SuccessAttachmentUploadState(
|
||||
this.uploadId,
|
||||
this.attachment,
|
||||
this.fileInfo,
|
||||
{
|
||||
this.fromFileShared = false
|
||||
}
|
||||
this.fileInfo
|
||||
);
|
||||
|
||||
@override
|
||||
@@ -47,7 +43,6 @@ class SuccessAttachmentUploadState extends Success {
|
||||
uploadId,
|
||||
attachment,
|
||||
fileInfo,
|
||||
fromFileShared,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@ import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:model/upload/file_info.dart';
|
||||
|
||||
class LocalFilePickerLoading extends LoadingState {}
|
||||
|
||||
class LocalFilePickerSuccess extends UIState {
|
||||
final List<FileInfo> pickedFiles;
|
||||
|
||||
@@ -14,6 +16,4 @@ class LocalFilePickerSuccess extends UIState {
|
||||
class LocalFilePickerFailure extends FeatureFailure {
|
||||
|
||||
LocalFilePickerFailure(dynamic exception) : super(exception: exception);
|
||||
}
|
||||
|
||||
class LocalFilePickerCancel extends FeatureFailure {}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:model/upload/file_info.dart';
|
||||
|
||||
class LocalImagePickerLoading extends LoadingState {}
|
||||
|
||||
class LocalImagePickerSuccess extends UIState {
|
||||
final FileInfo fileInfo;
|
||||
|
||||
LocalImagePickerSuccess(this.fileInfo);
|
||||
|
||||
@override
|
||||
List<Object> get props => [fileInfo];
|
||||
}
|
||||
|
||||
class LocalImagePickerFailure extends FeatureFailure {
|
||||
|
||||
LocalImagePickerFailure(dynamic exception) : super(exception: exception);
|
||||
}
|
||||
@@ -4,7 +4,8 @@ import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:model/upload/file_info.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/exceptions/pick_file_exception.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/extensions/platform_file_extension.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/state/local_file_picker_state.dart';
|
||||
|
||||
class LocalFilePickerInteractor {
|
||||
@@ -13,23 +14,22 @@ class LocalFilePickerInteractor {
|
||||
|
||||
Stream<Either<Failure, Success>> execute({FileType fileType = FileType.any}) async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(LocalFilePickerLoading());
|
||||
|
||||
final filesResult = await FilePicker.platform.pickFiles(
|
||||
type: fileType,
|
||||
allowMultiple: true,
|
||||
withData: PlatformInfo.isWeb
|
||||
withData: PlatformInfo.isWeb,
|
||||
withReadStream: PlatformInfo.isMobile
|
||||
);
|
||||
if (filesResult != null && filesResult.files.isNotEmpty) {
|
||||
final fileInfoResults = filesResult.files
|
||||
.map((platformFile) => FileInfo(
|
||||
platformFile.name,
|
||||
PlatformInfo.isWeb ? '' : platformFile.path ?? '',
|
||||
platformFile.size,
|
||||
bytes: PlatformInfo.isWeb ? platformFile.bytes : null
|
||||
))
|
||||
.toList();
|
||||
yield Right<Failure, Success>(LocalFilePickerSuccess(fileInfoResults));
|
||||
|
||||
if (filesResult?.files.isNotEmpty == true) {
|
||||
final listFileInfo = filesResult!.files
|
||||
.map((platformFile) => platformFile.toFileInfo())
|
||||
.toList();
|
||||
yield Right<Failure, Success>(LocalFilePickerSuccess(listFileInfo));
|
||||
} else {
|
||||
yield Left<Failure, Success>(LocalFilePickerCancel());
|
||||
yield Left<Failure, Success>(LocalFilePickerFailure(PickFileCanceledException()));
|
||||
}
|
||||
} catch (exception) {
|
||||
yield Left<Failure, Success>(LocalFilePickerFailure(exception));
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import 'package:core/presentation/state/failure.dart';
|
||||
import 'package:core/presentation/state/success.dart';
|
||||
import 'package:core/utils/platform_info.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:file_picker/file_picker.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/exceptions/pick_file_exception.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/extensions/platform_file_extension.dart';
|
||||
import 'package:tmail_ui_user/features/upload/domain/state/local_image_picker_state.dart';
|
||||
|
||||
class LocalImagePickerInteractor {
|
||||
|
||||
LocalImagePickerInteractor();
|
||||
|
||||
Stream<Either<Failure, Success>> execute() async* {
|
||||
try {
|
||||
yield Right<Failure, Success>(LocalImagePickerLoading());
|
||||
|
||||
final filePickerResult = await FilePicker.platform.pickFiles(
|
||||
type: FileType.image,
|
||||
allowMultiple: false,
|
||||
withReadStream: PlatformInfo.isMobile,
|
||||
withData: PlatformInfo.isWeb
|
||||
);
|
||||
|
||||
if (filePickerResult?.files.isNotEmpty == true) {
|
||||
final fileInfo = filePickerResult!.files.first.toFileInfo();
|
||||
yield Right<Failure, Success>(LocalImagePickerSuccess(fileInfo));
|
||||
} else {
|
||||
yield Left<Failure, Success>(LocalImagePickerFailure(PickFileCanceledException()));
|
||||
}
|
||||
} catch (exception) {
|
||||
yield Left<Failure, Success>(LocalImagePickerFailure(exception));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user