Fix stripped path of nc album and item

This commit is contained in:
Ming Ming 2023-07-12 00:11:37 +08:00
parent 705a54762d
commit 7417dd9533
2 changed files with 11 additions and 15 deletions

View file

@ -74,18 +74,18 @@ extension NcAlbumExtension on NcAlbum {
/// WebDAV file path: remote.php/dav/photos/{userId}/albums/{strippedPath}.
/// If this path points to the user's root album path, return "."
String get strippedPath {
if (!path.startsWith("remote.php/dav/photos/")) {
return path;
if (!path.startsWith("${api.ApiPhotos.path}/")) {
throw ArgumentError("Unsupported path: $path");
}
var begin = "remote.php/dav/photos/".length;
var begin = "${api.ApiPhotos.path}/".length;
begin = path.indexOf("/", begin);
if (begin == -1) {
return path;
throw ArgumentError("Unsupported path: $path");
}
// /albums/{strippedPath}
if (path.slice(begin, begin + 7) != "/albums") {
return path;
}
// /albums/
begin += 8;
final stripped = path.slice(begin);
if (stripped.isEmpty) {

View file

@ -42,28 +42,24 @@ extension NcAlbumItemExtension on NcAlbumItem {
/// If this path points to the user's root album path, return "."
String get strippedPath {
if (!path.startsWith("${api.ApiPhotos.path}/")) {
return path;
throw ArgumentError("Unsupported path: $path");
}
var begin = "${api.ApiPhotos.path}/".length;
begin = path.indexOf("/", begin);
if (begin == -1) {
return path;
throw ArgumentError("Unsupported path: $path");
}
// /albums/{album}/{strippedPath}
if (path.slice(begin, begin + 7) != "/albums") {
return path;
throw ArgumentError("Unsupported path: $path");
}
// /albums/
begin += 8;
// {album}/{strippedPath}
begin = path.indexOf("/", begin);
if (begin == -1) {
return path;
}
final stripped = path.slice(begin + 1);
if (stripped.isEmpty) {
return ".";
} else {
return stripped;
}
return path.slice(begin + 1);
}
bool compareIdentity(NcAlbumItem other) => fileId == other.fileId;