Fix #4 shared albums
This commit is contained in:
+11
-3
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,10 +11,18 @@ export interface Asset {
|
||||
|
||||
export interface SharedLink {
|
||||
key: string;
|
||||
type: string;
|
||||
assets: Asset[];
|
||||
album?: {
|
||||
id: string;
|
||||
}
|
||||
expiresAt: string | null;
|
||||
}
|
||||
|
||||
export interface Album {
|
||||
assets: Asset[]
|
||||
}
|
||||
|
||||
export enum ImageSize {
|
||||
thumbnail = 'thumbnail',
|
||||
original = 'original'
|
||||
|
||||
Reference in New Issue
Block a user