1
0
Fork 0
mirror of https://gitlab.com/nkming2/nc-photos.git synced 2025-03-23 15:37:10 +01:00
nc-photos/lib/entity/file_util.dart

47 lines
1.4 KiB
Dart
Raw Normal View History

2021-08-02 04:46:16 +08:00
import 'package:nc_photos/account.dart';
import 'package:nc_photos/api/api_util.dart' as api_util;
2021-04-10 12:28:12 +08:00
import 'package:nc_photos/entity/file.dart';
2021-05-06 19:36:20 +08:00
import 'package:nc_photos/platform/k.dart' as platform_k;
2021-04-10 12:28:12 +08:00
bool isSupportedFormat(File file) =>
_supportedFormatMimes.contains(file.contentType);
2021-05-06 14:29:46 +08:00
bool isSupportedImageFormat(File file) =>
isSupportedFormat(file) && file.contentType?.startsWith("image/") == true;
2021-05-06 19:36:20 +08:00
bool isSupportedVideoFormat(File file) =>
isSupportedFormat(file) && file.contentType?.startsWith("video/") == true;
bool isMetadataSupportedFormat(File file) =>
_metadataSupportedFormatMimes.contains(file.contentType);
2021-08-02 04:46:16 +08:00
bool isTrash(Account account, File file) =>
file.path.startsWith(api_util.getTrashbinPath(account));
/// For a path "remote.php/dav/files/foo/bar.jpg", return foo
String getUserDirName(File file) {
if (file.path.startsWith("remote.php/dav/files/")) {
final beg = "remote.php/dav/files/".length;
final end = file.path.indexOf("/", beg);
if (end != -1) {
return file.path.substring(beg, end);
}
}
throw ArgumentError("Invalid path: ${file.path}");
}
2021-07-05 00:32:35 +08:00
final _supportedFormatMimes = [
2021-04-10 12:28:12 +08:00
"image/jpeg",
"image/png",
"image/webp",
2021-04-15 05:09:31 +08:00
"image/heic",
2021-06-22 13:24:37 +08:00
"image/gif",
2021-08-05 15:04:12 +08:00
"video/mp4",
if (platform_k.isAndroid || platform_k.isWeb) "video/webm",
2021-04-10 12:28:12 +08:00
];
const _metadataSupportedFormatMimes = [
"image/jpeg",
"image/heic",
];