Fix #4 shared albums

This commit is contained in:
Alan Grainger
2024-10-30 19:53:09 +01:00
parent 43612fa89f
commit 6df65ec5b6
4 changed files with 32 additions and 7 deletions
+11 -3
View File
@@ -1,4 +1,4 @@
import { Asset, AssetType, ImageSize, SharedLink } from './types'
import { Album, Asset, AssetType, ImageSize, SharedLink } from './types'
import dayjs from 'dayjs'
import { log } from './index'
@@ -37,12 +37,20 @@ class Immich {
const res = (await this.request('/shared-links') || []) as SharedLink[]
const link = res.find(x => x.key === key)
if (link) {
// Filter assets to exclude trashed assets
link.assets = link.assets.filter(x => !x.isTrashed)
if (link.expiresAt && dayjs(link.expiresAt) < dayjs()) {
// This link has expired
log('Expired link ' + key)
} else {
if (link.type === 'ALBUM') {
// Fetch the assets from the album and populate the SharedLink assets array
const albumId = link.album?.id
if (albumId) {
const album = (await this.request('/albums/' + encodeURIComponent(albumId))) as Album
link.assets = album.assets || []
}
}
// Filter assets to exclude trashed assets
link.assets = link.assets.filter(x => !x.isTrashed)
return link
}
}