diff --git a/src/components/SelectionManager.vue b/src/components/SelectionManager.vue index 29941908..1992cb32 100644 --- a/src/components/SelectionManager.vue +++ b/src/components/SelectionManager.vue @@ -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')); } }, diff --git a/src/components/viewer/Viewer.vue b/src/components/viewer/Viewer.vue index ef04ae2d..a44eddec 100644 --- a/src/components/viewer/Viewer.vue +++ b/src/components/viewer/Viewer.vue @@ -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); } diff --git a/src/services/dav/base.ts b/src/services/dav/base.ts index ad5e0a3b..06e2c6c4 100644 --- a/src/services/dav/base.ts +++ b/src/services/dav/base.ts @@ -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