2021-08-01 22:46:16 +02:00
|
|
|
import 'package:nc_photos/account.dart';
|
|
|
|
import 'package:nc_photos/api/api_util.dart' as api_util;
|
2021-11-12 22:13:02 +01:00
|
|
|
import 'package:nc_photos/ci_string.dart';
|
2021-04-10 06:28:12 +02:00
|
|
|
import 'package:nc_photos/entity/file.dart';
|
2021-05-06 13:36:20 +02:00
|
|
|
import 'package:nc_photos/platform/k.dart' as platform_k;
|
2021-11-12 12:44:31 +01:00
|
|
|
import 'package:nc_photos/remote_storage_util.dart' as remote_storage_util;
|
2021-11-16 16:06:22 +01:00
|
|
|
import 'package:nc_photos/string_extension.dart';
|
2021-10-08 09:01:27 +02:00
|
|
|
import 'package:path/path.dart' as path;
|
2021-04-10 06:28:12 +02:00
|
|
|
|
2021-10-06 22:32:36 +02:00
|
|
|
bool isSupportedMime(String mime) => _supportedFormatMimes.contains(mime);
|
|
|
|
|
|
|
|
bool isSupportedFormat(File file) => isSupportedMime(file.contentType ?? "");
|
2021-04-10 06:28:12 +02:00
|
|
|
|
2021-05-06 08:29:46 +02:00
|
|
|
bool isSupportedImageFormat(File file) =>
|
|
|
|
isSupportedFormat(file) && file.contentType?.startsWith("image/") == true;
|
|
|
|
|
2021-05-06 13:36:20 +02:00
|
|
|
bool isSupportedVideoFormat(File file) =>
|
|
|
|
isSupportedFormat(file) && file.contentType?.startsWith("video/") == true;
|
|
|
|
|
2021-05-06 22:11:31 +02:00
|
|
|
bool isMetadataSupportedFormat(File file) =>
|
|
|
|
_metadataSupportedFormatMimes.contains(file.contentType);
|
|
|
|
|
2021-08-01 22:46:16 +02:00
|
|
|
bool isTrash(Account account, File file) =>
|
|
|
|
file.path.startsWith(api_util.getTrashbinPath(account));
|
|
|
|
|
2021-11-12 12:44:31 +01:00
|
|
|
bool isAlbumFile(Account account, File file) =>
|
|
|
|
file.path.startsWith(remote_storage_util.getRemoteAlbumsDir(account));
|
|
|
|
|
2021-11-15 18:55:39 +01:00
|
|
|
/// Return if [file] is located under [dir]
|
|
|
|
///
|
|
|
|
/// Return false if [file] is [dir] itself (since it's not "under")
|
|
|
|
///
|
|
|
|
/// See [isOrUnderDir]
|
|
|
|
bool isUnderDir(File file, File dir) => file.path.startsWith("${dir.path}/");
|
|
|
|
|
|
|
|
/// Return if [file] is [dir] or located under [dir]
|
|
|
|
///
|
|
|
|
/// See [isUnderDir]
|
|
|
|
bool isOrUnderDir(File file, File dir) =>
|
|
|
|
file.path == dir.path || isUnderDir(file, dir);
|
|
|
|
|
2021-11-16 16:06:22 +01:00
|
|
|
/// Convert a stripped path to a full path
|
|
|
|
///
|
|
|
|
/// See [File.strippedPath]
|
|
|
|
String unstripPath(Account account, String strippedPath) =>
|
|
|
|
"${api_util.getWebdavRootUrlRelative(account)}/$strippedPath"
|
|
|
|
.trimRightAny("/");
|
|
|
|
|
2021-06-14 15:51:29 +02:00
|
|
|
/// For a path "remote.php/dav/files/foo/bar.jpg", return foo
|
2021-11-12 22:13:02 +01:00
|
|
|
CiString getUserDirName(File file) {
|
2021-06-14 15:51:29 +02:00
|
|
|
if (file.path.startsWith("remote.php/dav/files/")) {
|
2021-09-15 08:58:06 +02:00
|
|
|
const beg = "remote.php/dav/files/".length;
|
2021-06-14 15:51:29 +02:00
|
|
|
final end = file.path.indexOf("/", beg);
|
|
|
|
if (end != -1) {
|
2021-11-12 22:13:02 +01:00
|
|
|
return file.path.substring(beg, end).toCi();
|
2021-06-14 15:51:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
throw ArgumentError("Invalid path: ${file.path}");
|
|
|
|
}
|
|
|
|
|
2021-10-08 09:01:27 +02:00
|
|
|
String renameConflict(String filename, int conflictCount) {
|
|
|
|
final temp = "${path.basenameWithoutExtension(filename)} ($conflictCount)";
|
|
|
|
if (path.extension(filename).isEmpty) {
|
|
|
|
return temp;
|
|
|
|
} else {
|
|
|
|
return "$temp${path.extension(filename)}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-04 18:32:35 +02:00
|
|
|
final _supportedFormatMimes = [
|
2021-04-10 06:28:12 +02:00
|
|
|
"image/jpeg",
|
|
|
|
"image/png",
|
|
|
|
"image/webp",
|
2021-04-14 23:09:31 +02:00
|
|
|
"image/heic",
|
2021-06-22 07:24:37 +02:00
|
|
|
"image/gif",
|
2021-08-05 09:04:12 +02:00
|
|
|
"video/mp4",
|
2021-09-20 10:53:42 +02:00
|
|
|
"video/quicktime",
|
2021-08-05 09:04:12 +02:00
|
|
|
if (platform_k.isAndroid || platform_k.isWeb) "video/webm",
|
2021-04-10 06:28:12 +02:00
|
|
|
];
|
2021-05-06 22:11:31 +02:00
|
|
|
|
|
|
|
const _metadataSupportedFormatMimes = [
|
|
|
|
"image/jpeg",
|
|
|
|
"image/heic",
|
|
|
|
];
|