mirror of
https://gitlab.com/nkming2/nc-photos.git
synced 2025-02-12 20:47:42 +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;
|
return null;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return e.copyWith(file: file);
|
return e.copyWith(
|
||||||
|
file: file.replacePath(e.file.fdPath),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return e;
|
return e;
|
||||||
|
|
|
@ -56,9 +56,7 @@ class CollectionNcAlbumAdapter
|
||||||
i,
|
i,
|
||||||
// retain the path such that it is correctly recognized as part of an
|
// retain the path such that it is correctly recognized as part of an
|
||||||
// album
|
// album
|
||||||
f?.copyWith(
|
f?.replacePath(i.path),
|
||||||
fdPath: i.path,
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}).toList();
|
}).toList();
|
||||||
});
|
});
|
||||||
|
|
|
@ -171,6 +171,10 @@ class FileNpDbDataSource implements FileDataSource2 {
|
||||||
@override
|
@override
|
||||||
Future<void> remove(Account account, FileDescriptor f) async {
|
Future<void> remove(Account account, FileDescriptor f) async {
|
||||||
_log.info("[remove] ${f.fdPath}");
|
_log.info("[remove] ${f.fdPath}");
|
||||||
|
if (file_util.isNcAlbumFile(account, f)) {
|
||||||
|
// removing from albums, not deleting the file
|
||||||
|
return;
|
||||||
|
}
|
||||||
await db.deleteFile(
|
await db.deleteFile(
|
||||||
account: account.toDb(),
|
account: account.toDb(),
|
||||||
file: f.toDbKey(),
|
file: f.toDbKey(),
|
||||||
|
|
|
@ -135,6 +135,14 @@ extension FileDescriptorExtension on FileDescriptor {
|
||||||
isFavorite: fdIsFavorite,
|
isFavorite: fdIsFavorite,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FileDescriptor replacePath(String newPath) {
|
||||||
|
if (this is File) {
|
||||||
|
return (this as File).copyWith(path: newPath);
|
||||||
|
} else {
|
||||||
|
return copyWith(fdPath: newPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class FileDescriptorServerIdentityComparator {
|
class FileDescriptorServerIdentityComparator {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import 'package:nc_photos/debug_util.dart';
|
||||||
import 'package:nc_photos/di_container.dart';
|
import 'package:nc_photos/di_container.dart';
|
||||||
import 'package:nc_photos/entity/collection_item.dart';
|
import 'package:nc_photos/entity/collection_item.dart';
|
||||||
import 'package:nc_photos/entity/file_descriptor.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/entity/nc_album.dart';
|
||||||
import 'package:nc_photos/use_case/remove.dart';
|
import 'package:nc_photos/use_case/remove.dart';
|
||||||
import 'package:np_codegen/np_codegen.dart';
|
import 'package:np_codegen/np_codegen.dart';
|
||||||
|
@ -41,11 +42,22 @@ class RemoveFromNcAlbum {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.cast<CollectionFileItem>()
|
.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();
|
.toList();
|
||||||
var count = fileItems.length;
|
var count = fileItems.length;
|
||||||
await Remove(_c)(
|
await Remove(_c)(
|
||||||
account,
|
account,
|
||||||
fileItems.map((e) => e.file).toList(),
|
fileItems.map((e) => e.file).toList(),
|
||||||
|
shouldCleanUp: false,
|
||||||
onError: (i, f, e, stackTrace) {
|
onError: (i, f, e, stackTrace) {
|
||||||
--count;
|
--count;
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue