dav: improve deleting error handling

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/653/head
Varun Patil 2023-05-14 22:33:02 -07:00
parent 1fb15a2f51
commit 6dfd9762fc
3 changed files with 15 additions and 22 deletions

View File

@ -754,8 +754,13 @@ export default defineComponent({
}
}
for await (const delIds of dav.deletePhotos(Array.from(selection.values()))) {
this.deleteSelectedPhotosById(delIds, selection);
try {
for await (const delIds of dav.deletePhotos(Array.from(selection.values()))) {
this.deleteSelectedPhotosById(delIds, selection);
}
} catch (e) {
console.error(e);
showError(this.t('memories', 'Failed to delete files'));
}
},

View File

@ -918,6 +918,9 @@ export default defineComponent({
for await (const p of dav.deletePhotos([photo])) {
if (!p[0]) return;
}
} catch {
showError(this.t('memories', 'Failed to delete photo'));
return;
} finally {
this.updateLoading(-1);
}

View File

@ -208,34 +208,19 @@ export async function* deletePhotos(photos: IPhoto[]) {
let fileIdsSet = new Set(photos.map((p) => p.fileid));
// Get files data
let fileInfos: IFileInfo[] = [];
try {
fileInfos = await getFiles(photos);
const fileInfos = (await getFiles(photos)).filter((f) => fileIdsSet.has(f.fileid));
// Take intersection of fileIds and fileInfos
fileInfos = fileInfos.filter((f) => fileIdsSet.has(f.fileid));
fileIdsSet = new Set(fileInfos.map((f) => f.fileid));
} catch (e) {
console.error('Failed to get file info for files to delete', photos, e);
showError(t('memories', 'Failed to delete files.'));
return;
}
// Take intersection of fileIds and fileInfos
fileIdsSet = new Set(fileInfos.map((f) => f.fileid));
// Check for local photos
try {
let deleted = await nativex.deleteLocalPhotos(photos);
// Don't remove remote files just yet
deleted = deleted.filter((f) => !fileIdsSet.has(f.fileid));
if (nativex.has()) {
const deleted = (await nativex.deleteLocalPhotos(photos)).filter((f) => !fileIdsSet.has(f.fileid));
// Yield for the fully local files
if (deleted.length > 0) {
yield deleted.map((f) => f.fileid);
}
} catch (e) {
console.error(e);
showError(t('memories', 'Failed to delete local files.'));
return;
}
// Delete each file