#87 fetch album assets separately to address change in Immich 1.132+
This commit is contained in:
+32
-3
@@ -1,4 +1,13 @@
|
|||||||
import { Asset, AssetType, ImageSize, IncomingShareRequest, SharedLink, SharedLinkResult } from './types'
|
import {
|
||||||
|
Album,
|
||||||
|
AlbumType,
|
||||||
|
Asset,
|
||||||
|
AssetType,
|
||||||
|
ImageSize,
|
||||||
|
IncomingShareRequest,
|
||||||
|
SharedLink,
|
||||||
|
SharedLinkResult
|
||||||
|
} from './types'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { addResponseHeaders, canDownload, getConfigOption, log } from './functions'
|
import { addResponseHeaders, canDownload, getConfigOption, log } from './functions'
|
||||||
import render from './render'
|
import render from './render'
|
||||||
@@ -94,14 +103,15 @@ class Immich {
|
|||||||
respondToInvalidRequest(res, 404)
|
respondToInvalidRequest(res, 404)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const link = sharedLinkRes.link
|
||||||
|
|
||||||
// Make sure there are some photo/video assets for this link
|
// Make sure there are some photo/video assets for this link
|
||||||
const link = sharedLinkRes.link
|
/*
|
||||||
if (!link.assets.length) {
|
if (!link.assets.length) {
|
||||||
log('No assets for key ' + request.key)
|
log('No assets for key ' + request.key)
|
||||||
respondToInvalidRequest(res, 404)
|
respondToInvalidRequest(res, 404)
|
||||||
return
|
return
|
||||||
}
|
} */
|
||||||
|
|
||||||
// Everything is ok - output the shared link data
|
// Everything is ok - output the shared link data
|
||||||
|
|
||||||
@@ -145,6 +155,25 @@ class Immich {
|
|||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
// Normal response - get the shared assets
|
// Normal response - get the shared assets
|
||||||
link = jsonBody as SharedLink
|
link = jsonBody as SharedLink
|
||||||
|
|
||||||
|
// For an album, we need to make a second request to Immich to populate
|
||||||
|
// the array of assets
|
||||||
|
if (link.type === AlbumType.album) {
|
||||||
|
const albumRes = await fetch(this.buildUrl(this.apiUrl() + '/albums/' + link?.album?.id, {
|
||||||
|
key,
|
||||||
|
password
|
||||||
|
}))
|
||||||
|
const album = await albumRes.json() as Album
|
||||||
|
if (!album?.id) {
|
||||||
|
log('Invalid album ID - ' + link?.album?.id)
|
||||||
|
return {
|
||||||
|
valid: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Replace the empty link.assets array with the array of assets from the album
|
||||||
|
link.assets = album.assets
|
||||||
|
}
|
||||||
|
|
||||||
link.password = password
|
link.password = password
|
||||||
if (link.expiresAt && dayjs(link.expiresAt) < dayjs()) {
|
if (link.expiresAt && dayjs(link.expiresAt) < dayjs()) {
|
||||||
// This link has expired
|
// This link has expired
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ export enum AssetType {
|
|||||||
video = 'VIDEO'
|
video = 'VIDEO'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export enum AlbumType {
|
||||||
|
album = 'ALBUM',
|
||||||
|
individual = 'INDIVIDUAL'
|
||||||
|
}
|
||||||
|
|
||||||
export interface Asset {
|
export interface Asset {
|
||||||
id: string;
|
id: string;
|
||||||
key: string;
|
key: string;
|
||||||
@@ -15,6 +20,11 @@ export interface Asset {
|
|||||||
isTrashed: boolean;
|
isTrashed: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface Album {
|
||||||
|
id: string;
|
||||||
|
assets: Asset[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface SharedLink {
|
export interface SharedLink {
|
||||||
key: string;
|
key: string;
|
||||||
type: string;
|
type: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user