2026-02-14 00:59:57 +01:00
|
|
|
/**
|
|
|
|
|
* Catch-all route — handles both subpage listings and album detail pages.
|
|
|
|
|
*
|
|
|
|
|
* Single segment:
|
|
|
|
|
* - If slug matches a subpage → render subpage album grid
|
|
|
|
|
* - If slug matches a standalone album → render album detail
|
|
|
|
|
*
|
|
|
|
|
* Two segments:
|
|
|
|
|
* - Treat as subpage-slug/album-slug → render album detail
|
|
|
|
|
* with back-link to the subpage
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import Link from 'next/link';
|
2026-02-14 10:30:27 +01:00
|
|
|
import Image from 'next/image';
|
|
|
|
|
import { cookies } from 'next/headers';
|
|
|
|
|
import type { Metadata } from 'next';
|
2026-02-15 11:23:51 +01:00
|
|
|
import { immich, type ImmichAsset } from '@/lib/immich';
|
2026-02-14 00:59:57 +01:00
|
|
|
import { notFound } from 'next/navigation';
|
2026-02-15 11:23:51 +01:00
|
|
|
import { PhotoGrid, type PhotoItem } from './PhotoGrid';
|
2026-02-14 11:47:26 +01:00
|
|
|
import {
|
|
|
|
|
imageUrl,
|
|
|
|
|
exifUrl,
|
2026-05-29 17:05:12 +02:00
|
|
|
videoUrl,
|
2026-02-14 11:47:26 +01:00
|
|
|
assetPlaceholder,
|
|
|
|
|
assetExifSummary,
|
|
|
|
|
assetAspectRatio,
|
|
|
|
|
} from '@/lib/urls';
|
2026-02-14 10:30:27 +01:00
|
|
|
import { getConfig, type GridConfig } from '@/lib/config';
|
|
|
|
|
import { isProtected, isAuthenticated } from '@/lib/auth';
|
|
|
|
|
import PasswordGate from '@/components/PasswordGate';
|
2026-02-15 11:23:51 +01:00
|
|
|
import { BackLink } from '@/components/BackLink';
|
2026-03-08 18:55:45 +01:00
|
|
|
import { AlbumDetailView } from './AlbumDetailView';
|
|
|
|
|
import { SubpageGridView } from './SubpageGridView';
|
2026-02-14 00:59:57 +01:00
|
|
|
|
|
|
|
|
// Render at request time — requires live Immich connection
|
|
|
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
|
|
|
|
|
|
interface PathPageProps {
|
2026-02-14 11:47:26 +01:00
|
|
|
params: Promise<{ path: string[] }>;
|
2026-02-14 00:59:57 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-14 10:30:27 +01:00
|
|
|
export async function generateMetadata({ params }: PathPageProps): Promise<Metadata> {
|
2026-02-14 11:47:26 +01:00
|
|
|
const { path } = await params;
|
|
|
|
|
if (!path || path.length === 0) return {};
|
2026-02-14 10:30:27 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
const slug = path[0];
|
|
|
|
|
let title = slug;
|
|
|
|
|
let subtitle = '';
|
2026-02-14 10:30:27 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
if (path.length === 2) {
|
|
|
|
|
const album = await immich.getAlbumBySlug(path[1], slug);
|
|
|
|
|
if (album) {
|
|
|
|
|
title = album.albumName;
|
2026-05-29 17:05:12 +02:00
|
|
|
const count = album.assets.filter((a) => a.type === 'IMAGE' || a.type === 'VIDEO').length;
|
2026-02-14 11:47:26 +01:00
|
|
|
subtitle = `${count} photo${count === 1 ? '' : 's'}`;
|
|
|
|
|
}
|
|
|
|
|
} else if (immich.isSubpageSlug(slug)) {
|
|
|
|
|
const result = await immich.getSubpageAlbums(slug);
|
|
|
|
|
if (result) {
|
|
|
|
|
// Single album → use album name; multiple → use subpage name
|
|
|
|
|
if (result.albums.length === 1) {
|
|
|
|
|
const album = await immich.getAlbumBySlug(result.albums[0].slug, slug);
|
2026-02-14 10:30:27 +01:00
|
|
|
if (album) {
|
2026-02-14 11:47:26 +01:00
|
|
|
title = album.albumName;
|
2026-05-29 17:05:12 +02:00
|
|
|
const count = album.assets.filter((a) => a.type === 'IMAGE' || a.type === 'VIDEO').length;
|
2026-02-14 11:47:26 +01:00
|
|
|
subtitle = `${count} photo${count === 1 ? '' : 's'}`;
|
2026-02-14 10:30:27 +01:00
|
|
|
}
|
2026-02-14 11:47:26 +01:00
|
|
|
} else {
|
|
|
|
|
title = result.subpage.name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
const album = await immich.getAlbumBySlug(slug);
|
|
|
|
|
if (album) {
|
|
|
|
|
title = album.albumName;
|
2026-05-29 17:05:12 +02:00
|
|
|
const count = album.assets.filter((a) => a.type === 'IMAGE' || a.type === 'VIDEO').length;
|
2026-02-14 11:47:26 +01:00
|
|
|
subtitle = `${count} photo${count === 1 ? '' : 's'}`;
|
2026-02-14 10:30:27 +01:00
|
|
|
}
|
2026-02-14 11:47:26 +01:00
|
|
|
}
|
2026-02-14 10:30:27 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
const ogUrl = `/api/og?title=${encodeURIComponent(title)}${subtitle ? `&subtitle=${encodeURIComponent(subtitle)}` : ''}`;
|
2026-02-14 10:30:27 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
return {
|
|
|
|
|
title,
|
|
|
|
|
openGraph: { title, images: [ogUrl] },
|
|
|
|
|
twitter: { card: 'summary_large_image', title, images: [ogUrl] },
|
|
|
|
|
};
|
2026-02-14 10:30:27 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-15 11:23:51 +01:00
|
|
|
/** Map Immich assets to PhotoItem props for the grid/lightbox. */
|
|
|
|
|
function toPhotoItems(assets: ImmichAsset[], showExif: boolean): PhotoItem[] {
|
|
|
|
|
return assets
|
2026-05-29 17:05:12 +02:00
|
|
|
.filter((a) => a.type === 'IMAGE' || a.type === 'VIDEO')
|
2026-02-15 11:23:51 +01:00
|
|
|
.map((a) => {
|
|
|
|
|
const ph = assetPlaceholder(a);
|
2026-05-29 17:05:12 +02:00
|
|
|
const exif = showExif && a.type === 'IMAGE' ? assetExifSummary(a) : undefined;
|
|
|
|
|
const isVideo = a.type === 'VIDEO';
|
2026-02-15 11:23:51 +01:00
|
|
|
return {
|
|
|
|
|
id: a.id,
|
2026-05-29 17:05:12 +02:00
|
|
|
type: isVideo ? 'video' : 'image',
|
2026-05-30 15:21:28 +02:00
|
|
|
thumbUrl: imageUrl(a.id, 'preview'),
|
2026-02-15 11:23:51 +01:00
|
|
|
previewUrl: imageUrl(a.id, 'preview'),
|
|
|
|
|
originalUrl: imageUrl(a.id, 'original'),
|
2026-05-29 17:05:12 +02:00
|
|
|
...(isVideo ? { videoUrl: videoUrl(a.id) } : {}),
|
2026-02-15 11:23:51 +01:00
|
|
|
exifUrl: exifUrl(a.id),
|
|
|
|
|
...(ph ? { blurDataURL: ph.blurDataURL, dominantColor: ph.dominantColor } : {}),
|
|
|
|
|
...(exif ?? {}),
|
|
|
|
|
aspectRatio: assetAspectRatio(a),
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-13 11:56:40 +01:00
|
|
|
/**
|
2026-04-07 23:04:03 +02:00
|
|
|
* Returns a PasswordGate element if the key (slug or ID) is protected and
|
|
|
|
|
* not yet authenticated, otherwise returns null.
|
2026-03-13 11:56:40 +01:00
|
|
|
*/
|
2026-04-07 23:04:03 +02:00
|
|
|
async function gateIfProtected(
|
|
|
|
|
key: string,
|
|
|
|
|
type: 'subpage' | 'album' = 'subpage',
|
|
|
|
|
titleOverride?: string,
|
|
|
|
|
): Promise<React.ReactElement | null> {
|
|
|
|
|
if (!isProtected(key, type)) return null;
|
2026-03-13 11:56:40 +01:00
|
|
|
const cookieStore = await cookies();
|
|
|
|
|
const getCookie = (name: string) => cookieStore.get(name)?.value;
|
2026-04-07 23:04:03 +02:00
|
|
|
if (isAuthenticated(key, getCookie, type)) return null;
|
|
|
|
|
|
|
|
|
|
let title = titleOverride || key;
|
|
|
|
|
if (!titleOverride && type === 'subpage') {
|
|
|
|
|
const subpageData = await immich.getSubpageAlbums(key);
|
|
|
|
|
title = subpageData?.subpage.name ?? key;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <PasswordGate slug={key} title={title} type={type} />;
|
2026-03-13 11:56:40 +01:00
|
|
|
}
|
|
|
|
|
|
2026-05-30 15:33:43 +02:00
|
|
|
/** Fetch hero image URL + blur placeholder for an album if configured. */
|
|
|
|
|
async function getAlbumHeroData(
|
|
|
|
|
albumId: string,
|
|
|
|
|
config: ReturnType<typeof getConfig>,
|
|
|
|
|
): Promise<{ heroImageUrl: string; heroBlurDataURL?: string } | null> {
|
|
|
|
|
const heroAssetId = config.albumHeroImages[albumId];
|
|
|
|
|
if (!heroAssetId) return null;
|
|
|
|
|
const asset = await immich.getAssetInfo(heroAssetId);
|
|
|
|
|
const ph = asset ? assetPlaceholder(asset) : null;
|
|
|
|
|
return {
|
|
|
|
|
heroImageUrl: imageUrl(heroAssetId, 'preview'),
|
|
|
|
|
heroBlurDataURL: ph?.blurDataURL,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 00:59:57 +01:00
|
|
|
export default async function PathPage({ params }: PathPageProps) {
|
2026-02-14 11:47:26 +01:00
|
|
|
const { path } = await params;
|
|
|
|
|
const config = getConfig();
|
2026-02-14 00:59:57 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
// Build grid CSS custom properties, optionally merging subpage overrides
|
|
|
|
|
const buildGridStyle = (overrides?: Partial<GridConfig>): React.CSSProperties => {
|
|
|
|
|
const g = { ...config.grid, ...overrides };
|
|
|
|
|
return {
|
|
|
|
|
'--grid-columns': g.columns,
|
|
|
|
|
'--grid-gap': `${g.gap}px`,
|
|
|
|
|
'--grid-aspect-ratio': g.aspectRatio,
|
|
|
|
|
} as React.CSSProperties;
|
|
|
|
|
};
|
|
|
|
|
const resolveLayout = (overrides?: Partial<GridConfig>) =>
|
|
|
|
|
overrides?.layout ?? config.grid.layout;
|
2026-02-14 10:30:27 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
if (!path || path.length === 0) {
|
|
|
|
|
notFound();
|
|
|
|
|
}
|
2026-02-14 10:30:27 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
// ── Two segments: subpage/album ──────────────────────────────
|
|
|
|
|
if (path.length === 2) {
|
|
|
|
|
const [subpageSlug, albumSlug] = path;
|
2026-02-14 00:59:57 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
// Password gate for protected subpages
|
2026-03-13 11:56:40 +01:00
|
|
|
const gate = await gateIfProtected(subpageSlug);
|
|
|
|
|
if (gate) return gate;
|
2026-02-14 00:59:57 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
const album = await immich.getAlbumBySlug(albumSlug, subpageSlug);
|
2026-02-14 00:59:57 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
if (!album) {
|
|
|
|
|
notFound();
|
2026-02-14 00:59:57 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
// Look up subpage config for grid overrides and back link
|
|
|
|
|
const subpageData = await immich.getSubpageAlbums(subpageSlug);
|
|
|
|
|
const spGrid = subpageData?.subpage.grid;
|
|
|
|
|
const subpageName = subpageData?.subpage.name ?? subpageSlug;
|
2026-02-14 00:59:57 +01:00
|
|
|
|
2026-02-15 11:23:51 +01:00
|
|
|
const images = toPhotoItems(album.assets, config.exifOnHover);
|
2026-02-14 10:30:27 +01:00
|
|
|
|
2026-04-07 23:04:03 +02:00
|
|
|
// Password gate for protected albums
|
|
|
|
|
const albumGate = await gateIfProtected(album.id, 'album', album.albumName);
|
|
|
|
|
if (albumGate) return albumGate;
|
|
|
|
|
|
2026-05-30 15:33:43 +02:00
|
|
|
const heroData = await getAlbumHeroData(album.id, config);
|
|
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
return (
|
2026-03-08 18:55:45 +01:00
|
|
|
<AlbumDetailView
|
|
|
|
|
album={album}
|
|
|
|
|
images={images}
|
|
|
|
|
layout={resolveLayout(spGrid)}
|
|
|
|
|
gridStyle={buildGridStyle(spGrid)}
|
|
|
|
|
backLinkHref={`/${subpageSlug}`}
|
|
|
|
|
backLinkLabel={`Back to ${subpageName}`}
|
2026-05-30 15:33:43 +02:00
|
|
|
{...heroData}
|
2026-03-08 18:55:45 +01:00
|
|
|
/>
|
2026-02-14 11:47:26 +01:00
|
|
|
);
|
|
|
|
|
}
|
2026-02-14 00:59:57 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
// ── Single segment: subpage or standalone album ──────────────
|
|
|
|
|
const slug = path[0];
|
2026-02-14 00:59:57 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
// Check if it's a subpage
|
|
|
|
|
if (immich.isSubpageSlug(slug)) {
|
|
|
|
|
// Password gate for protected subpages
|
2026-03-13 11:56:40 +01:00
|
|
|
const gate = await gateIfProtected(slug);
|
|
|
|
|
if (gate) return gate;
|
2026-02-14 10:30:27 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
const result = await immich.getSubpageAlbums(slug);
|
|
|
|
|
if (!result || result.albums.length === 0) {
|
|
|
|
|
notFound();
|
|
|
|
|
}
|
2026-02-14 10:30:27 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
const { albums } = result;
|
2026-02-14 10:30:27 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
// ── Single album → full-bleed (skip album grid) ──────────
|
|
|
|
|
if (albums.length === 1) {
|
|
|
|
|
const album = await immich.getAlbumBySlug(albums[0].slug, slug);
|
|
|
|
|
if (!album) notFound();
|
2026-02-14 10:30:27 +01:00
|
|
|
|
2026-02-15 11:23:51 +01:00
|
|
|
const images = toPhotoItems(album.assets, config.exifOnHover);
|
2026-02-14 10:30:27 +01:00
|
|
|
|
2026-04-07 23:04:03 +02:00
|
|
|
// Password gate for protected albums
|
|
|
|
|
const albumGate = await gateIfProtected(album.id, 'album', album.albumName);
|
|
|
|
|
if (albumGate) return albumGate;
|
|
|
|
|
|
2026-05-30 15:33:43 +02:00
|
|
|
const heroData = await getAlbumHeroData(album.id, config);
|
|
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
return (
|
2026-03-08 18:55:45 +01:00
|
|
|
<AlbumDetailView
|
|
|
|
|
album={album}
|
|
|
|
|
images={images}
|
|
|
|
|
layout={resolveLayout(result.subpage.grid)}
|
|
|
|
|
gridStyle={buildGridStyle(result.subpage.grid)}
|
2026-03-08 23:16:01 +01:00
|
|
|
subtitle={result.subpage.subtitle}
|
2026-03-08 18:55:45 +01:00
|
|
|
backLinkHref="/"
|
|
|
|
|
backLinkLabel="Back to Gallery"
|
2026-05-30 15:33:43 +02:00
|
|
|
{...heroData}
|
2026-03-08 18:55:45 +01:00
|
|
|
/>
|
2026-02-14 11:47:26 +01:00
|
|
|
);
|
2026-02-14 00:59:57 +01:00
|
|
|
}
|
|
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
// ── Multiple albums → show album grid ─────────────────────
|
2026-02-14 00:59:57 +01:00
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
// Batch-fetch ThumbHash for album cover placeholders
|
|
|
|
|
const coverPlaceholders = await Promise.all(
|
|
|
|
|
albums.map(async (album) => {
|
|
|
|
|
if (!album.albumThumbnailAssetId) return null;
|
|
|
|
|
const asset = await immich.getAssetInfo(album.albumThumbnailAssetId);
|
|
|
|
|
return asset ? assetPlaceholder(asset) : null;
|
|
|
|
|
}),
|
|
|
|
|
);
|
2026-02-14 00:59:57 +01:00
|
|
|
|
|
|
|
|
return (
|
2026-03-08 18:55:45 +01:00
|
|
|
<SubpageGridView
|
|
|
|
|
slug={slug}
|
2026-03-08 22:46:27 +01:00
|
|
|
title={result.subpage.title || result.subpage.name}
|
|
|
|
|
subtitle={result.subpage.subtitle}
|
2026-03-08 18:55:45 +01:00
|
|
|
albums={albums}
|
|
|
|
|
coverPlaceholders={coverPlaceholders}
|
2026-03-08 23:52:23 +01:00
|
|
|
sections={result.subpage.sections}
|
2026-03-08 18:55:45 +01:00
|
|
|
/>
|
2026-02-14 00:59:57 +01:00
|
|
|
);
|
2026-02-14 11:47:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Otherwise treat as a standalone album slug
|
|
|
|
|
const album = await immich.getAlbumBySlug(slug);
|
|
|
|
|
if (!album) {
|
|
|
|
|
notFound();
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-15 11:23:51 +01:00
|
|
|
const images = toPhotoItems(album.assets, config.exifOnHover);
|
2026-02-14 11:47:26 +01:00
|
|
|
|
2026-04-07 23:04:03 +02:00
|
|
|
// Password gate for protected albums
|
|
|
|
|
const albumGate = await gateIfProtected(album.id, 'album', album.albumName);
|
|
|
|
|
if (albumGate) return albumGate;
|
|
|
|
|
|
2026-05-30 15:33:43 +02:00
|
|
|
const heroData = await getAlbumHeroData(album.id, config);
|
|
|
|
|
|
2026-02-14 11:47:26 +01:00
|
|
|
return (
|
2026-03-08 18:55:45 +01:00
|
|
|
<AlbumDetailView
|
|
|
|
|
album={album}
|
|
|
|
|
images={images}
|
|
|
|
|
layout={resolveLayout()}
|
|
|
|
|
gridStyle={buildGridStyle()}
|
|
|
|
|
backLinkHref="/"
|
|
|
|
|
backLinkLabel="Back to Gallery"
|
2026-05-30 15:33:43 +02:00
|
|
|
{...heroData}
|
2026-03-08 18:55:45 +01:00
|
|
|
/>
|
2026-02-14 11:47:26 +01:00
|
|
|
);
|
2026-02-14 00:59:57 +01:00
|
|
|
}
|