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) {
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);
}
},

View File

@ -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;