From 9b12b2ab41d4293d9cdaccb2063bda072f787b8e Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Mon, 28 Aug 2023 15:23:43 -0700 Subject: [PATCH] albums: fix changing albums from album (fix #795) Signed-off-by: Varun Patil --- src/components/viewer/Viewer.vue | 2 +- src/services/dav/albums.ts | 4 ++-- src/services/dav/base.ts | 24 ++++++++++++++++++------ 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/components/viewer/Viewer.vue b/src/components/viewer/Viewer.vue index 72ba0c8c..ee2cc237 100644 --- a/src/components/viewer/Viewer.vue +++ b/src/components/viewer/Viewer.vue @@ -143,7 +143,7 @@ diff --git a/src/services/dav/albums.ts b/src/services/dav/albums.ts index 9b887445..6e1770a1 100644 --- a/src/services/dav/albums.ts +++ b/src/services/dav/albums.ts @@ -54,7 +54,7 @@ export async function getAlbums(sort: 1 | 2 = 1, fileid?: number) { */ export async function* addToAlbum(user: string, name: string, photos: IPhoto[]) { // Get files data - let fileInfos = await base.getFiles(photos); + const fileInfos = await base.getFiles(photos, { ignoreRoute: true }); const albumPath = getAlbumPath(user, name); // Add each file @@ -92,7 +92,7 @@ export async function* addToAlbum(user: string, name: string, photos: IPhoto[]) */ export async function* removeFromAlbum(user: string, name: string, photos: IPhoto[]) { // Get files data - let fileInfos = await base.getFiles(photos); + const fileInfos = await base.getFiles(photos, { ignoreRoute: true }); const albumPath = getAlbumPath(user, name); // Remove each file diff --git a/src/services/dav/base.ts b/src/services/dav/base.ts index 1a338965..b1927fdf 100644 --- a/src/services/dav/base.ts +++ b/src/services/dav/base.ts @@ -38,17 +38,29 @@ export const IMAGE_MIME_TYPES = [ const GET_FILE_CHUNK_SIZE = 50; +type GetFilesOpts = { + /** Attempt to use some cached value to get filename (default true) */ + cache?: boolean; + /** Get original route-independent filename for current user only (default false) */ + ignoreRoute?: boolean; +}; + /** * Get file infos for list of files given Ids * @param photos list of photos + * @param opts options * @details This tries to use the cached filename in the photo object (imageInfo.filename) * If none was found, then it will fetch the file info from the server. */ -export async function getFiles(photos: IPhoto[]): Promise { - // Check if albums - const route = vueroute(); - if (route.name === 'albums') { - return getAlbumFileInfos(photos, route.params.user, route.params.name); +export async function getFiles(photos: IPhoto[], opts?: GetFilesOpts): Promise { + // Some routes may have special handling of filenames + if (!opts?.ignoreRoute) { + const route = vueroute(); + + // Check if albums + if (route.name === 'albums') { + return getAlbumFileInfos(photos, route.params.user, route.params.name); + } } // Remove any local photos @@ -59,7 +71,7 @@ export async function getFiles(photos: IPhoto[]): Promise { const rest: IPhoto[] = []; // Partition photos with and without cache - if (utils.uid) { + if (utils.uid && opts?.cache !== false) { for (const photo of photos) { const filename = photo.imageInfo?.filename; if (filename) {