Remove locked assets from shares

This commit is contained in:
Alan Grainger
2026-10-07 18:08:12 +13:00
parent 172f247418
commit 285d48e9d0
8 changed files with 69 additions and 19 deletions
+2 -1
View File
@@ -204,7 +204,7 @@ async function fetchShareByKey (key: string, password?: string, keyType: KeyType
log('Shared link ' + key + ' returned no assets array (type ' + link.type + ')') log('Shared link ' + key + ' returned no assets array (type ' + link.type + ')')
link.assets = [] 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) link.assets = servableAssets(link.assets)
// Populate the shared assets with the public key/password // Populate the shared assets with the public key/password
link.assets.forEach(asset => { link.assets.forEach(asset => {
@@ -284,6 +284,7 @@ function timelineBucketToAssets (bucket: TimelineBucketAssets): Asset[] {
localDateTime: localDateTimeFromOffset(fileCreatedAt, bucket.localOffsetHours?.[i]), localDateTime: localDateTimeFromOffset(fileCreatedAt, bucket.localOffsetHours?.[i]),
thumbhash: bucket.thumbhash?.[i] || undefined, thumbhash: bucket.thumbhash?.[i] || undefined,
livePhotoVideoId: bucket.livePhotoVideoId?.[i] || undefined, livePhotoVideoId: bucket.livePhotoVideoId?.[i] || undefined,
visibility: bucket.visibility?.[i],
width, width,
height, height,
needsDetail: true needsDetail: true
+8 -5
View File
@@ -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 { DownloadAll } from './types'
import dayjs from 'dayjs' 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 }) 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 * Narrow a share's assets to what IPP can render: not trashed, not in the
* processing in Immich. `thumbhash` is the readiness signal: Immich's * owner's locked folder, and finished processing in Immich. Immich's share
* thumbnail job writes the files and only then sets it, so until it appears * listing does not filter on visibility, so a locked asset has to go here.
* every image URL IPP hands out would 404. * `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[] { export function servableAssets (assets: Asset[]): Asset[] {
return assets.filter(asset => { return assets.filter(asset => {
if (asset.isTrashed) return false if (asset.isTrashed) return false
if (asset.visibility === AssetVisibility.locked) return false
if (asset.thumbhash) return true if (asset.thumbhash) return true
if (!warnedUnprocessed.get(asset.id)) { if (!warnedUnprocessed.get(asset.id)) {
warnedUnprocessed.set(asset.id, true) warnedUnprocessed.set(asset.id, true)
+2 -1
View File
@@ -1,5 +1,5 @@
import { Request } from 'express-serve-static-core' 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. * One entry of `GET /timeline/buckets` - a time bucket (month) and its count.
@@ -27,6 +27,7 @@ export interface TimelineBucketAssets {
localOffsetHours: number[]; localOffsetHours: number[];
// Motion photo (Live Photo) clip id; null for ordinary assets. // Motion photo (Live Photo) clip id; null for ordinary assets.
livePhotoVideoId: (string | null)[]; livePhotoVideoId: (string | null)[];
visibility: AssetVisibility[];
} }
export enum ImageSize { export enum ImageSize {
+41
View File
@@ -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()
})
})
+1 -1
View File
@@ -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 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. 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. All incoming data is validated and sanitised, and anything unexpected is simply dropped with a 404.
+11
View File
@@ -3,6 +3,16 @@ export enum AssetType {
video = 'VIDEO' 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 { export enum KeyType {
key = 'key', key = 'key',
slug = 'slug' slug = 'slug'
@@ -49,6 +59,7 @@ export interface Asset {
localDateTime?: string; localDateTime?: string;
type: AssetType; type: AssetType;
isTrashed: boolean; isTrashed: boolean;
visibility?: AssetVisibility;
exifInfo?: ExifInfo; exifInfo?: ExifInfo;
width?: number; width?: number;
height?: number; height?: number;
+1 -5
View File
@@ -4,11 +4,7 @@ import type { Server } from 'http'
import type { AddressInfo } from 'net' import type { AddressInfo } from 'net'
import { sessionMiddleware, unlockHandler } from '../src/session' import { sessionMiddleware, unlockHandler } from '../src/session'
/* // The unlock body is visitor input: only a share-shaped key and a string password may reach the cookie
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.
*/
describe('unlockHandler', () => { describe('unlockHandler', () => {
let server: Server let server: Server
+3 -6
View File
@@ -6,12 +6,9 @@ export class IdleTimeoutError extends Error {}
/** /**
* A pass-through Transform that destroys itself when fewer than `minBytes` * A pass-through Transform that destroys itself when fewer than `minBytes`
* flow through it in any `idleMs` interval. The check is armed when the * 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. * 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
* With `minBytes` left at 1 this is a plain idle timeout: a slow-but-steady * floor on throughput.
* 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.
*/ */
export function createIdleTimeoutStream (idleMs: number, minBytes = 1): Transform { export function createIdleTimeoutStream (idleMs: number, minBytes = 1): Transform {
let received = 0 let received = 0