fix: download 404 — Immich getAlbum no longer returns assets

The previous getAlbum fix (removing ?withoutAssets=true) was insufficient:
current Immich's GET /albums/:id NEVER returns assets — AlbumService.get
calls findOrFail with { withAssets: false } and the withoutAssets param is
gone. So album.assets was always empty and every download still failed with
ASSET_NOT_IN_ALBUM → 404. The AI_MEMORY "getAlbum + iterate album.assets"
guidance was stale (written for an older Immich API).

Membership is now verified via /search/metadata with an id + albumIds filter,
which returns the asset only if it belongs to the album. This is the
authoritative test (asset.albums is unreliable for older assets too).

- usages/service.ts: loadRequestedAlbum checks isAssetInAlbum via searchPhotos
  before fetching the album name; getAlbum now only provides albumName.
- bulk-download/route.ts: build the assetId→album map via searchPhotos per
  granted album instead of the empty getAlbum().assets iteration.
- immich client/types: add optional `id` to the searchPhotos input.
- tests: usages mocks now stub searchPhotos; the 13 pre-existing service
  test failures (mock returned getAlbum without assets → TypeError) are
  resolved — 20/20 pass.

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Leon TonhäuserandClaude committed 2026-08-11 14:25:55 +02:00
1 parent 962e2c7dc2
commit 6a31e5f411
7 files changed
+83 -39

No files matched your search

+1
View File
@@ -199,6 +199,7 @@ test("0002 preserves dirty rows and reconstructs only provable legacy intents",
const immich = {
getAlbum: vi.fn(),
getAsset: vi.fn(),
searchPhotos: vi.fn(),
};
const usageService = createUsageService({
repository: createUsageServiceRepository(testDb.database),