Remove locked assets from shares
This commit is contained in:
+2
-1
@@ -204,7 +204,7 @@ async function fetchShareByKey (key: string, password?: string, keyType: KeyType
|
||||
log('Shared link ' + key + ' returned no assets array (type ' + link.type + ')')
|
||||
link.assets = []
|
||||
}
|
||||
// Drop trashed assets, and any Immich hasn't finished processing
|
||||
// Drop trashed and locked assets, and any Immich hasn't finished processing
|
||||
link.assets = servableAssets(link.assets)
|
||||
// Populate the shared assets with the public key/password
|
||||
link.assets.forEach(asset => {
|
||||
@@ -284,6 +284,7 @@ function timelineBucketToAssets (bucket: TimelineBucketAssets): Asset[] {
|
||||
localDateTime: localDateTimeFromOffset(fileCreatedAt, bucket.localOffsetHours?.[i]),
|
||||
thumbhash: bucket.thumbhash?.[i] || undefined,
|
||||
livePhotoVideoId: bucket.livePhotoVideoId?.[i] || undefined,
|
||||
visibility: bucket.visibility?.[i],
|
||||
width,
|
||||
height,
|
||||
needsDetail: true
|
||||
|
||||
+8
-5
@@ -1,4 +1,4 @@
|
||||
import { Asset, getConfigOption, KeyType, log, SharedLink, TtlLruCache } from '@ipp/core'
|
||||
import { Asset, AssetVisibility, getConfigOption, KeyType, log, SharedLink, TtlLruCache } from '@ipp/core'
|
||||
import { DownloadAll } from './types'
|
||||
import dayjs from 'dayjs'
|
||||
|
||||
@@ -72,14 +72,17 @@ export function uploadLink (share: SharedLink): string | undefined {
|
||||
const warnedUnprocessed = new TtlLruCache<true>({ ttlMs: 24 * 60 * 60_000, max: 1000 })
|
||||
|
||||
/**
|
||||
* Narrow a share's assets to what IPP can render: not trashed, and finished
|
||||
* processing in Immich. `thumbhash` is the readiness signal: Immich's
|
||||
* thumbnail job writes the files and only then sets it, so until it appears
|
||||
* every image URL IPP hands out would 404.
|
||||
* Narrow a share's assets to what IPP can render: not trashed, not in the
|
||||
* owner's locked folder, and finished processing in Immich. Immich's share
|
||||
* listing does not filter on visibility, so a locked asset has to go here.
|
||||
* `thumbhash` is the readiness signal: Immich's thumbnail job writes the
|
||||
* files and only then sets it, so until it appears every image URL IPP hands
|
||||
* out would 404.
|
||||
*/
|
||||
export function servableAssets (assets: Asset[]): Asset[] {
|
||||
return assets.filter(asset => {
|
||||
if (asset.isTrashed) return false
|
||||
if (asset.visibility === AssetVisibility.locked) return false
|
||||
if (asset.thumbhash) return true
|
||||
if (!warnedUnprocessed.get(asset.id)) {
|
||||
warnedUnprocessed.set(asset.id, true)
|
||||
|
||||
+2
-1
@@ -1,5 +1,5 @@
|
||||
import { Request } from 'express-serve-static-core'
|
||||
import { KeyType } from '@ipp/core'
|
||||
import { AssetVisibility, KeyType } from '@ipp/core'
|
||||
|
||||
/**
|
||||
* One entry of `GET /timeline/buckets` - a time bucket (month) and its count.
|
||||
@@ -27,6 +27,7 @@ export interface TimelineBucketAssets {
|
||||
localOffsetHours: number[];
|
||||
// Motion photo (Live Photo) clip id; null for ordinary assets.
|
||||
livePhotoVideoId: (string | null)[];
|
||||
visibility: AssetVisibility[];
|
||||
}
|
||||
|
||||
export enum ImageSize {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { describe, it, expect, vi } from 'vitest'
|
||||
import { Asset, AssetType, AssetVisibility, KeyType } from '@ipp/core'
|
||||
import { servableAssets } from '../src/share'
|
||||
|
||||
function asset (overrides: Partial<Asset> = {}): Asset {
|
||||
return {
|
||||
id: 'a1',
|
||||
key: 'k',
|
||||
keyType: KeyType.key,
|
||||
type: AssetType.image,
|
||||
isTrashed: false,
|
||||
thumbhash: 'abc',
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
|
||||
describe('servableAssets', () => {
|
||||
it('keeps a processed, visible asset', () => {
|
||||
expect(servableAssets([asset()])).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('drops a locked asset even when Immich lists it', () => {
|
||||
expect(servableAssets([asset({ visibility: AssetVisibility.locked })])).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('keeps archived assets, which Immich shows in albums and shares', () => {
|
||||
expect(servableAssets([asset({ visibility: AssetVisibility.archive })])).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('keeps an asset with no visibility field, for Immich responses that omit it', () => {
|
||||
expect(servableAssets([asset({ visibility: undefined })])).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('drops trashed and unprocessed assets', () => {
|
||||
vi.spyOn(console, 'warn').mockImplementation(() => {})
|
||||
vi.spyOn(console, 'log').mockImplementation(() => {})
|
||||
expect(servableAssets([asset({ isTrashed: true })])).toHaveLength(0)
|
||||
expect(servableAssets([asset({ id: 'a2', thumbhash: undefined })])).toHaveLength(0)
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user