mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-02 06:46:22 +01:00
Fix removing photos from a server album incorrectly deleted it, and implement runtime blocks to prevent this from happening again
This commit is contained in:
parent
f2308abf84
commit
b007c3e764
5 changed files with 28 additions and 4 deletions
|
@ -375,7 +375,9 @@ class CollectionItemsController {
|
|||
return null;
|
||||
}
|
||||
} else {
|
||||
return e.copyWith(file: file);
|
||||
return e.copyWith(
|
||||
file: file.replacePath(e.file.fdPath),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
return e;
|
||||
|
|
|
@ -56,9 +56,7 @@ class CollectionNcAlbumAdapter
|
|||
i,
|
||||
// retain the path such that it is correctly recognized as part of an
|
||||
// album
|
||||
f?.copyWith(
|
||||
fdPath: i.path,
|
||||
),
|
||||
f?.replacePath(i.path),
|
||||
);
|
||||
}).toList();
|
||||
});
|
||||
|
|
|
@ -171,6 +171,10 @@ class FileNpDbDataSource implements FileDataSource2 {
|
|||
@override
|
||||
Future<void> remove(Account account, FileDescriptor f) async {
|
||||
_log.info("[remove] ${f.fdPath}");
|
||||
if (file_util.isNcAlbumFile(account, f)) {
|
||||
// removing from albums, not deleting the file
|
||||
return;
|
||||
}
|
||||
await db.deleteFile(
|
||||
account: account.toDb(),
|
||||
file: f.toDbKey(),
|
||||
|
|
|
@ -135,6 +135,14 @@ extension FileDescriptorExtension on FileDescriptor {
|
|||
isFavorite: fdIsFavorite,
|
||||
);
|
||||
}
|
||||
|
||||
FileDescriptor replacePath(String newPath) {
|
||||
if (this is File) {
|
||||
return (this as File).copyWith(path: newPath);
|
||||
} else {
|
||||
return copyWith(fdPath: newPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class FileDescriptorServerIdentityComparator {
|
||||
|
|
|
@ -5,6 +5,7 @@ import 'package:nc_photos/debug_util.dart';
|
|||
import 'package:nc_photos/di_container.dart';
|
||||
import 'package:nc_photos/entity/collection_item.dart';
|
||||
import 'package:nc_photos/entity/file_descriptor.dart';
|
||||
import 'package:nc_photos/entity/file_util.dart' as file_util;
|
||||
import 'package:nc_photos/entity/nc_album.dart';
|
||||
import 'package:nc_photos/use_case/remove.dart';
|
||||
import 'package:np_codegen/np_codegen.dart';
|
||||
|
@ -41,11 +42,22 @@ class RemoveFromNcAlbum {
|
|||
}
|
||||
})
|
||||
.cast<CollectionFileItem>()
|
||||
// since nextcloud album uses the DELETE method, we must make sure we
|
||||
// are "deleting" with an album path, not the actual file path
|
||||
.where((e) {
|
||||
if (file_util.isNcAlbumFile(account, e.file)) {
|
||||
return true;
|
||||
} else {
|
||||
_log.warning("[call] Wrong path for files in Nextcloud album");
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.toList();
|
||||
var count = fileItems.length;
|
||||
await Remove(_c)(
|
||||
account,
|
||||
fileItems.map((e) => e.file).toList(),
|
||||
shouldCleanUp: false,
|
||||
onError: (i, f, e, stackTrace) {
|
||||
--count;
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue