fix: download 404, next/image thumbnail 400, and cross-album search
Three production bugs on redaktionen.leon-tonhaeuser.de: 1. Download 404 (POST /api/download-intents → 404). getAlbum requested ?withoutAssets=true, so album.assets was always empty and the usages membership check (album.assets.some(id)) always failed → ASSET_NOT_IN_ALBUM → 404. Same root cause broke bulk-download's assetToGrantedAlbum map. Removed withoutAssets so consumers that authorize via album.assets get the real list; grants/thumbnail consumers ignore the extra data. 2. _next/image 400 on thumbnail proxy. next/image's optimizer choked on the watermarked streaming thumbnail response. Thumbnails are already server-resized to 800px, so the optimizer added nothing — switched leuchtkasten + admin AlbumGrid to plain <img>, matching photo-gallery. 3. Cross-album search "finds nothing". Immich albumIds is AND across albums (PR #18985): one /search/metadata call with all granted ids requires the asset to be in EVERY album, so single-album photos never match. Album- internal search passed one id so it worked. Fan out per granted album and merge; callers already paginate in-app. Also drop the jahr filter from the album-internal search form (unnecessary within a single album); backend still honors a jahr query param. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
f1ed89ea67
commit
962e2c7dc2
5 files changed
+71
-40
No files matched your search
@@ -46,29 +46,70 @@ export function createAlbumCatalog({ grants, immich }: AlbumCatalogDependencies)
|
||||
input: SearchVisiblePhotosInput,
|
||||
): Promise<ImmichSearchPage> {
|
||||
const grantedAlbumIds = await currentGrantIds(grants, editorialId);
|
||||
const albumIds = input.requestedAlbumId
|
||||
? authorizedSearchAlbums(grantedAlbumIds, input.requestedAlbumId)
|
||||
: grantedAlbumIds;
|
||||
if (albumIds.length === 0) {
|
||||
if (grantedAlbumIds.length === 0) {
|
||||
return emptySearchPage();
|
||||
}
|
||||
|
||||
const description = normalizeDescription(input.description);
|
||||
try {
|
||||
return await immich.searchPhotos({
|
||||
albumIds,
|
||||
...(description === undefined ? {} : { description }),
|
||||
type: "IMAGE",
|
||||
page: normalizePage(input.page),
|
||||
size: input.size ?? PHOTO_PAGE_SIZE,
|
||||
});
|
||||
} catch {
|
||||
throw new AlbumCatalogError("IMMICH_UNAVAILABLE");
|
||||
const page = normalizePage(input.page);
|
||||
const size = input.size ?? PHOTO_PAGE_SIZE;
|
||||
|
||||
if (input.requestedAlbumId) {
|
||||
const albumIds = authorizedSearchAlbums(grantedAlbumIds, input.requestedAlbumId);
|
||||
if (albumIds.length === 0) {
|
||||
return emptySearchPage();
|
||||
}
|
||||
return searchAlbum(immich, albumIds, description, page, size);
|
||||
}
|
||||
|
||||
// Cross-album search. Immich's `albumIds` filter is AND across albums —
|
||||
// an asset must be in EVERY listed album — so one call with all granted
|
||||
// ids returns nothing for assets that live in a single album (the common
|
||||
// case: one photo per game/series album). Fan out per granted album and
|
||||
// merge; callers paginate in-app via paginatePhotos.
|
||||
// ponytail: N upstream calls per global search. Bounded by the editorial's
|
||||
// grant count and narrowed by the description filter, so per-album results
|
||||
// are small. If a huge-grant editorial makes this slow, cap the fan-out
|
||||
// and accept partial coverage.
|
||||
const pages = await Promise.all(
|
||||
grantedAlbumIds.map((albumId) => searchAlbum(immich, [albumId], description, page, size)),
|
||||
);
|
||||
return mergeSearchPages(pages);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function searchAlbum(
|
||||
immich: Pick<ImmichClient, "searchPhotos">,
|
||||
albumIds: string[],
|
||||
description: string | undefined,
|
||||
page: number,
|
||||
size: number,
|
||||
): Promise<ImmichSearchPage> {
|
||||
try {
|
||||
return await immich.searchPhotos({
|
||||
albumIds,
|
||||
...(description === undefined ? {} : { description }),
|
||||
type: "IMAGE",
|
||||
page,
|
||||
size,
|
||||
});
|
||||
} catch {
|
||||
throw new AlbumCatalogError("IMMICH_UNAVAILABLE");
|
||||
}
|
||||
}
|
||||
|
||||
function mergeSearchPages(pages: ImmichSearchPage[]): ImmichSearchPage {
|
||||
// nextPage/previousPage are unused by callers — they paginate in-app via
|
||||
// paginatePhotos, which recomputes both from the merged item count.
|
||||
return {
|
||||
items: pages.flatMap((p) => p.items),
|
||||
total: pages.reduce((sum, p) => sum + p.total, 0),
|
||||
nextPage: null,
|
||||
previousPage: null,
|
||||
};
|
||||
}
|
||||
|
||||
function emptySearchPage(): ImmichSearchPage {
|
||||
return { items: [], total: 0, nextPage: null, previousPage: null };
|
||||
}
|
||||
|
||||
@@ -47,9 +47,11 @@ const albumSummarySchema = z
|
||||
.passthrough();
|
||||
|
||||
const albumSchema = albumSummarySchema.extend({
|
||||
// `getAlbum` requests `?withoutAssets=true` so Immich returns album metadata
|
||||
// without the full asset list — otherwise large albums blow past the request
|
||||
// timeout and surface as IMMICH_UNAVAILABLE. No consumer reads `.assets`.
|
||||
// `getAlbum` returns the full asset list. Two consumers need it: usages
|
||||
// membership (loadRequestedAlbum checks album.assets.some(id)) and bulk
|
||||
// download (builds an assetId→album map by iterating album.assets).
|
||||
// `asset.albums` is unreliable on Immich (empty for older assets), so
|
||||
// album-membership authorization must go through here.
|
||||
assets: z.array(assetSchema).optional().default([]),
|
||||
});
|
||||
|
||||
@@ -343,7 +345,7 @@ export function createImmichClient({
|
||||
},
|
||||
getAlbum(albumId, signal) {
|
||||
return requestJson<ImmichAlbum>(
|
||||
`/albums/${encodeURIComponent(albumId)}?withoutAssets=true`,
|
||||
`/albums/${encodeURIComponent(albumId)}`,
|
||||
{ method: "GET" },
|
||||
albumSchema,
|
||||
signal,
|
||||
|
||||
Reference in new issue
Block a user