dav: refactor archive to use photo list

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/900/head
Varun Patil 2023-10-30 11:39:15 -07:00
parent 2c81503484
commit ef44965dee
2 changed files with 16 additions and 14 deletions

View File

@ -809,7 +809,7 @@ export default defineComponent({
async archiveSelection(selection: Selection) { async archiveSelection(selection: Selection) {
if (selection.size >= 50 && !(await utils.dialogs.moveItems(selection.size))) return; 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); this.deleteSelectedPhotosById(delIds, selection);
} }
}, },

View File

@ -1,8 +1,12 @@
import * as base from './base'; import * as base from './base';
import { showError } from '@nextcloud/dialogs'; import { showError } from '@nextcloud/dialogs';
import { translate as t } from '@services/l10n';
import axios from '@nextcloud/axios'; 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 * Archive or unarchive a single file
@ -10,29 +14,27 @@ import { API } from '../API';
* @param fileid File id * @param fileid File id
* @param archive Archive or unarchive * @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 }); 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 * @param archive Archive or unarchive
* @returns list of file ids that were deleted * @returns list of file ids that were deleted
*/ */
export async function* archiveFilesByIds(fileIds: number[], archive: boolean) { export async function* archiveFilesByIds(photos: IPhoto[], archive: boolean) {
if (fileIds.length === 0) { if (!photos.length) return;
return;
}
// Archive each file // Archive each file
const calls = fileIds.map((id) => async () => { const calls = photos.map((photo) => async () => {
try { try {
await archiveFile(id, archive); await archiveFile(photo.fileid, archive);
return id as number; return photo.fileid;
} catch (error) { } 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'); const msg = error?.response?.data?.message || t('memories', 'General Failure');
showError(t('memories', 'Error: {msg}', { msg })); showError(t('memories', 'Error: {msg}', { msg }));
return 0; return 0;