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