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

+6
View File
@@ -46,6 +46,12 @@ function createServices() {
const immich = {
getAlbum: vi.fn().mockResolvedValue({ id: albumId, albumName: "Presse 2026" }),
getAsset: vi.fn().mockResolvedValue(asset),
searchPhotos: vi.fn().mockResolvedValue({
items: [{ id: asset.id }],
total: 1,
nextPage: null,
previousPage: null,
}),
};
return {
usageService: createUsageService({