import { recordActivity } from "@/modules/activity/service"; import { AlbumCatalogError, albumCatalog, PHOTO_PAGE_SIZE } from "@/modules/albums/catalog"; import { UrlPagination } from "@/components/ui/url-pagination"; import { AlbumContactSheet, formatCount, PhotoSearchForm } from "@/modules/albums/catalog-content"; import { filterPhotos, normalizeSort, paginatePhotos, sortPhotos, type InAppPage, type PhotoSort } from "@/modules/albums/filter"; import { PhotoGallery } from "@/modules/albums/photo-gallery"; import { AnnouncementBanner } from "@/modules/announcements/announcement-banner"; import { announcementService } from "@/modules/announcements/service"; import { loadEditorialDownloadOptions } from "@/modules/downloads/stream"; import { lightboxService } from "@/modules/lightbox/service"; import { PageHeader } from "@/components/ui/page-header"; import { Alert, EmptyState } from "@/components/ui/sakani"; import { requireEditorial } from "../access"; // ponytail: same ceiling as the album detail page — cross-album search fetches // up to 1000 matching photos, then filters/paginates in-app. const SEARCH_FETCH_SIZE = 1000; export default async function AlbumsPage({ searchParams }: { searchParams: Promise<{ suche?: string | string[]; page?: string | string[]; format?: string | string[]; jahr?: string | string[]; sortierung?: string | string[] }> }) { const principal = await requireEditorial(); const rawSearchParams = await searchParams; const query = normalizedQuery(singleValue(rawSearchParams.suche)); const format = singleValue(rawSearchParams.format); const jahr = singleValue(rawSearchParams.jahr); const sortierung = normalizeSort(singleValue(rawSearchParams.sortierung)); const hints = await announcementService.listActiveAnnouncements(new Date()); if (query) { let results; try { results = await albumCatalog.searchVisiblePhotos(principal.editorialId, { description: query, page: 1, size: SEARCH_FETCH_SIZE, }); } catch (error) { if (error instanceof AlbumCatalogError && error.code === "RATE_LIMITED") { return ; } throw error; } await recordActivity({ editorialId: principal.editorialId, type: "search", query }); const filtered = sortPhotos(filterPhotos(results.items, { format, jahr }), sortierung); const { result: page, currentPage } = paginatePhotos(filtered, singleValue(rawSearchParams.page), PHOTO_PAGE_SIZE); const downloadOptions = await loadEditorialDownloadOptions( principal.editorialId, page.items.map((asset) => asset.id), ); const lightboxItems = await lightboxService.getLightboxItems(principal.editorialId); const lightboxAssetIds = new Set(lightboxItems.map(i => i.assetId)); return ( {formatCount(page.total, "Foto")} gefunden lightboxAssetIds.has(id)).map(({ id }) => id)} showAlbumName /> ); } const result = await loadAlbums(principal.editorialId); if (result.unavailable) { return ; } return ( {result.albums.length === 0 ? ( ) : ( )} ); } function SearchRateLimited({ query, format, jahr, sortierung }: { query: string; format?: string; jahr?: string; sortierung: PhotoSort }) { return ( ); } function GlobalSearchPagination({ currentPage, page, query, format, jahr, sortierung }: { currentPage: number; page: InAppPage; query: string; format?: string; jahr?: string; sortierung: PhotoSort }) { return ( ); } function globalPageHref(page: number, query: string, format?: string, jahr?: string, sortierung?: PhotoSort): string { const parameters = new URLSearchParams({ suche: query, page: String(page) }); if (format) parameters.set("format", format); if (jahr) parameters.set("jahr", jahr); if (sortierung === "aelteste") parameters.set("sortierung", "aelteste"); return `/redaktion/alben?${parameters.toString()}`; } 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); } async function loadAlbums(editorialId: string) { try { return { albums: await albumCatalog.getVisibleAlbums(editorialId), unavailable: false as const }; } catch (error) { if (error instanceof AlbumCatalogError && error.code === "IMMICH_UNAVAILABLE") { return { albums: [], unavailable: true as const }; } throw error; } } function ImmichUnavailable() { return ( ); }
{formatCount(page.total, "Foto")} gefunden