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
@@ -1,7 +1,8 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
|
/* eslint-disable @next/next/no-img-element */
|
||||||
|
|
||||||
import { useState, useTransition } from "react";
|
import { useState, useTransition } from "react";
|
||||||
import Image from "next/image";
|
|
||||||
|
|
||||||
import type { AlbumActionResult } from "./actions";
|
import type { AlbumActionResult } from "./actions";
|
||||||
|
|
||||||
@@ -52,12 +53,11 @@ function AlbumCard({ album, editorialId, grantAction, revokeAction, notifyAction
|
|||||||
<li className={`flex flex-col bg-white border ${album.isGranted ? 'border-green-500 shadow-md ring-1 ring-green-500' : 'border-gray-200'} rounded-xl overflow-hidden transition-all duration-300 hover:shadow-lg`} data-granted={album.isGranted}>
|
<li className={`flex flex-col bg-white border ${album.isGranted ? 'border-green-500 shadow-md ring-1 ring-green-500' : 'border-gray-200'} rounded-xl overflow-hidden transition-all duration-300 hover:shadow-lg`} data-granted={album.isGranted}>
|
||||||
<div className="relative aspect-[3/2] bg-gray-100 overflow-hidden">
|
<div className="relative aspect-[3/2] bg-gray-100 overflow-hidden">
|
||||||
{album.albumThumbnailAssetId ? (
|
{album.albumThumbnailAssetId ? (
|
||||||
<Image
|
<img
|
||||||
className="w-full h-full object-contain transition-transform duration-500 hover:scale-105"
|
className="w-full h-full object-contain transition-transform duration-500 hover:scale-105"
|
||||||
alt={`Titelbild von ${album.albumName}`}
|
alt={`Titelbild von ${album.albumName}`}
|
||||||
height={200}
|
loading="lazy"
|
||||||
src={`/api/assets/${encodeURIComponent(album.albumThumbnailAssetId)}/thumbnail?albumId=${encodeURIComponent(album.id)}`}
|
src={`/api/assets/${encodeURIComponent(album.albumThumbnailAssetId)}/thumbnail?albumId=${encodeURIComponent(album.id)}`}
|
||||||
width={300}
|
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div aria-label="Kein Albumcover verfügbar" className="w-full h-full flex items-center justify-center text-gray-400 text-xs uppercase tracking-widest" role="img">
|
<div aria-label="Kein Albumcover verfügbar" className="w-full h-full flex items-center justify-center text-gray-400 text-xs uppercase tracking-widest" role="img">
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ export default async function AlbumPage({ params, searchParams }: AlbumPageProps
|
|||||||
Alle Alben
|
Alle Alben
|
||||||
</Link>
|
</Link>
|
||||||
</PageHeader>
|
</PageHeader>
|
||||||
<AlbumSearchForm albumId={result.album.id} query={query} format={format} jahr={jahr} />
|
<AlbumSearchForm albumId={result.album.id} query={query} format={format} />
|
||||||
<p aria-live="polite" className="result-summary" role="status">
|
<p aria-live="polite" className="result-summary" role="status">
|
||||||
{formatCount(result.page.total, "Foto")} gefunden
|
{formatCount(result.page.total, "Foto")} gefunden
|
||||||
</p>
|
</p>
|
||||||
@@ -81,10 +81,7 @@ export default async function AlbumPage({ params, searchParams }: AlbumPageProps
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function AlbumSearchForm({ albumId, query, format, jahr }: { albumId: string; query: string; format?: string; jahr?: string; }) {
|
function AlbumSearchForm({ albumId, query, format }: { albumId: string; query: string; format?: string; }) {
|
||||||
const currentYear = new Date().getFullYear();
|
|
||||||
const years = Array.from({ length: 10 }, (_, i) => currentYear - i);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form
|
<form
|
||||||
action={`/redaktion/alben/${albumId}`}
|
action={`/redaktion/alben/${albumId}`}
|
||||||
@@ -112,15 +109,6 @@ function AlbumSearchForm({ albumId, query, format, jahr }: { albumId: string; qu
|
|||||||
<option value="hoch">Hochformat</option>
|
<option value="hoch">Hochformat</option>
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<label className="album-search-select">
|
|
||||||
<span>Jahr</span>
|
|
||||||
<select name="jahr" defaultValue={jahr || ""}>
|
|
||||||
<option value="">Alle Jahre</option>
|
|
||||||
{years.map((y) => (
|
|
||||||
<option key={y} value={y.toString()}>{y}</option>
|
|
||||||
))}
|
|
||||||
</select>
|
|
||||||
</label>
|
|
||||||
<button type="submit">Suchen</button>
|
<button type="submit">Suchen</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
|
/* eslint-disable @next/next/no-img-element */
|
||||||
|
|
||||||
import { headers } from "next/headers";
|
import { headers } from "next/headers";
|
||||||
import { PageHeader } from "@/components/ui/page-header";
|
import { PageHeader } from "@/components/ui/page-header";
|
||||||
import { requireActiveEditorial } from "@/modules/auth/principal";
|
import { requireActiveEditorial } from "@/modules/auth/principal";
|
||||||
import { lightboxService } from "@/modules/lightbox/service";
|
import { lightboxService } from "@/modules/lightbox/service";
|
||||||
import { immichClient } from "@/modules/immich/client";
|
import { immichClient } from "@/modules/immich/client";
|
||||||
import Image from "next/image";
|
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { RemoveLightboxItemButton } from "./RemoveLightboxItemButton";
|
import { RemoveLightboxItemButton } from "./RemoveLightboxItemButton";
|
||||||
import { DownloadLightboxForm } from "./DownloadLightboxForm";
|
import { DownloadLightboxForm } from "./DownloadLightboxForm";
|
||||||
@@ -51,12 +52,11 @@ export default async function LightboxPage() {
|
|||||||
<li key={item.assetId} className="relative group rounded-xl overflow-hidden border border-border bg-card shadow-sm transition-all hover:shadow-md hover:-translate-y-1">
|
<li key={item.assetId} className="relative group rounded-xl overflow-hidden border border-border bg-card shadow-sm transition-all hover:shadow-md hover:-translate-y-1">
|
||||||
<Link href={href} className="block">
|
<Link href={href} className="block">
|
||||||
<div className="aspect-[3/2] w-full overflow-hidden bg-muted">
|
<div className="aspect-[3/2] w-full overflow-hidden bg-muted">
|
||||||
<Image
|
<img
|
||||||
alt={asset.originalFileName ?? "Bild"}
|
alt={asset.originalFileName ?? "Bild"}
|
||||||
className="w-full h-full object-contain transition-transform duration-300 group-hover:scale-105"
|
className="w-full h-full object-contain transition-transform duration-300 group-hover:scale-105"
|
||||||
height={200}
|
loading="lazy"
|
||||||
src={`/api/assets/${encodeURIComponent(item.assetId)}/thumbnail`}
|
src={`/api/assets/${encodeURIComponent(item.assetId)}/thumbnail`}
|
||||||
width={300}
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="p-3 border-t border-border bg-card">
|
<div className="p-3 border-t border-border bg-card">
|
||||||
|
|||||||
@@ -46,29 +46,70 @@ export function createAlbumCatalog({ grants, immich }: AlbumCatalogDependencies)
|
|||||||
input: SearchVisiblePhotosInput,
|
input: SearchVisiblePhotosInput,
|
||||||
): Promise<ImmichSearchPage> {
|
): Promise<ImmichSearchPage> {
|
||||||
const grantedAlbumIds = await currentGrantIds(grants, editorialId);
|
const grantedAlbumIds = await currentGrantIds(grants, editorialId);
|
||||||
const albumIds = input.requestedAlbumId
|
if (grantedAlbumIds.length === 0) {
|
||||||
? authorizedSearchAlbums(grantedAlbumIds, input.requestedAlbumId)
|
|
||||||
: grantedAlbumIds;
|
|
||||||
if (albumIds.length === 0) {
|
|
||||||
return emptySearchPage();
|
return emptySearchPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
const description = normalizeDescription(input.description);
|
const description = normalizeDescription(input.description);
|
||||||
try {
|
const page = normalizePage(input.page);
|
||||||
return await immich.searchPhotos({
|
const size = input.size ?? PHOTO_PAGE_SIZE;
|
||||||
albumIds,
|
|
||||||
...(description === undefined ? {} : { description }),
|
if (input.requestedAlbumId) {
|
||||||
type: "IMAGE",
|
const albumIds = authorizedSearchAlbums(grantedAlbumIds, input.requestedAlbumId);
|
||||||
page: normalizePage(input.page),
|
if (albumIds.length === 0) {
|
||||||
size: input.size ?? PHOTO_PAGE_SIZE,
|
return emptySearchPage();
|
||||||
});
|
}
|
||||||
} catch {
|
return searchAlbum(immich, albumIds, description, page, size);
|
||||||
throw new AlbumCatalogError("IMMICH_UNAVAILABLE");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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 {
|
function emptySearchPage(): ImmichSearchPage {
|
||||||
return { items: [], total: 0, nextPage: null, previousPage: null };
|
return { items: [], total: 0, nextPage: null, previousPage: null };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,9 +47,11 @@ const albumSummarySchema = z
|
|||||||
.passthrough();
|
.passthrough();
|
||||||
|
|
||||||
const albumSchema = albumSummarySchema.extend({
|
const albumSchema = albumSummarySchema.extend({
|
||||||
// `getAlbum` requests `?withoutAssets=true` so Immich returns album metadata
|
// `getAlbum` returns the full asset list. Two consumers need it: usages
|
||||||
// without the full asset list — otherwise large albums blow past the request
|
// membership (loadRequestedAlbum checks album.assets.some(id)) and bulk
|
||||||
// timeout and surface as IMMICH_UNAVAILABLE. No consumer reads `.assets`.
|
// 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([]),
|
assets: z.array(assetSchema).optional().default([]),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -343,7 +345,7 @@ export function createImmichClient({
|
|||||||
},
|
},
|
||||||
getAlbum(albumId, signal) {
|
getAlbum(albumId, signal) {
|
||||||
return requestJson<ImmichAlbum>(
|
return requestJson<ImmichAlbum>(
|
||||||
`/albums/${encodeURIComponent(albumId)}?withoutAssets=true`,
|
`/albums/${encodeURIComponent(albumId)}`,
|
||||||
{ method: "GET" },
|
{ method: "GET" },
|
||||||
albumSchema,
|
albumSchema,
|
||||||
signal,
|
signal,
|
||||||
|
|||||||
Reference in new issue
Block a user