import Link from "next/link"; import { notFound } from "next/navigation"; import { AlbumCatalogError, albumCatalog, PHOTO_PAGE_SIZE } from "@/modules/albums/catalog"; import { formatCount, PhotoPagination } from "@/modules/albums/catalog-content"; import { filterPhotos, paginatePhotos } from "@/modules/albums/filter"; import { PhotoGallery } from "@/modules/albums/photo-gallery"; import { loadEditorialDownloadOptions } from "@/modules/downloads/stream"; import { lightboxService } from "@/modules/lightbox/service"; import { requireEditorial } from "../../access"; import { PageHeader } from "@/components/ui/page-header"; // ponytail: fetch the whole album in one request so hoch/quer and jahr filters // can be applied across the full set before paginating, instead of over a // single 60-item page. Ceiling: albums > 1000 photos lose tail items; raise // here (and the Immich size cap) if a sport album ever exceeds it. const ALBUM_FETCH_SIZE = 1000; type AlbumPageProps = Readonly<{ params: Promise<{ albumId: string }>; searchParams: Promise<{ page?: string | string[]; suche?: string | string[]; format?: string | string[]; jahr?: string | string[] }>; }>; export default async function AlbumPage({ params, searchParams }: AlbumPageProps) { const [{ albumId }, rawSearchParams, principal] = await Promise.all([ params, searchParams, requireEditorial(), ]); const query = normalizedQuery(singleValue(rawSearchParams.suche)); const format = singleValue(rawSearchParams.format); const jahr = singleValue(rawSearchParams.jahr); const result = await loadAlbumPage({ editorialId: principal.editorialId, albumId, query, page: singleValue(rawSearchParams.page), format, jahr, }); if (result.unavailable) { return ; } if (!result.album) { notFound(); } return (
Alle Alben

{formatCount(result.page.total, "Foto")} gefunden

); } function AlbumSearchForm({ albumId, query, format, jahr }: { albumId: string; query: string; format?: string; jahr?: string; }) { const currentYear = new Date().getFullYear(); const years = Array.from({ length: 10 }, (_, i) => currentYear - i); return (
); } async function loadAlbumPage({ editorialId, albumId, query, page, format, jahr, }: { editorialId: string; albumId: string; query: string; page: string | undefined; format?: string; jahr?: string; }) { try { const albums = await albumCatalog.getVisibleAlbums(editorialId); const album = albums.find((candidate) => candidate.id === albumId); if (!album) { return { album: null, page: null, currentPage: 1, downloadOptions: undefined, lightboxAssetIds: new Set(), unavailable: false as const }; } const results = await albumCatalog.searchVisiblePhotos(editorialId, { requestedAlbumId: album.id, description: query, page: 1, size: ALBUM_FETCH_SIZE, }); // Filter format + jahr across the full album set BEFORE paginating, so the // total, the page slice, and the has-more-pages signal all reflect the // active filters. The old code filtered a single 60-item page client-side, // which silently dropped matching photos and reported the unfiltered total. const filtered = filterPhotos(results.items, { format, jahr }); const { result: resultPage, currentPage } = paginatePhotos(filtered, page, PHOTO_PAGE_SIZE); const downloadOptions = await loadEditorialDownloadOptions( editorialId, resultPage.items.map((asset) => asset.id), ); const lightboxItems = await lightboxService.getLightboxItems(editorialId); const lightboxAssetIds = new Set(lightboxItems.map((i) => i.assetId)); return { album, page: resultPage, currentPage, downloadOptions, lightboxAssetIds, unavailable: false as const }; } catch (error) { if (error instanceof AlbumCatalogError && error.code === "IMMICH_UNAVAILABLE") { return { album: null, page: null, currentPage: 1, downloadOptions: undefined, lightboxAssetIds: new Set(), unavailable: true as const }; } throw error; } } function singleValue(value: string | string[] | undefined): string | undefined { return typeof value === "string" ? value : undefined; } function normalizedQuery(value: string | undefined): string { return (value ?? "").replace(/\s+/g, " ").trim().slice(0, 200); } function ImmichUnavailable() { return (

Bitte laden Sie diese Seite in wenigen Minuten erneut.

Zurück zu den Alben
); }