TF-2644 Handle total size exceeded maximum size when drag & drop multiple file to composer

This commit is contained in:
dab246
2024-03-01 17:09:09 +07:00
committed by Dat H. Pham
parent d646a5b9e4
commit 145a49d728
54 changed files with 1140 additions and 800 deletions
+44 -11
View File
@@ -1,32 +1,65 @@
import 'package:equatable/equatable.dart';
import 'package:flutter/foundation.dart';
import 'package:mime/mime.dart';
class FileInfo with EquatableMixin {
final String fileName;
final String filePath;
final int fileSize;
final String? filePath;
final Uint8List? bytes;
final Stream<List<int>>? readStream;
final String? type;
final bool? isInline;
final bool? isShared;
FileInfo(this.fileName, this.filePath, this.fileSize, {this.bytes});
factory FileInfo.empty() {
return FileInfo('', '', 0);
}
FileInfo({
required this.fileName,
required this.fileSize,
this.filePath,
this.bytes,
this.readStream,
this.type,
this.isInline,
this.isShared,
});
factory FileInfo.fromBytes({
required Uint8List bytes,
String? name,
int? size
int? size,
String? type,
}) {
return FileInfo(name ?? '', '', size ?? 0, bytes: bytes);
return FileInfo(
fileName: name ?? '',
fileSize: size ?? 0,
bytes: bytes,
type: type
);
}
String get fileExtension => fileName.split('.').last;
String get mimeType => lookupMimeType(kIsWeb ? fileName : filePath) ?? 'application/octet-stream';
String get mimeType {
if (type?.isNotEmpty == true) {
return type!;
} else if (filePath?.isNotEmpty == true){
final matchedType = lookupMimeType(filePath!, headerBytes: bytes) ?? 'application/octet-stream';
return matchedType;
} else {
final matchedType = lookupMimeType(fileName, headerBytes: bytes) ?? 'application/octet-stream';
return matchedType;
}
}
@override
List<Object?> get props => [fileName, filePath, fileSize, bytes];
List<Object?> get props => [
fileName,
filePath,
fileSize,
bytes,
readStream,
type,
isInline,
isShared,
];
}