feat: standardizer changes

This commit is contained in:
Leon Tonhäuser committed 2026-08-11 11:19:10 +02:00
1 parent 8728308fc6
commit 70ebcc9cd5
13 files changed
+141 -113

No files matched your search

+5 -4
View File
@@ -4,6 +4,7 @@ import { usages, editorialAccounts } from "@/db/schema";
import { requireAdmin } from "@/modules/auth/principal";
import { headers } from "next/headers";
import Link from "next/link";
import { PageHeader } from "@/components/ui/page-header";
import { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
@@ -51,10 +52,10 @@ export default async function AdminDashboardPage() {
return (
<div className="space-y-8 animate-in fade-in slide-in-from-bottom-4 duration-500">
<div>
<h1 className="text-4xl font-bold tracking-tight">Admin Dashboard</h1>
<p className="text-muted-foreground mt-2">Willkommen zurück! Hier ist ein Überblick über die aktuelle Nutzung des Portals.</p>
</div>
<PageHeader
title="Admin Dashboard"
description="Willkommen zurück! Hier ist ein Überblick über die aktuelle Nutzung des Portals."
/>
<div className="grid grid-cols-1 md:grid-cols-3 gap-6">
<Card>
+7 -2
View File
@@ -1,5 +1,7 @@
import { desc } from "drizzle-orm";
import { PageHeader } from "@/components/ui/page-header";
import { db } from "@/db/client";
import { editorialAccounts } from "@/db/schema";
@@ -23,8 +25,11 @@ export default async function EditorialsPage() {
return (
<section className="content-section" aria-labelledby="editorials-title">
<p className="eyebrow">Kontoverwaltung</p>
<h1 id="editorials-title">Redaktionen</h1>
<PageHeader
kicker="Kontoverwaltung"
title="Redaktionen"
titleId="editorials-title"
/>
{activeEditorials.length === 0 ? (
<p>Noch keine aktiven Redaktionen registriert.</p>
) : (
+15 -6
View File
@@ -7,6 +7,7 @@ import { loadEditorialDownloadOptions } from "@/modules/downloads/stream";
import { lightboxService } from "@/modules/lightbox/service";
import { requireEditorial } from "../../access";
import { PageHeader } from "@/components/ui/page-header";
type AlbumPageProps = Readonly<{
params: Promise<{ albumId: string }>;
@@ -41,13 +42,15 @@ export default async function AlbumPage({ params, searchParams }: AlbumPageProps
return (
<section className="editorial-section" aria-labelledby="album-title">
<p className="editorial-kicker">Bildarchiv · {result.album.assetCount} freigegebene Fotos</p>
<div className="editorial-title-row album-title-row">
<h1 id="album-title">{result.album.albumName}</h1>
<PageHeader
kicker={`Bildarchiv · ${result.album.assetCount} freigegebene Fotos`}
title={result.album.albumName}
titleId="album-title"
>
<Link className="quiet-link" href="/redaktion/alben">
Alle Alben
</Link>
</div>
</PageHeader>
<AlbumSearchForm albumId={result.album.id} query={query} format={format} jahr={jahr} />
<PhotoContactSheet
albumId={result.album.id}
@@ -175,12 +178,18 @@ function normalizedQuery(value: string | undefined): string {
function ImmichUnavailable() {
return (
<section className="editorial-section editorial-state" aria-labelledby="album-title">
<p className="editorial-kicker">Bildarchiv</p>
<h1 id="album-title">Fotos momentan nicht erreichbar</h1>
<PageHeader
kicker="Bildarchiv"
title="Fotos momentan nicht erreichbar"
titleId="album-title"
>
<div className="flex flex-col gap-2 items-end">
<p role="status">Bitte laden Sie diese Seite in wenigen Minuten erneut.</p>
<Link className="quiet-link" href="/redaktion/alben">
Zurück zu den Alben
</Link>
</div>
</PageHeader>
</section>
);
}
+17 -13
View File
@@ -4,6 +4,7 @@ import { loadEditorialDownloadOptions } from "@/modules/downloads/stream";
import { lightboxService } from "@/modules/lightbox/service";
import type { ImmichSearchPage } from "@/modules/immich/types";
import Link from "next/link";
import { PageHeader } from "@/components/ui/page-header";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
@@ -56,10 +57,11 @@ export default async function AlbumsPage({ searchParams }: { searchParams: Promi
return (
<div className="space-y-6 max-w-7xl animate-in fade-in slide-in-from-bottom-4 duration-500" aria-labelledby="albums-title">
<div>
<p className="text-sm font-semibold uppercase tracking-widest text-primary-600 dark:text-primary-500 mb-2">Bildarchiv · Suche</p>
<h1 id="albums-title" className="text-4xl font-bold tracking-tight">Suchergebnisse</h1>
</div>
<PageHeader
kicker="Bildarchiv · Suche"
title="Suchergebnisse"
titleId="albums-title"
/>
<GlobalSearchForm query={query} format={format} jahr={jahr} />
<PhotoContactSheet
albumName="Alle Alben"
@@ -82,11 +84,12 @@ export default async function AlbumsPage({ searchParams }: { searchParams: Promi
return (
<div className="space-y-8 max-w-7xl animate-in fade-in slide-in-from-bottom-4 duration-500" aria-labelledby="albums-title">
<div>
<p className="text-sm font-semibold uppercase tracking-widest text-primary-600 dark:text-primary-500 mb-2">Bildarchiv · Freigaben</p>
<h1 id="albums-title" className="text-4xl font-bold tracking-tight">Ihre Alben</h1>
<p className="text-muted-foreground mt-2">Wählen Sie ein Spiel oder eine Serie, um die freigegebenen Fotos zu durchsuchen.</p>
</div>
<PageHeader
kicker="Bildarchiv · Freigaben"
title="Ihre Alben"
titleId="albums-title"
description="Wählen Sie ein Spiel oder eine Serie, um die freigegebenen Fotos zu durchsuchen."
/>
<GlobalSearchForm query={query} format={format} jahr={jahr} />
{result.albums.length === 0 ? (
<p className="text-muted-foreground text-center py-12">Für Ihre Redaktion sind noch keine Fotoalben freigegeben.</p>
@@ -169,10 +172,11 @@ async function loadAlbums(editorialId: string) {
function ImmichUnavailable() {
return (
<div className="space-y-6 max-w-7xl animate-in fade-in slide-in-from-bottom-4 duration-500" aria-labelledby="albums-title">
<div>
<p className="text-sm font-semibold uppercase tracking-widest text-primary-600 dark:text-primary-500 mb-2">Bildarchiv</p>
<h1 id="albums-title" className="text-4xl font-bold tracking-tight">Alben momentan nicht erreichbar</h1>
</div>
<PageHeader
kicker="Bildarchiv"
title="Alben momentan nicht erreichbar"
titleId="albums-title"
/>
<div className="bg-destructive/15 text-destructive p-4 rounded-md border border-destructive/30" role="status">
Bitte laden Sie diese Seite in wenigen Minuten erneut. Ihre Freigaben bleiben unverändert.
</div>
+5 -4
View File
@@ -1,4 +1,5 @@
import { headers } from "next/headers";
import { PageHeader } from "@/components/ui/page-header";
import { requireActiveEditorial } from "@/modules/auth/principal";
import { lightboxService } from "@/modules/lightbox/service";
import { immichClient } from "@/modules/immich/client";
@@ -21,10 +22,10 @@ export default async function LightboxPage() {
return (
<div className="space-y-8 max-w-7xl animate-in fade-in slide-in-from-bottom-4 duration-500">
<div>
<p className="text-sm font-semibold uppercase tracking-widest text-primary-600 dark:text-primary-500 mb-2">Merkzettel</p>
<h1 className="text-4xl font-bold tracking-tight">Dein Leuchtkasten</h1>
</div>
<PageHeader
kicker="Merkzettel"
title="Dein Leuchtkasten"
/>
{items.length === 0 ? (
<p className="text-muted-foreground text-center py-12">Dein Leuchtkasten ist leer.</p>
@@ -1,5 +1,7 @@
import Link from "next/link";
import { PageHeader } from "@/components/ui/page-header";
import { formatBerlinDateTime } from "@/modules/downloads/format";
import type { UsageHistoryAttempt, UsageHistoryPage } from "@/modules/downloads/stream";
@@ -17,11 +19,12 @@ const byteFormatter = new Intl.NumberFormat("de-DE", {
export function UsageHistoryContent({ history }: Readonly<{ history: UsageHistoryPage }>) {
return (
<section className="editorial-section usage-history" aria-labelledby="usage-history-title">
<p className="editorial-kicker">Abrechnung · Downloadprotokoll</p>
<div className="editorial-title-row">
<h1 id="usage-history-title">Ihre Nutzungen</h1>
<p>Verwendungszwecke, Kosten und Auslieferungsversuche Ihrer Redaktion.</p>
</div>
<PageHeader
kicker="Abrechnung · Downloadprotokoll"
title="Ihre Nutzungen"
titleId="usage-history-title"
description="Verwendungszwecke, Kosten und Auslieferungsversuche Ihrer Redaktion."
/>
{history.items.length === 0 ? (
<div className="usage-history-empty">
+7 -2
View File
@@ -1,5 +1,7 @@
import { eq } from "drizzle-orm";
import { PageHeader } from "@/components/ui/page-header";
import { db } from "@/db/client";
import { billingAddressVersions, editorialAccounts } from "@/db/schema";
@@ -28,8 +30,11 @@ export default async function EditorialProfilePage() {
return (
<section className="editorial-section" aria-labelledby="profile-title">
<p className="eyebrow">Redaktionskonto</p>
<h1 id="profile-title">Profil</h1>
<PageHeader
kicker="Redaktionskonto"
title="Profil"
titleId="profile-title"
/>
<dl>
<dt>Redaktion</dt>
<dd>{editorial?.name}</dd>
+4 -13
View File
@@ -1,22 +1,13 @@
/* eslint-disable @next/next/no-img-element */
type BrandLogoProps = {
variant: "black" | "white";
};
export function BrandLogo({ variant }: Readonly<BrandLogoProps>) {
const logo =
variant === "white"
? { source: "/brand/logo-white.png", width: 250, height: 250 }
: { source: "/brand/logo-black.png", width: 1000, height: 1000 };
export function BrandLogo() {
return (
<img
alt="Leon Tonhäuser Sportfotografie"
className="brand-logo"
height={logo.height}
src={logo.source}
width={logo.width}
height={250}
src="/brand/logo-black.png"
width={250}
/>
);
}
+1 -3
View File
@@ -32,9 +32,7 @@ export function PortalShell({
<header className="sticky top-0 z-50 w-full border-b border-border/40 bg-background/80 backdrop-blur-md transition-colors duration-300">
<div className="flex h-16 items-center justify-between px-6 lg:px-12">
<Link aria-label={sectionLabel} className="flex items-center gap-2 transition-opacity hover:opacity-80" href={brandHref}>
{/* The BrandLogo might need to be theme-aware or we just use white/black depending on theme */}
<div className="dark:hidden flex items-center"><BrandLogo variant="black" /></div>
<div className="hidden dark:flex items-center"><BrandLogo variant="white" /></div>
<div className="flex items-center"><BrandLogo /></div>
</Link>
<div className="flex items-center gap-6 text-sm font-medium">
<span className="hidden md:inline-block text-muted-foreground uppercase tracking-widest text-xs font-bold">{sectionLabel}</span>
+31
View File
@@ -0,0 +1,31 @@
import * as React from "react"
import { cn } from "@/lib/utils"
export interface PageHeaderProps extends React.HTMLAttributes<HTMLDivElement> {
kicker?: React.ReactNode;
title: React.ReactNode;
description?: React.ReactNode;
titleId?: string;
}
export function PageHeader({
className,
kicker,
title,
description,
titleId,
children,
...props
}: PageHeaderProps) {
return (
<header className={cn("mb-8", className)} {...props}>
{kicker && <p className="editorial-kicker">{kicker}</p>}
<div className="editorial-title-row">
<h1 id={titleId}>{title}</h1>
{description && <p>{description}</p>}
{children}
</div>
</header>
)
}
+2 -2
View File
@@ -235,7 +235,7 @@ export function buildDocumentDefinition(snapshot: BillingReportSnapshot) {
columns: [
{
image: "logo",
width: 120,
width: 80,
},
{
width: "*",
@@ -297,7 +297,7 @@ export function buildDocumentDefinition(snapshot: BillingReportSnapshot) {
// Recipient block
{
stack: addressLines.map((line) => ({ text: line, style: "recipient" })),
margin: [0, 0, 0, 20],
margin: [0, 40, 0, 20],
},
// Title
+28 -50
View File
@@ -92,15 +92,10 @@ function createRepository() {
function createService() {
const state = createRepository();
const immich = {
listAlbumsForAsset: vi.fn().mockResolvedValue([
{
getAlbum: vi.fn().mockResolvedValue({
id: albumId,
albumName: "Presse 2026",
description: null,
albumThumbnailAssetId: assetId,
assetCount: 1,
},
]),
}),
getAsset: vi.fn().mockResolvedValue({
id: assetId,
type: "IMAGE" as const,
@@ -162,7 +157,7 @@ test("canonicalizes every UUID before fingerprinting, lookup, Immich calls, and
expect(second).toEqual(first);
expect(usages).toHaveLength(1);
expect(usages[0]).toMatchObject({ editorialId, assetId, albumId, idempotencyKey });
expect(immich.listAlbumsForAsset).toHaveBeenCalledWith(assetId);
expect(immich.getAlbum).toHaveBeenCalledWith(albumId);
expect(immich.getAsset).toHaveBeenCalledWith(assetId);
});
@@ -231,72 +226,54 @@ test.each([
}),
).rejects.toMatchObject({ code });
expect(findIntent).not.toHaveBeenCalled();
expect(immich.listAlbumsForAsset).not.toHaveBeenCalled();
expect(immich.getAlbum).not.toHaveBeenCalled();
expect(immich.getAsset).not.toHaveBeenCalled();
},
);
test("rejects an asset outside the exact requested album", async () => {
const { service, immich, usages } = createService();
immich.listAlbumsForAsset.mockResolvedValue([
{
id: otherAlbumId,
albumName: "Andere Bilder",
description: null,
albumThumbnailAssetId: null,
assetCount: 1,
},
]);
immich.getAsset.mockResolvedValue({
id: assetId,
type: "IMAGE",
originalFileName: "jubel.jpg",
albums: [{ id: otherAlbumId }],
});
await expect(service.createNewUsage(newUsageInput)).rejects.toMatchObject({
code: "ASSET_NOT_IN_ALBUM",
});
expect(immich.getAsset).not.toHaveBeenCalled();
expect(immich.getAlbum).not.toHaveBeenCalled();
expect(usages).toHaveLength(0);
});
test("rejects removal from the requested album between preflight and locked refresh", async () => {
const { service, immich, usages } = createService();
immich.listAlbumsForAsset
.mockResolvedValueOnce([
{
id: albumId,
albumName: "Presse 2026",
description: null,
albumThumbnailAssetId: assetId,
assetCount: 1,
},
])
.mockResolvedValueOnce([]);
const currentAsset = {
id: assetId,
type: "IMAGE" as const,
originalFileName: "jubel.jpg",
originalMimeType: "image/jpeg",
localDateTime: null,
fileCreatedAt: null,
albums: [{ id: albumId }],
};
immich.getAsset
.mockResolvedValueOnce(currentAsset)
.mockResolvedValueOnce({ ...currentAsset, albums: [] });
await expect(service.createNewUsage(newUsageInput)).rejects.toMatchObject({
code: "ASSET_NOT_IN_ALBUM",
});
expect(immich.listAlbumsForAsset).toHaveBeenCalledTimes(2);
expect(immich.getAsset).toHaveBeenCalledTimes(2);
expect(usages).toHaveLength(0);
});
test("persists metadata from the locked final Immich refresh", async () => {
const { service, immich, usages } = createService();
immich.listAlbumsForAsset
.mockResolvedValueOnce([
{
id: albumId,
albumName: "Presse 2026",
description: null,
albumThumbnailAssetId: assetId,
assetCount: 1,
},
])
.mockResolvedValueOnce([
{
id: albumId,
albumName: "Presse final",
description: null,
albumThumbnailAssetId: assetId,
assetCount: 1,
},
]);
immich.getAlbum
.mockResolvedValueOnce({ id: albumId, albumName: "Presse 2026" })
.mockResolvedValueOnce({ id: albumId, albumName: "Presse final" });
const currentAsset = {
id: assetId,
type: "IMAGE" as const,
@@ -317,6 +294,7 @@ test("persists metadata from the locked final Immich refresh", async () => {
await service.createNewUsage(newUsageInput);
expect(immich.getAsset).toHaveBeenCalledTimes(2);
expect(immich.getAlbum).toHaveBeenCalledTimes(2);
expect(usages).toEqual([
expect.objectContaining({ albumName: "Presse final", filename: "final.jpg" }),
]);
+11 -9
View File
@@ -57,11 +57,12 @@ export type UsageRepository = {
};
type UsageImmich = {
listAlbumsForAsset(assetId: string): Promise<ImmichAlbumSummary[]>;
getAlbum(albumId: string): Promise<{ id: string; albumName: string }>;
getAsset(assetId: string): Promise<{
id: string;
type: string;
originalFileName: string;
albums?: { id: string }[];
}>;
};
@@ -87,16 +88,16 @@ export function createUsageService({
const existing = await repository.findIntent(input.editorialId, input.idempotencyKey);
if (existing) return resolveIntent(existing, fingerprint, "new_usage");
const album = await loadRequestedAlbum(immich, input.assetId, input.albumId);
const asset = await loadImageAsset(immich, input.assetId);
const album = await loadRequestedAlbum(immich, asset, input.albumId);
const persisted = await repository.createBillableIntent({
...input,
albumName: normalizeUpstreamSnapshot(album.albumName),
filename: normalizeUpstreamSnapshot(asset.originalFileName),
requestFingerprint: fingerprint,
}, async () => {
const currentAlbum = await loadRequestedAlbum(immich, input.assetId, input.albumId);
const currentAsset = await loadImageAsset(immich, input.assetId);
const currentAlbum = await loadRequestedAlbum(immich, currentAsset, input.albumId);
return {
albumName: normalizeUpstreamSnapshot(currentAlbum.albumName),
filename: normalizeUpstreamSnapshot(currentAsset.originalFileName),
@@ -328,17 +329,18 @@ function normalizeNewUsageInput(input: CreateNewUsageInput): CreateNewUsageInput
async function loadRequestedAlbum(
immich: UsageImmich,
assetId: string,
asset: Awaited<ReturnType<UsageImmich["getAsset"]>>,
albumId: string,
): Promise<ImmichAlbumSummary> {
let albums: ImmichAlbumSummary[];
): Promise<{ id: string; albumName: string }> {
if (!asset.albums?.some((a) => a.id === albumId)) {
throw new UsageAccountingError("ASSET_NOT_IN_ALBUM");
}
let album;
try {
albums = await immich.listAlbumsForAsset(assetId);
album = await immich.getAlbum(albumId);
} catch {
throw new UsageAccountingError("IMMICH_UNAVAILABLE");
}
const album = albums.find((candidate) => candidate.id === albumId);
if (!album) throw new UsageAccountingError("ASSET_NOT_IN_ALBUM");
return album;
}