54 lines
1.4 KiB
Dart
54 lines
1.4 KiB
Dart
import 'package:file_saver/file_saver.dart';
|
|
|
|
class FileClassification {
|
|
static String? getFileName(String url) {
|
|
Uri uri = Uri.parse(url);
|
|
return uri.pathSegments.isNotEmpty ? uri.pathSegments.last : null;
|
|
}
|
|
|
|
static String getFileClass(String url) {
|
|
String? fileName = getFileName(url);
|
|
if (fileName == null) return 'unknown';
|
|
|
|
// Get the file extension
|
|
String extension = fileName.split('.').last.toLowerCase();
|
|
|
|
// Determine the class based on the file extension
|
|
if (['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp'].contains(extension)) {
|
|
return 'image';
|
|
} else if (['mp3', 'wav', 'ogg', 'aac'].contains(extension)) {
|
|
return 'audio';
|
|
} else if (['mp4', 'mkv', 'webm', 'avi', 'mov'].contains(extension)) {
|
|
return 'video';
|
|
} else {
|
|
return 'unknown';
|
|
}
|
|
}
|
|
|
|
|
|
static MimeType getMimeType(String filename) {
|
|
String extension = filename.split('.').last.toLowerCase();
|
|
switch (extension.toLowerCase()) {
|
|
case 'jpg':
|
|
case 'jpeg':
|
|
return MimeType.jpeg;
|
|
case 'png':
|
|
return MimeType.png;
|
|
case 'gif':
|
|
return MimeType.gif;
|
|
case 'bmp':
|
|
return MimeType.bmp;
|
|
case 'mp3':
|
|
return MimeType.mp3;
|
|
case 'aac':
|
|
return MimeType.aac;
|
|
case 'mp4':
|
|
return MimeType.mp4Video;
|
|
case 'avi':
|
|
return MimeType.avi;
|
|
default:
|
|
return MimeType.other; // Fallback for unknown types
|
|
}
|
|
}
|
|
|
|
} |