From ef44965deef305fce46ff549952d09193a0f060b Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Mon, 30 Oct 2023 11:39:15 -0700 Subject: [PATCH] dav: refactor archive to use photo list Signed-off-by: Varun Patil --- src/components/SelectionManager.vue | 2 +- src/services/dav/archive.ts | 28 +++++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/components/SelectionManager.vue b/src/components/SelectionManager.vue index 271ea546..b7d248e9 100644 --- a/src/components/SelectionManager.vue +++ b/src/components/SelectionManager.vue @@ -809,7 +809,7 @@ export default defineComponent({ async archiveSelection(selection: Selection) { if (selection.size >= 50 && !(await utils.dialogs.moveItems(selection.size))) return; - for await (let delIds of dav.archiveFilesByIds(Array.from(selection.fileids()), !this.routeIsArchive)) { + for await (let delIds of dav.archiveFilesByIds(selection.photosNoDupFileId(), !this.routeIsArchive)) { this.deleteSelectedPhotosById(delIds, selection); } }, diff --git a/src/services/dav/archive.ts b/src/services/dav/archive.ts index 2208dadc..61711a3a 100644 --- a/src/services/dav/archive.ts +++ b/src/services/dav/archive.ts @@ -1,8 +1,12 @@ import * as base from './base'; + import { showError } from '@nextcloud/dialogs'; -import { translate as t } from '@services/l10n'; import axios from '@nextcloud/axios'; -import { API } from '../API'; + +import { translate as t } from '@services/l10n'; +import { API } from '@services/API'; + +import type { IPhoto } from '@typings'; /** * Archive or unarchive a single file @@ -10,29 +14,27 @@ import { API } from '../API'; * @param fileid File id * @param archive Archive or unarchive */ -export async function archiveFile(fileid: number, archive: boolean) { +async function archiveFile(fileid: number, archive: boolean) { return await axios.patch(API.ARCHIVE(fileid), { archive }); } /** - * Archive all files in a given list of Ids + * Archive all photos in a given list * - * @param fileIds list of file ids + * @param photos list of photos to process * @param archive Archive or unarchive * @returns list of file ids that were deleted */ -export async function* archiveFilesByIds(fileIds: number[], archive: boolean) { - if (fileIds.length === 0) { - return; - } +export async function* archiveFilesByIds(photos: IPhoto[], archive: boolean) { + if (!photos.length) return; // Archive each file - const calls = fileIds.map((id) => async () => { + const calls = photos.map((photo) => async () => { try { - await archiveFile(id, archive); - return id as number; + await archiveFile(photo.fileid, archive); + return photo.fileid; } catch (error) { - console.error('Failed to (un)archive', id, error); + console.error('Failed to (un)archive', photo.fileid, error); const msg = error?.response?.data?.message || t('memories', 'General Failure'); showError(t('memories', 'Error: {msg}', { msg })); return 0;