From 6ae80569ffe7bcbdd3ef72ab2b5f285b84858d4d Mon Sep 17 00:00:00 2001 From: Alan Grainger <16197738+alangrainger@users.noreply.github.com> Date: Tue, 20 Oct 2026 09:39:37 +1300 Subject: [PATCH] Add nostore to upload healthcheck and fix double-sort --- app/src/gallery/filename.ts | 27 ++++++++++++++++++----- app/src/gallery/order.ts | 32 ++++++++++++++------------- app/src/stream/asset.ts | 8 +++---- app/src/stream/download.ts | 10 ++++----- app/tests/assetStream.test.ts | 38 ++++++++++++++++++++++---------- app/tests/dateSort.test.ts | 12 +++++++--- shared/src/http.ts | 4 +++- shared/tests/healthcheck.test.ts | 12 +++++++++- upload-app/src/index.ts | 5 +---- upload-app/src/tag-uploads.ts | 35 +++++++++++++++-------------- 10 files changed, 115 insertions(+), 68 deletions(-) diff --git a/app/src/gallery/filename.ts b/app/src/gallery/filename.ts index 0cab39d..1e1e44b 100644 --- a/app/src/gallery/filename.ts +++ b/app/src/gallery/filename.ts @@ -5,7 +5,7 @@ import { resolveImageEndpoint } from './sizing' /** * Where an asset sits in its share, for the position-based download names of - * `downloadedFilename: 2`. Built with `positionInShare` / `findPositionInShare`. + * `downloadedFilename: 2`. Built with `positionInShare`, `sharePositions` or `findPositionInShare`. */ export interface AssetPosition { /** The share's key. Only its hash reaches a filename, never the key itself. */ @@ -25,13 +25,28 @@ export function positionInShare (share: SharedLink, index: number): AssetPositio } /** - * Look up an asset's position in its share by id. A motion photo's clip takes - * the position of the still it belongs to. Undefined when the id is not in - * the share, which `getFilename` treats as "no position". + * Every asset's position in its share, by id, for a caller that looks up many. + * A motion photo's clip takes the position of the still it belongs to. The + * first asset to claim an id keeps it. + */ +export function sharePositions (share: SharedLink): Map { + const positions = new Map() + share.assets.forEach((asset, index) => { + const position = positionInShare(share, index) + for (const id of [asset.id, asset.livePhotoVideoId]) { + if (id && !positions.has(id)) positions.set(id, position) + } + }) + return positions +} + +/** + * Look up one asset's position in its share by id, as `sharePositions` does. + * Undefined when the id is not in the share, which `getFilename` treats as + * "no position". */ export function findPositionInShare (share: SharedLink, assetId: string): AssetPosition | undefined { - const index = share.assets.findIndex(a => a.id === assetId || a.livePhotoVideoId === assetId) - return index === -1 ? undefined : positionInShare(share, index) + return sharePositions(share).get(assetId) } /** `ipp.downloadedFilename` when the operator's config omits it: share hash plus position */ diff --git a/app/src/gallery/order.ts b/app/src/gallery/order.ts index 4d63437..e6dd91f 100644 --- a/app/src/gallery/order.ts +++ b/app/src/gallery/order.ts @@ -6,36 +6,38 @@ import type { GroupByDateMode } from '../shared/types' * when the share is loaded, so the gallery, the zip download and the single * download all see the same order and an asset's position is its index. * - * An album with a sort order is sorted by capture time in that direction. - * Date grouping then sorts by the local timestamp the client buckets on, so - * buckets stay contiguous (`dateSortComparator`). + * With date grouping on, sorts by the local timestamp the client buckets on, + * so buckets stay contiguous. Otherwise an album with a sort order is sorted + * by capture time in that direction, and anything else keeps Immich's order. * * Sorts in place and returns the same array. */ export function displayOrder (assets: Asset[], albumOrder?: string): Asset[] { - if (albumOrder === 'asc') { - assets.sort((a, b) => a?.fileCreatedAt?.localeCompare(b.fileCreatedAt || '') || 0) - } else if (albumOrder === 'desc') { - assets.sort((a, b) => b?.fileCreatedAt?.localeCompare(a.fileCreatedAt || '') || 0) - } if (groupByDateMode()) { assets.sort(dateSortComparator(albumOrder)) + } else if (albumOrder === 'asc' || albumOrder === 'desc') { + assets.sort(dateSortComparator(albumOrder, captureTime)) } return assets } +/** The local timestamp the client's date groups bucket on */ +const localTime = (a: Asset) => a.localDateTime || a.fileCreatedAt || '' + +/** The capture timestamp in UTC, which Immich sorts an album by */ +const captureTime = (a: Asset) => a.fileCreatedAt || '' + /** - * Comparator for the date-grouping sort: ascending when the album's order is - * `'asc'`, otherwise newest-first (individual shares and orderless albums). + * Comparator on the timestamp `key` returns: ascending when the album's order + * is `'asc'`, otherwise newest-first (individual shares and orderless albums). * Undated assets always sort last regardless of direction, so the client's - * "Undated" group renders at the bottom. + * "Undated" group renders at the bottom and the order is consistent. */ -export function dateSortComparator (order?: string): (a: Asset, b: Asset) => number { +export function dateSortComparator (order?: string, key: (a: Asset) => string = localTime): (a: Asset, b: Asset) => number { const ascending = order === 'asc' - const sortKey = (a: Asset) => a.localDateTime || a.fileCreatedAt || '' return (a, b) => { - const ka = sortKey(a) - const kb = sortKey(b) + const ka = key(a) + const kb = key(b) if (!ka || !kb) return ka ? -1 : kb ? 1 : 0 // undated always last return ascending ? ka.localeCompare(kb) : kb.localeCompare(ka) } diff --git a/app/src/stream/asset.ts b/app/src/stream/asset.ts index 84ce3b6..6defa8e 100644 --- a/app/src/stream/asset.ts +++ b/app/src/stream/asset.ts @@ -19,7 +19,7 @@ import { pipeline } from 'stream/promises' * or locked assets are handled implicitly: Immich's own endpoints refuse * to serve them, and the upstream failure surfaces as a client 404. */ -export async function assetBuffer (req: IncomingShareRequest, res: Response, asset: Asset, size?: ImageSize | string, share?: SharedLink, forceVideoPlayback = false) { +export async function assetBuffer (req: IncomingShareRequest, res: Response, asset: Asset, size: ImageSize | string | undefined, share: SharedLink, forceVideoPlayback = false) { // A cancelled download must not leave Immich streaming #288 const upstream = abortOnClose(res) @@ -31,7 +31,7 @@ export async function assetBuffer (req: IncomingShareRequest, res: Response, ass let servedSize: ImageSize | undefined const requested = validateImageSize(size) - const useVideoPlayback = forceVideoPlayback || (isVideoAsset(asset) && requested === ImageSize.original && share?.allowDownload === false) + const useVideoPlayback = forceVideoPlayback || (isVideoAsset(asset) && requested === ImageSize.original && share.allowDownload === false) if (useVideoPlayback) { subpath = '/video/playback' @@ -60,7 +60,7 @@ export async function assetBuffer (req: IncomingShareRequest, res: Response, ass if (detail?.originalMimeType) asset = { ...asset, originalMimeType: detail.originalMimeType } } const endpoint = requested === ImageSize.original - ? resolveDownloadEndpoint(asset, share?.allowDownload !== false) + ? resolveDownloadEndpoint(asset, share.allowDownload !== false) : resolveImageEndpoint(requested, asset) subpath = endpoint.subpath sizeQueryParam = endpoint.sizeQueryParam @@ -95,7 +95,7 @@ export async function assetBuffer (req: IncomingShareRequest, res: Response, ass // Always an attachment, so an SVG can't render inline. Album assets have // no originalFileName; Immich's own Content-Disposition carries it. const named = asset.originalFileName ? asset : enrichFromHeaders(asset, data) - const position = share && findPositionInShare(share, asset.id) + const position = findPositionInShare(share, asset.id) res.setHeader('Content-Disposition', attachmentDisposition(getFilename(named, servedSize, servedMimeFrom(subpath, data), position))) } headerList.forEach(header => { diff --git a/app/src/stream/download.ts b/app/src/stream/download.ts index 100ffe0..a536c1e 100644 --- a/app/src/stream/download.ts +++ b/app/src/stream/download.ts @@ -3,7 +3,7 @@ import { assetFetchUrl, authHeadersForAsset } from '../immich' import { Response } from 'express-serve-static-core' import archiver, { Archiver } from 'archiver' import { resolveDownloadEndpoint, ImageEndpoint } from '../gallery/sizing' -import { AssetPosition, attachmentDisposition, enrichFromHeaders, findPositionInShare, getFilename, servedMimeFrom } from '../gallery/filename' +import { AssetPosition, attachmentDisposition, enrichFromHeaders, getFilename, servedMimeFrom, sharePositions } from '../gallery/filename' /** Attempts to get response headers from Immich for one asset before giving up. */ const MAX_ATTEMPTS = 3 @@ -77,10 +77,12 @@ export async function downloadAssets (res: Response, share: SharedLink, assets: // Headers and piping are deferred until the first asset has arrived, so a // failure before then can still be answered with a normal error response. let piped = false + // A multi-select download keeps each asset's position in the whole share + const positions = sharePositions(share) for (const asset of assets) { if (controller.signal.aborted) break - const fetched = await fetchOne(share, asset, controller.signal) + const fetched = await fetchOne(share, asset, positions.get(asset.id), controller.signal) if (fetched === null) break // aborted while waiting on Immich if ('failure' in fetched) { if (!piped) { @@ -196,7 +198,7 @@ function teardownArchive (archive: Archiver, res: Response) { * Returns the fetched asset on success, a wrapped Failure on error, or null * if the download was aborted before we got an answer. */ -async function fetchOne (share: SharedLink, asset: Asset, signal: AbortSignal): Promise { +async function fetchOne (share: SharedLink, asset: Asset, position: AssetPosition | undefined, signal: AbortSignal): Promise { if (signal.aborted) return null const endpoint = resolveDownloadEndpoint(asset, share.allowDownload !== false) @@ -213,8 +215,6 @@ async function fetchOne (share: SharedLink, asset: Asset, signal: AbortSignal): // so recover them from the headers we already fetched - no extra calls. const namedAsset = asset.originalFileName ? asset : enrichFromHeaders(asset, fetched.response) - // A multi-select download keeps each asset's position in the whole share - const position = findPositionInShare(share, asset.id) return { response: fetched.response, asset: namedAsset, endpoint, servedMime: servedMimeFrom(endpoint.subpath, fetched.response), url, position } } diff --git a/app/tests/assetStream.test.ts b/app/tests/assetStream.test.ts index ed0ea28..0fadeeb 100644 --- a/app/tests/assetStream.test.ts +++ b/app/tests/assetStream.test.ts @@ -1,5 +1,5 @@ import { describe, it, expect, vi, afterEach } from 'vitest' -import { Asset, AssetType, KeyType, loadConfig } from '@ipp/core' +import { Asset, AssetType, KeyType, loadConfig, SharedLink } from '@ipp/core' import { Writable } from 'stream' import type { Request, Response } from 'express-serve-static-core' import { assetBuffer } from '../src/stream/asset' @@ -28,6 +28,11 @@ const asset: Asset = { originalMimeType: 'image/jpeg' } +/** A share holding just `item`, which every streamed asset belongs to. */ +function shareOf (item: Asset): SharedLink { + return { key: 'testkey', keyType: KeyType.key, type: 'INDIVIDUAL', assets: [item] } +} + function makeRequest (method = 'GET'): IncomingShareRequest { return { req: { method } as Request, key: 'testkey', range: '' } } @@ -117,10 +122,11 @@ function newSource (): Source { describe('assetBuffer streaming', () => { it('delivers the whole body and forwards upstream headers', async () => { + setConfig({ ipp: { downloadedFilename: 0 } }) const source = newSource() vi.stubGlobal('fetch', pullFetch(4 * CHUNK, source)) const res = new FakeRes() - await assetBuffer(makeRequest(), asResponse(res), asset, ImageSize.original) + await assetBuffer(makeRequest(), asResponse(res), asset, ImageSize.original, shareOf(asset)) expect(res.received).toBe(4 * CHUNK) expect(res.writableFinished).toBe(true) expect(res.headers['content-type']).toBe('image/jpeg') @@ -129,6 +135,13 @@ describe('assetBuffer streaming', () => { expect(res.headers['x-accel-buffering']).toBe('no') }) + it('names a download by its position in the share by default', async () => { + vi.stubGlobal('fetch', pullFetch(CHUNK, newSource())) + const res = new FakeRes() + await assetBuffer(makeRequest(), asResponse(res), asset, ImageSize.original, shareOf(asset)) + expect(res.headers['content-disposition']).toMatch(/''[0-9a-f]{8}_001\.jpg$/) + }) + it('applies backpressure so upstream is read no faster than the visitor drains it', async () => { // Issue #288: a fast NAS read against a slow visitor used to buffer the // whole file in memory. Track how far ahead of the sink the source gets. @@ -142,7 +155,7 @@ describe('assetBuffer streaming', () => { maxOutstanding = Math.max(maxOutstanding, source.pulled - res.received) origWrite(chunk, enc, cb) } - await assetBuffer(makeRequest(), asResponse(res), asset, ImageSize.original) + await assetBuffer(makeRequest(), asResponse(res), asset, ImageSize.original, shareOf(asset)) expect(res.received).toBe(total) expect(maxOutstanding).toBeLessThan(1024 * 1024) }, 20_000) @@ -160,7 +173,7 @@ describe('assetBuffer streaming', () => { setImmediate(() => res.destroy(new Error('client aborted'))) } } - await assetBuffer(makeRequest(), asResponse(res), asset, ImageSize.original) + await assetBuffer(makeRequest(), asResponse(res), asset, ImageSize.original, shareOf(asset)) expect(source.cancelled || source.signals[0].aborted).toBe(true) // Upstream must stop shortly after the disconnect, not run to infinity expect(source.pulled).toBeLessThan(1024 * 1024) @@ -171,7 +184,7 @@ describe('assetBuffer streaming', () => { vi.stubGlobal('fetch', pullFetch(Infinity, source, 200)) const res = new FakeRes() setTimeout(() => res.destroy(new Error('client aborted')), 20) - await expect(assetBuffer(makeRequest(), asResponse(res), asset, ImageSize.original)).resolves.toBeUndefined() + await expect(assetBuffer(makeRequest(), asResponse(res), asset, ImageSize.original, shareOf(asset))).resolves.toBeUndefined() expect(source.signals[0].aborted).toBe(true) expect(source.pulled).toBe(0) expect(res.received).toBe(0) @@ -182,7 +195,7 @@ describe('assetBuffer streaming', () => { vi.stubGlobal('fetch', pullFetch(Infinity, source, 50)) const res = new FakeRes() res.destroy() - await assetBuffer(makeRequest(), asResponse(res), asset, ImageSize.original) + await assetBuffer(makeRequest(), asResponse(res), asset, ImageSize.original, shareOf(asset)) expect(source.signals[0].aborted).toBe(true) expect(source.pulled).toBe(0) }) @@ -191,7 +204,7 @@ describe('assetBuffer streaming', () => { const source = newSource() vi.stubGlobal('fetch', pullFetch(4 * CHUNK, source)) const res = new FakeRes() - await assetBuffer(makeRequest('HEAD'), asResponse(res), asset, ImageSize.original) + await assetBuffer(makeRequest('HEAD'), asResponse(res), asset, ImageSize.original, shareOf(asset)) expect(res.writableEnded).toBe(true) expect(res.received).toBe(0) expect(source.cancelled).toBe(true) @@ -199,7 +212,7 @@ describe('assetBuffer streaming', () => { }) it('names a WebP preview download .webp', async () => { - setConfig({ ipp: { maxDownloadQuality: 'preview' } }) + setConfig({ ipp: { maxDownloadQuality: 'preview', downloadedFilename: 0 } }) vi.stubGlobal('fetch', vi.fn(async () => new globalThis.Response( new ReadableStream({ start (controller) { controller.enqueue(new Uint8Array(1024)); controller.close() } @@ -207,7 +220,7 @@ describe('assetBuffer streaming', () => { { status: 200, headers: { 'content-type': 'image/webp', 'content-length': '1024' } } ))) const res = new FakeRes() - await assetBuffer(makeRequest(), asResponse(res), asset, ImageSize.original) + await assetBuffer(makeRequest(), asResponse(res), asset, ImageSize.original, shareOf(asset)) expect(res.headers['content-disposition']).toContain('a1.webp') expect(res.headers['content-type']).toBe('image/webp') }) @@ -227,15 +240,16 @@ describe('assetBuffer streaming', () => { setConfig({ ipp: { downloadedFilename: 0 } }) vi.stubGlobal('fetch', svgFetch({ 'content-disposition': 'attachment; filename="drawing.svg"' })) const res = new FakeRes() - await assetBuffer(makeRequest(), asResponse(res), albumAsset, ImageSize.original) + await assetBuffer(makeRequest(), asResponse(res), albumAsset, ImageSize.original, shareOf(albumAsset)) expect(res.headers['content-disposition']).toBe("attachment; filename*=UTF-8''drawing.svg") expect(res.headers['x-content-type-options']).toBe('nosniff') }) it('falls back to the asset id when Immich sends no filename', async () => { + setConfig({ ipp: { downloadedFilename: 0 } }) vi.stubGlobal('fetch', svgFetch({})) const res = new FakeRes() - await assetBuffer(makeRequest(), asResponse(res), albumAsset, ImageSize.original) + await assetBuffer(makeRequest(), asResponse(res), albumAsset, ImageSize.original, shareOf(albumAsset)) expect(res.headers['content-disposition']).toBe("attachment; filename*=UTF-8''a2.svg") }) }) @@ -243,7 +257,7 @@ describe('assetBuffer streaming', () => { it('serves display sizes inline, still with nosniff', async () => { vi.stubGlobal('fetch', pullFetch(CHUNK, newSource())) const res = new FakeRes() - await assetBuffer(makeRequest(), asResponse(res), asset, ImageSize.preview) + await assetBuffer(makeRequest(), asResponse(res), asset, ImageSize.preview, shareOf(asset)) expect(res.headers['content-disposition']).toBeUndefined() expect(res.headers['x-content-type-options']).toBe('nosniff') }) diff --git a/app/tests/dateSort.test.ts b/app/tests/dateSort.test.ts index a937668..ae37672 100644 --- a/app/tests/dateSort.test.ts +++ b/app/tests/dateSort.test.ts @@ -3,9 +3,9 @@ import { Asset, AssetType, KeyType, loadConfig } from '@ipp/core' import { dateSortComparator, displayOrder } from '../src/gallery/order' /* - The date-grouping sort must follow the album's own order while - keeping undated assets last in BOTH directions. displayOrder applies it, - after the album's own sort, when `gallery.groupByDate` is on. + The date sort must follow the album's own order while keeping undated + assets last in BOTH directions. displayOrder sorts once: by local time when + `gallery.groupByDate` is on, else by capture time in the album's order. */ afterEach(() => { @@ -84,6 +84,12 @@ describe('displayOrder', () => { expect(ids(displayOrder(album(), 'desc'))).toEqual(['b', 'a', 'c']) }) + it('puts undated assets last in an album sort', () => { + const withUndated = () => [dated('a', '2024-02-01T10:00:00.000Z'), { ...asset(), id: 'u' }, dated('c', '2024-01-01T10:00:00.000Z')] + expect(ids(displayOrder(withUndated(), 'asc'))).toEqual(['c', 'a', 'u']) + expect(ids(displayOrder(withUndated(), 'desc'))).toEqual(['a', 'c', 'u']) + }) + it('sorts by local time when date grouping is on, so buckets stay contiguous', () => { process.env.CONFIG = JSON.stringify({ ipp: { gallery: { groupByDate: 'day' } } }) loadConfig() diff --git a/shared/src/http.ts b/shared/src/http.ts index 556825c..b789404 100644 --- a/shared/src/http.ts +++ b/shared/src/http.ts @@ -38,10 +38,12 @@ export function abortOnClose (res: Response): AbortSignal { } /** - * A `GET /healthcheck` handler: `body` while Immich answers, else 503. + * A `GET /healthcheck` handler: `body` while Immich answers, else 503. Never + * cached, so a browser or CDN can't answer for a service that has gone. */ export function healthcheckHandler (body: string) { return async (_req: Request, res: Response): Promise => { + addNoStoreHeaders(res) if (await accessible()) { res.send(body) } else { diff --git a/shared/tests/healthcheck.test.ts b/shared/tests/healthcheck.test.ts index 155645f..1c6f79b 100644 --- a/shared/tests/healthcheck.test.ts +++ b/shared/tests/healthcheck.test.ts @@ -10,8 +10,9 @@ import * as client from '../src/immich/client' */ function response () { - const res = { body: undefined as string | undefined, code: 200 } + const res = { body: undefined as string | undefined, code: 200, headers: {} as Record } return Object.assign(res, { + set (name: string, value: string) { res.headers[name] = value; return res }, send (body?: string) { res.body = body; return res }, status (code: number) { res.code = code; return res } }) @@ -36,6 +37,15 @@ describe('healthcheckHandler', () => { expect(res.body).toBeUndefined() }) + it('is never cached, up or down', async () => { + for (const up of [true, false]) { + vi.spyOn(client, 'accessible').mockResolvedValue(up) + const res = response() + await healthcheckHandler('upload-ok')({} as never, res as never) + expect(res.headers['Cache-Control']).toContain('no-store') + } + }) + it("is IPP's own healthcheck with `ok`", async () => { vi.spyOn(client, 'accessible').mockResolvedValue(true) const res = response() diff --git a/upload-app/src/index.ts b/upload-app/src/index.ts index a5a1dc8..9fed8d5 100644 --- a/upload-app/src/index.ts +++ b/upload-app/src/index.ts @@ -79,10 +79,7 @@ function bodyDeadline (ms: number): RequestHandler { IPP answers `ok`, so the owner can tell which service a route reached. */ const healthcheck = healthcheckHandler('upload-ok') -app.get(['/healthcheck', '/share/healthcheck'], (_req, res, next) => { - addNoStoreHeaders(res) - next() -}, asyncHandler(healthcheck)) +app.get(['/healthcheck', '/share/healthcheck'], asyncHandler(healthcheck)) const router = Router() diff --git a/upload-app/src/tag-uploads.ts b/upload-app/src/tag-uploads.ts index 22a7cf2..b10ed3d 100644 --- a/upload-app/src/tag-uploads.ts +++ b/upload-app/src/tag-uploads.ts @@ -49,18 +49,8 @@ export interface TagOptions { print: (line: string) => void } -/** What `tagUploads` found and did. */ -export interface TagSummary { - /** Asset IDs per visitor name. */ - named: Map - anonymous: number - unreadable: number - /** Assets that got a tag they did not have. Always 0 in a dry run. */ - tagged: number -} - /** The fields of an Immich `AssetResponseDto` that the script reads. */ -interface Asset { +export interface Asset { id: string ownerId: string originalFileName: string @@ -68,6 +58,16 @@ interface Asset { isTrashed: boolean } +/** What `tagUploads` found and did. */ +export interface TagSummary { + /** Uploads per visitor name. */ + named: Map + anonymous: number + unreadable: number + /** Assets that got a tag they did not have. Always 0 in a dry run. */ + tagged: number +} + /** A failed Immich call, with a message fit for the owner. */ export class ImmichError extends Error {} @@ -136,7 +136,6 @@ function files (count: number): string { export async function tagUploads (options: TagOptions): Promise { const { apiKey, apply, parent, prefix, separator, print } = options const summary: TagSummary = { named: new Map(), anonymous: 0, unreadable: 0, tagged: 0 } - const fileNames = new Map() const uploads = await findUploads(apiKey, prefix) print('Found ' + files(uploads.length) + ' starting with "' + prefix + '".') @@ -148,8 +147,9 @@ export async function tagUploads (options: TagOptions): Promise { summary.unreadable++ print('Skipped ' + asset.originalFileName + ': ' + stored.reason + '.') } else { - summary.named.set(stored.uploader, [...(summary.named.get(stored.uploader) || []), asset.id]) - fileNames.set(stored.uploader, [...(fileNames.get(stored.uploader) || []), asset.originalFileName]) + const named = summary.named.get(stored.uploader) + if (named) named.push(asset) + else summary.named.set(stored.uploader, [asset]) } } @@ -164,13 +164,14 @@ export async function tagUploads (options: TagOptions): Promise { print('') for (const name of names) { - const ids = summary.named.get(name) || [] + const sent = summary.named.get(name) || [] const tag = parent + '/' + name if (!apply) { - print(tag + ': ' + files(ids.length)) - for (const fileName of (fileNames.get(name) || []).sort()) print(' ' + fileName) + print(tag + ': ' + files(sent.length)) + for (const fileName of sent.map(asset => asset.originalFileName).sort()) print(' ' + fileName) continue } + const ids = sent.map(asset => asset.id) const tagId = tagIds.get(tag) if (!tagId) throw new ImmichError('Immich did not return the tag ' + tag) let added = 0