From 285d48e9d09852d33d2f9296d337ba42d0cf1da6 Mon Sep 17 00:00:00 2001 From: Alan Grainger <16197738+alangrainger@users.noreply.github.com> Date: Wed, 7 Oct 2026 18:08:12 +1300 Subject: [PATCH] Remove locked assets from shares --- app/src/immich.ts | 3 ++- app/src/share.ts | 13 +++++---- app/src/types.ts | 3 ++- app/tests/servableAssets.test.ts | 41 +++++++++++++++++++++++++++++ docs/introduction.md | 2 +- shared/src/types.ts | 11 ++++++++ shared/tests/session.test.ts | 6 +---- upload-app/src/idleTimeoutStream.ts | 9 +++---- 8 files changed, 69 insertions(+), 19 deletions(-) create mode 100644 app/tests/servableAssets.test.ts diff --git a/app/src/immich.ts b/app/src/immich.ts index cb748b2..4d6e09b 100644 --- a/app/src/immich.ts +++ b/app/src/immich.ts @@ -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 diff --git a/app/src/share.ts b/app/src/share.ts index ece8df4..18200cf 100644 --- a/app/src/share.ts +++ b/app/src/share.ts @@ -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({ 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) diff --git a/app/src/types.ts b/app/src/types.ts index 5d2fc4f..3de1b08 100644 --- a/app/src/types.ts +++ b/app/src/types.ts @@ -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 { diff --git a/app/tests/servableAssets.test.ts b/app/tests/servableAssets.test.ts new file mode 100644 index 0000000..16e580e --- /dev/null +++ b/app/tests/servableAssets.test.ts @@ -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 { + 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() + }) +}) diff --git a/docs/introduction.md b/docs/introduction.md index 8cacbad..2ee2573 100644 --- a/docs/introduction.md +++ b/docs/introduction.md @@ -28,7 +28,7 @@ what photos or videos are shared in that share URL. If it is a valid share URL, the proxy fetches just those assets via local API and returns them to the visitor as an individual image or gallery. -If the shared link has expired or any of the assets have been put in the Immich trash, it will not return those. +If the shared link has expired, or any of the assets have been put in the Immich trash or the locked folder, it will not return those. All incoming data is validated and sanitised, and anything unexpected is simply dropped with a 404. diff --git a/shared/src/types.ts b/shared/src/types.ts index 3bf0290..fdf6df8 100644 --- a/shared/src/types.ts +++ b/shared/src/types.ts @@ -3,6 +3,16 @@ export enum AssetType { video = 'VIDEO' } +/** Immich's asset visibility states, as the API serialises them. */ +export enum AssetVisibility { + timeline = 'timeline', + archive = 'archive', + /** The video half of a motion photo, never shown on its own */ + hidden = 'hidden', + /** The owner's PIN-protected locked folder */ + locked = 'locked' +} + export enum KeyType { key = 'key', slug = 'slug' @@ -49,6 +59,7 @@ export interface Asset { localDateTime?: string; type: AssetType; isTrashed: boolean; + visibility?: AssetVisibility; exifInfo?: ExifInfo; width?: number; height?: number; diff --git a/shared/tests/session.test.ts b/shared/tests/session.test.ts index 3b658ee..1f66fb3 100644 --- a/shared/tests/session.test.ts +++ b/shared/tests/session.test.ts @@ -4,11 +4,7 @@ import type { Server } from 'http' import type { AddressInfo } from 'net' import { sessionMiddleware, unlockHandler } from '../src/session' -/* - The unlock body is visitor input. Only a share-shaped key with a string - password is stored; anything else is dropped before it reaches the cookie, - so a stray object can never become `req.password` or a session key. -*/ +// The unlock body is visitor input: only a share-shaped key and a string password may reach the cookie describe('unlockHandler', () => { let server: Server diff --git a/upload-app/src/idleTimeoutStream.ts b/upload-app/src/idleTimeoutStream.ts index 39e74cf..5f9fa2a 100644 --- a/upload-app/src/idleTimeoutStream.ts +++ b/upload-app/src/idleTimeoutStream.ts @@ -6,12 +6,9 @@ export class IdleTimeoutError extends Error {} /** * A pass-through Transform that destroys itself when fewer than `minBytes` * flow through it in any `idleMs` interval. The check is armed when the - * transform is created, so a body that never starts also times out. - * - * With `minBytes` left at 1 this is a plain idle timeout: a slow-but-steady - * stream keeps going, a stalled one fails. A higher `minBytes` is a floor on - * throughput, which stops a trickle of one byte a minute holding the - * resources an upload reserved for as long as the sender likes. + * transform is created, so a body that never starts also times out. With + * `minBytes` left at 1 this is a plain idle timeout; a higher value is a + * floor on throughput. */ export function createIdleTimeoutStream (idleMs: number, minBytes = 1): Transform { let received = 0