TF-4075 Change attachments location
(cherry picked from commit ab23dac45d9dcf7c5e057f8e16974b3ed8205771)
This commit is contained in:
@@ -1,49 +1,18 @@
|
||||
import 'package:core/data/constants/constant.dart';
|
||||
import 'package:core/domain/preview/document_uti.dart';
|
||||
import 'package:core/domain/preview/supported_preview_file_types.dart';
|
||||
import 'package:core/presentation/extensions/string_extension.dart';
|
||||
import 'package:core/presentation/model/file_category.dart';
|
||||
import 'package:core/presentation/resources/image_paths.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
|
||||
extension MediaTypeExtension on MediaType {
|
||||
bool isAndroidSupportedPreview() => SupportedPreviewFileTypes.androidSupportedTypes.contains(mimeType);
|
||||
|
||||
bool isIOSSupportedPreview() => SupportedPreviewFileTypes.iOSSupportedTypes.containsKey(mimeType);
|
||||
|
||||
bool isImageFile() => SupportedPreviewFileTypes.imageMimeTypes.contains(mimeType);
|
||||
|
||||
bool isDocFile() => SupportedPreviewFileTypes.docMimeTypes.contains(mimeType);
|
||||
|
||||
bool isPowerPointFile() => SupportedPreviewFileTypes.pptMimeTypes.contains(mimeType);
|
||||
|
||||
bool isExcelFile() => SupportedPreviewFileTypes.xlsMimeTypes.contains(mimeType);
|
||||
|
||||
bool isZipFile() => SupportedPreviewFileTypes.zipMimeTypes.contains(mimeType);
|
||||
|
||||
bool isRtfFile() => SupportedPreviewFileTypes.rtfMimeTypes.contains(mimeType);
|
||||
|
||||
bool isTextFile() => SupportedPreviewFileTypes.textMimeTypes.contains(mimeType);
|
||||
|
||||
bool isJsonFile() => SupportedPreviewFileTypes.jsonMimeTypes.contains(mimeType);
|
||||
|
||||
DocumentUti getDocumentUti() => DocumentUti(SupportedPreviewFileTypes.iOSSupportedTypes[mimeType]);
|
||||
|
||||
String getIcon(ImagePaths imagePaths, {String? fileName}) {
|
||||
if (isPDFFile(fileName: fileName) == true || isRtfFile()) {
|
||||
return imagePaths.icFilePdf;
|
||||
} else if (isDocFile()) {
|
||||
return imagePaths.icFileDocx;
|
||||
} else if (isExcelFile()) {
|
||||
return imagePaths.icFileXlsx;
|
||||
} else if (isPowerPointFile()) {
|
||||
return imagePaths.icFilePptx;
|
||||
} else if (isZipFile()) {
|
||||
return imagePaths.icFileZip;
|
||||
} else if (isImageSupportedPreview(fileName: fileName)) {
|
||||
return imagePaths.icFilePng;
|
||||
} else {
|
||||
return imagePaths.icFileEPup;
|
||||
}
|
||||
final category = getFileCategory(fileName: fileName);
|
||||
return category.getIconPath(imagePaths);
|
||||
}
|
||||
|
||||
bool isPDFFile({required String? fileName}) =>
|
||||
@@ -58,10 +27,132 @@ extension MediaTypeExtension on MediaType {
|
||||
(mimeType == Constant.octetStreamMimeType &&
|
||||
fileName?.endsWith(Constant.htmlExtension) == true);
|
||||
|
||||
bool isImageSupportedPreview({required String? fileName}) =>
|
||||
isImageFile() ||
|
||||
(mimeType == Constant.octetStreamMimeType &&
|
||||
fileName != null &&
|
||||
SupportedPreviewFileTypes.imageMimeTypes
|
||||
.contains(fileName.imageMimeType));
|
||||
FileCategory getFileCategory({String? fileName}) {
|
||||
String? ext;
|
||||
|
||||
if (fileName != null && fileName.contains('.')) {
|
||||
ext = fileName.split('.').last.toLowerCase();
|
||||
}
|
||||
|
||||
switch (ext) {
|
||||
case 'pdf':
|
||||
return FileCategory.pdf;
|
||||
case 'doc':
|
||||
case 'docx':
|
||||
case 'rtf':
|
||||
return FileCategory.document;
|
||||
case 'odt':
|
||||
return FileCategory.documentODT;
|
||||
case 'xls':
|
||||
case 'xlsx':
|
||||
case 'csv':
|
||||
case 'tsv':
|
||||
return FileCategory.spreadsheet;
|
||||
case 'ods':
|
||||
return FileCategory.spreadsheetODS;
|
||||
case 'ppt':
|
||||
case 'pptx':
|
||||
return FileCategory.presentation;
|
||||
case 'odp':
|
||||
return FileCategory.presentationODP;
|
||||
case 'jpg':
|
||||
case 'jpeg':
|
||||
case 'png':
|
||||
case 'gif':
|
||||
case 'bmp':
|
||||
case 'svg':
|
||||
case 'webp':
|
||||
case 'heic':
|
||||
case 'heif':
|
||||
case 'avif':
|
||||
case 'tiff':
|
||||
return FileCategory.image;
|
||||
case 'mp3':
|
||||
case 'wav':
|
||||
case 'ogg':
|
||||
case 'm4a':
|
||||
case 'aac':
|
||||
case 'flac':
|
||||
return FileCategory.audio;
|
||||
case 'mp4':
|
||||
case 'mov':
|
||||
case 'avi':
|
||||
case 'mkv':
|
||||
case 'webm':
|
||||
case 'wmv':
|
||||
return FileCategory.video;
|
||||
case 'zip':
|
||||
case 'rar':
|
||||
case '7z':
|
||||
case 'tar':
|
||||
case 'gz':
|
||||
case 'bz2':
|
||||
return FileCategory.archive;
|
||||
case 'txt':
|
||||
case 'md':
|
||||
case 'log':
|
||||
return FileCategory.text;
|
||||
case 'js':
|
||||
case 'ts':
|
||||
case 'json':
|
||||
case 'html':
|
||||
case 'css':
|
||||
case 'xml':
|
||||
case 'java':
|
||||
case 'kt':
|
||||
case 'dart':
|
||||
case 'py':
|
||||
case 'c':
|
||||
case 'cpp':
|
||||
case 'h':
|
||||
case 'cs':
|
||||
case 'swift':
|
||||
case 'go':
|
||||
case 'rb':
|
||||
case 'php':
|
||||
case 'sh':
|
||||
case 'yml':
|
||||
case 'yaml':
|
||||
return FileCategory.code;
|
||||
case 'apk':
|
||||
case 'ipa':
|
||||
case 'exe':
|
||||
case 'dmg':
|
||||
return FileCategory.other;
|
||||
}
|
||||
|
||||
final lowerType = mimeType.toLowerCase();
|
||||
|
||||
if (lowerType == 'application/pdf') return FileCategory.pdf;
|
||||
if (lowerType.startsWith('image/')) return FileCategory.image;
|
||||
if (lowerType.startsWith('audio/')) return FileCategory.audio;
|
||||
if (lowerType.startsWith('video/')) return FileCategory.video;
|
||||
if (lowerType.startsWith('text/')) return FileCategory.text;
|
||||
|
||||
if (lowerType.contains('zip') || lowerType.contains('compressed')) {
|
||||
return FileCategory.archive;
|
||||
}
|
||||
|
||||
if (lowerType.contains('msword') ||
|
||||
lowerType.contains('wordprocessingml')) {
|
||||
return FileCategory.document;
|
||||
}
|
||||
|
||||
if (lowerType.contains('spreadsheetml') ||
|
||||
lowerType.contains('excel') ||
|
||||
lowerType.contains('csv')) {
|
||||
return FileCategory.spreadsheet;
|
||||
}
|
||||
|
||||
if (lowerType.contains('presentationml') ||
|
||||
lowerType.contains('powerpoint')) {
|
||||
return FileCategory.presentation;
|
||||
}
|
||||
|
||||
if (lowerType == 'application/octet-stream') {
|
||||
return FileCategory.other;
|
||||
}
|
||||
|
||||
return FileCategory.other;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user