albums: fix changing albums from album (fix #795)

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/803/head
Varun Patil 2023-08-28 15:23:43 -07:00
parent 6ca3b10606
commit 9b12b2ab41
3 changed files with 21 additions and 9 deletions

View File

@ -143,7 +143,7 @@
</NcActionButton>
<NcActionButton
:aria-label="t('memories', 'Add to album')"
v-if="config.albums_enabled && !isLocal && !routeIsPublic && canShare"
v-if="config.albums_enabled && !isLocal && !routeIsPublic && canShare && currentPhoto?.imageInfo?.filename"
@click="updateAlbums"
:close-after-click="true"
>

View File

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

View File

@ -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<IFileInfo[]> {
// Check if albums
const route = vueroute();
if (route.name === 'albums') {
return getAlbumFileInfos(photos, <string>route.params.user, <string>route.params.name);
export async function getFiles(photos: IPhoto[], opts?: GetFilesOpts): Promise<IFileInfo[]> {
// Some routes may have special handling of filenames
if (!opts?.ignoreRoute) {
const route = vueroute();
// Check if albums
if (route.name === 'albums') {
return getAlbumFileInfos(photos, <string>route.params.user, <string>route.params.name);
}
}
// Remove any local photos
@ -59,7 +71,7 @@ export async function getFiles(photos: IPhoto[]): Promise<IFileInfo[]> {
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) {