fix: comprehensive portal audit - bugfixes, performance, security, logo
Critical bugs: - Fix bulk-download: UUID idempotency key, input validation, error handling, parallel asset validation - Fix leuchtkasten 404 link -> album page with search - Fix revalidatePath [id] -> [albumId] - Fix PDF crash on null invoiceNumber Logo: - Fix dimensions (1000x1000), dark mode support (logo-white.png), max-height constraint UI bugs: - Fix unsafe Date method calls (6 files) - Fix album UUID shown instead of name in catalog - Fix global search downloads (albumId from asset) - Add null guard for lightbox asset map Performance: - Parallelize admin dashboard queries (Promise.all) - Lazy-load recharts via next/dynamic - Add thumbnail caching headers (24h + ETag) - Reduce duplicate Immich API calls in usage service - Add DB index on usages(createdAt) - Add optimizePackageImports for lucide-react, recharts Security: - Input validation on bulk-download (max 100 items, UUID format, purpose length) - Verify security headers present in next.config.ts
This commit is contained in:
1 parent
0576d946c5
commit
d9d69ed861
21 files changed
+150
-74
No files matched your search
@@ -3,6 +3,9 @@ import type { NextConfig } from "next";
|
|||||||
const nextConfig: NextConfig = {
|
const nextConfig: NextConfig = {
|
||||||
output: "standalone",
|
output: "standalone",
|
||||||
poweredByHeader: false,
|
poweredByHeader: false,
|
||||||
|
experimental: {
|
||||||
|
optimizePackageImports: ["lucide-react", "recharts"],
|
||||||
|
},
|
||||||
async headers() {
|
async headers() {
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ export default async function AuditPage({ searchParams }: { searchParams: Search
|
|||||||
<tbody>
|
<tbody>
|
||||||
{page.events.map((event) => (
|
{page.events.map((event) => (
|
||||||
<tr key={event.id}>
|
<tr key={event.id}>
|
||||||
<td>{berlinFormatter.format(event.occurredAt)}</td>
|
<td>{berlinFormatter.format(new Date(event.occurredAt))}</td>
|
||||||
<td>{actorLabel(event)}</td>
|
<td>{actorLabel(event)}</td>
|
||||||
<td>{event.eventType}</td>
|
<td>{event.eventType}</td>
|
||||||
<td>{entityLabel(event)}</td>
|
<td>{entityLabel(event)}</td>
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import dynamic from "next/dynamic";
|
||||||
|
|
||||||
|
const DownloadsChart = dynamic(
|
||||||
|
() => import("./downloads-chart").then((mod) => mod.DownloadsChart),
|
||||||
|
{ ssr: false }
|
||||||
|
);
|
||||||
|
|
||||||
|
export { DownloadsChart };
|
||||||
+16
-12
@@ -7,7 +7,7 @@ import Link from "next/link";
|
|||||||
import { PageHeader } from "@/components/ui/page-header";
|
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";
|
||||||
import { DownloadsChart } from "./downloads-chart";
|
import { DownloadsChart } from "./downloads-chart-lazy";
|
||||||
|
|
||||||
export default async function AdminDashboardPage() {
|
export default async function AdminDashboardPage() {
|
||||||
await requireAdmin(new Headers(await headers()));
|
await requireAdmin(new Headers(await headers()));
|
||||||
@@ -15,17 +15,21 @@ export default async function AdminDashboardPage() {
|
|||||||
const now = new Date();
|
const now = new Date();
|
||||||
const firstDayOfMonth = new Date(Date.UTC(now.getFullYear(), now.getMonth(), 1));
|
const firstDayOfMonth = new Date(Date.UTC(now.getFullYear(), now.getMonth(), 1));
|
||||||
|
|
||||||
|
const thirtyDaysAgo = new Date();
|
||||||
|
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
|
||||||
|
|
||||||
|
const [revenueStatsResult, topEditorials, topAlbums, dailyDownloads] = await Promise.all([
|
||||||
// 1. Umsatz diesen Monat (Offen + Abgerechnet, aber nur usages aus diesem Monat)
|
// 1. Umsatz diesen Monat (Offen + Abgerechnet, aber nur usages aus diesem Monat)
|
||||||
const [revenueStats] = await db
|
db
|
||||||
.select({
|
.select({
|
||||||
totalCents: sql<number>`COALESCE(SUM(${usages.priceCents}), 0)::int`,
|
totalCents: sql<number>`COALESCE(SUM(${usages.priceCents}), 0)::int`,
|
||||||
count: sql<number>`COUNT(${usages.id})::int`,
|
count: sql<number>`COUNT(${usages.id})::int`,
|
||||||
})
|
})
|
||||||
.from(usages)
|
.from(usages)
|
||||||
.where(gte(usages.createdAt, firstDayOfMonth));
|
.where(gte(usages.createdAt, firstDayOfMonth)),
|
||||||
|
|
||||||
// 2. Aktivste Redaktionen (nach Anzahl an Downloads insgesamt)
|
// 2. Aktivste Redaktionen (nach Anzahl an Downloads insgesamt)
|
||||||
const topEditorials = await db
|
db
|
||||||
.select({
|
.select({
|
||||||
editorialId: usages.editorialAccountId,
|
editorialId: usages.editorialAccountId,
|
||||||
name: editorialAccounts.name,
|
name: editorialAccounts.name,
|
||||||
@@ -36,10 +40,10 @@ export default async function AdminDashboardPage() {
|
|||||||
.innerJoin(editorialAccounts, eq(usages.editorialAccountId, editorialAccounts.id))
|
.innerJoin(editorialAccounts, eq(usages.editorialAccountId, editorialAccounts.id))
|
||||||
.groupBy(usages.editorialAccountId, editorialAccounts.name)
|
.groupBy(usages.editorialAccountId, editorialAccounts.name)
|
||||||
.orderBy(desc(sql`COUNT(${usages.id})`))
|
.orderBy(desc(sql`COUNT(${usages.id})`))
|
||||||
.limit(5);
|
.limit(5),
|
||||||
|
|
||||||
// 3. Beliebteste Alben
|
// 3. Beliebteste Alben
|
||||||
const topAlbums = await db
|
db
|
||||||
.select({
|
.select({
|
||||||
albumName: usages.albumNameSnapshot,
|
albumName: usages.albumNameSnapshot,
|
||||||
downloadCount: sql<number>`COUNT(${usages.id})::int`,
|
downloadCount: sql<number>`COUNT(${usages.id})::int`,
|
||||||
@@ -47,13 +51,10 @@ export default async function AdminDashboardPage() {
|
|||||||
.from(usages)
|
.from(usages)
|
||||||
.groupBy(usages.albumNameSnapshot)
|
.groupBy(usages.albumNameSnapshot)
|
||||||
.orderBy(desc(sql`COUNT(${usages.id})`))
|
.orderBy(desc(sql`COUNT(${usages.id})`))
|
||||||
.limit(5);
|
.limit(5),
|
||||||
|
|
||||||
// 4. Time-series data for the last 30 days
|
// 4. Time-series data for the last 30 days
|
||||||
const thirtyDaysAgo = new Date();
|
db
|
||||||
thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
|
|
||||||
|
|
||||||
const dailyDownloads = await db
|
|
||||||
.select({
|
.select({
|
||||||
date: sql<string>`DATE_TRUNC('day', ${usages.createdAt})::date::text`,
|
date: sql<string>`DATE_TRUNC('day', ${usages.createdAt})::date::text`,
|
||||||
downloads: sql<number>`COUNT(${usages.id})::int`,
|
downloads: sql<number>`COUNT(${usages.id})::int`,
|
||||||
@@ -61,7 +62,10 @@ export default async function AdminDashboardPage() {
|
|||||||
.from(usages)
|
.from(usages)
|
||||||
.where(gte(usages.createdAt, thirtyDaysAgo))
|
.where(gte(usages.createdAt, thirtyDaysAgo))
|
||||||
.groupBy(sql`DATE_TRUNC('day', ${usages.createdAt})`)
|
.groupBy(sql`DATE_TRUNC('day', ${usages.createdAt})`)
|
||||||
.orderBy(sql`DATE_TRUNC('day', ${usages.createdAt})`);
|
.orderBy(sql`DATE_TRUNC('day', ${usages.createdAt})`)
|
||||||
|
]);
|
||||||
|
|
||||||
|
const revenueStats = revenueStatsResult[0];
|
||||||
|
|
||||||
// Fill in missing days
|
// Fill in missing days
|
||||||
const chartData = [];
|
const chartData = [];
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ export default async function AutoRulesPage({ params }: AutoRulesPageProps) {
|
|||||||
<li key={rule.id} className="auto-rule-item">
|
<li key={rule.id} className="auto-rule-item">
|
||||||
<span className="auto-rule-keyword">{rule.keyword}</span>
|
<span className="auto-rule-keyword">{rule.keyword}</span>
|
||||||
<span className="auto-rule-date">
|
<span className="auto-rule-date">
|
||||||
{rule.createdAt.toLocaleDateString('de-DE')}
|
{new Date(rule.createdAt).toLocaleDateString('de-DE')}
|
||||||
</span>
|
</span>
|
||||||
<form action={deleteAutoRuleAction.bind(null, editorial.id, rule.id)}>
|
<form action={deleteAutoRuleAction.bind(null, editorial.id, rule.id)}>
|
||||||
<button type="submit" className="auto-rule-delete">Entfernen</button>
|
<button type="submit" className="auto-rule-delete">Entfernen</button>
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ export default async function EditorialsPage() {
|
|||||||
<div className="space-y-1 text-sm text-muted-foreground">
|
<div className="space-y-1 text-sm text-muted-foreground">
|
||||||
<p>{editorial.contactName} · {editorial.loginEmail}</p>
|
<p>{editorial.contactName} · {editorial.loginEmail}</p>
|
||||||
<p className="pt-2">
|
<p className="pt-2">
|
||||||
Archiviert am: {editorial.archivedAt?.toLocaleDateString("de-DE")}
|
Archiviert am: {editorial.archivedAt ? new Date(editorial.archivedAt).toLocaleDateString("de-DE") : ""}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
|
|||||||
@@ -47,9 +47,9 @@ export function createThumbnailHandler(dependencies: ThumbnailHandlerDependencie
|
|||||||
|
|
||||||
const thumbnail = await dependencies.immich.getThumbnail(assetId);
|
const thumbnail = await dependencies.immich.getThumbnail(assetId);
|
||||||
if (access.kind === "editorial") {
|
if (access.kind === "editorial") {
|
||||||
return watermarkedThumbnailResponse(thumbnail);
|
return watermarkedThumbnailResponse(thumbnail, assetId);
|
||||||
}
|
}
|
||||||
return thumbnailResponse(thumbnail);
|
return thumbnailResponse(thumbnail, assetId);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return genericNotFound();
|
return genericNotFound();
|
||||||
}
|
}
|
||||||
@@ -101,11 +101,12 @@ async function isAdminAlbumCover(
|
|||||||
return album.albumThumbnailAssetId === assetId;
|
return album.albumThumbnailAssetId === assetId;
|
||||||
}
|
}
|
||||||
|
|
||||||
function thumbnailResponse(thumbnail: ImmichBinary): Response {
|
function thumbnailResponse(thumbnail: ImmichBinary, assetId: string): Response {
|
||||||
const responseHeaders = new Headers({
|
const responseHeaders = new Headers({
|
||||||
"cache-control": "private, no-store",
|
"cache-control": "private, max-age=86400, stale-while-revalidate=604800",
|
||||||
"content-type": thumbnail.contentType,
|
"content-type": thumbnail.contentType,
|
||||||
"x-content-type-options": "nosniff",
|
"x-content-type-options": "nosniff",
|
||||||
|
"etag": `"${assetId}"`,
|
||||||
});
|
});
|
||||||
if (thumbnail.contentLength !== null) {
|
if (thumbnail.contentLength !== null) {
|
||||||
responseHeaders.set("content-length", String(thumbnail.contentLength));
|
responseHeaders.set("content-length", String(thumbnail.contentLength));
|
||||||
@@ -117,7 +118,7 @@ function genericNotFound(): Response {
|
|||||||
return new Response(null, { status: 404 });
|
return new Response(null, { status: 404 });
|
||||||
}
|
}
|
||||||
|
|
||||||
async function watermarkedThumbnailResponse(thumbnail: ImmichBinary): Promise<Response> {
|
async function watermarkedThumbnailResponse(thumbnail: ImmichBinary, assetId: string): Promise<Response> {
|
||||||
const reader = thumbnail.body.getReader();
|
const reader = thumbnail.body.getReader();
|
||||||
const chunks: Uint8Array[] = [];
|
const chunks: Uint8Array[] = [];
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -150,10 +151,11 @@ async function watermarkedThumbnailResponse(thumbnail: ImmichBinary): Promise<Re
|
|||||||
.toBuffer();
|
.toBuffer();
|
||||||
|
|
||||||
const responseHeaders = new Headers({
|
const responseHeaders = new Headers({
|
||||||
"cache-control": "private, no-store",
|
"cache-control": "private, max-age=86400, stale-while-revalidate=604800",
|
||||||
"content-type": "image/webp",
|
"content-type": "image/webp",
|
||||||
"content-length": String(watermarked.length),
|
"content-length": String(watermarked.length),
|
||||||
"x-content-type-options": "nosniff",
|
"x-content-type-options": "nosniff",
|
||||||
|
"etag": `"${assetId}-watermark"`,
|
||||||
});
|
});
|
||||||
|
|
||||||
return new Response(watermarked, { headers: responseHeaders });
|
return new Response(watermarked, { headers: responseHeaders });
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ export function createGetReportHandler(dependencies: GetHandlerDependencies) {
|
|||||||
const report = await dependencies.getReportPdf(reportId);
|
const report = await dependencies.getReportPdf(reportId);
|
||||||
if (!report) return notFound();
|
if (!report) return notFound();
|
||||||
|
|
||||||
const filename = buildFilename(report.invoiceNumber);
|
const filename = buildFilename(report.invoiceNumber, reportId);
|
||||||
return new Response(new Uint8Array(report.bytes), {
|
return new Response(new Uint8Array(report.bytes), {
|
||||||
status: 200,
|
status: 200,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -38,7 +38,10 @@ export function createGetReportHandler(dependencies: GetHandlerDependencies) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildFilename(invoiceNumber: string): string {
|
function buildFilename(invoiceNumber: string | null, reportId: string): string {
|
||||||
|
if (!invoiceNumber) {
|
||||||
|
return `entwurf-${reportId}.pdf`;
|
||||||
|
}
|
||||||
const safe = invoiceNumber.replace(/[^A-Za-z0-9_-]/g, "_");
|
const safe = invoiceNumber.replace(/[^A-Za-z0-9_-]/g, "_");
|
||||||
return `${safe || "nutzungsnachweis"}.pdf`;
|
return `${safe || "nutzungsnachweis"}.pdf`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export async function GET(
|
|||||||
const reportPdf = await getReportPdf(reportId);
|
const reportPdf = await getReportPdf(reportId);
|
||||||
if (!reportPdf) return notFound();
|
if (!reportPdf) return notFound();
|
||||||
|
|
||||||
const filename = buildFilename(reportPdf.invoiceNumber);
|
const filename = buildFilename(reportPdf.invoiceNumber, reportId);
|
||||||
return new Response(new Uint8Array(reportPdf.bytes), {
|
return new Response(new Uint8Array(reportPdf.bytes), {
|
||||||
status: 200,
|
status: 200,
|
||||||
headers: {
|
headers: {
|
||||||
@@ -43,7 +43,10 @@ export async function GET(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildFilename(invoiceNumber: string): string {
|
function buildFilename(invoiceNumber: string | null, reportId: string): string {
|
||||||
|
if (!invoiceNumber) {
|
||||||
|
return `entwurf-${reportId}.pdf`;
|
||||||
|
}
|
||||||
const safe = invoiceNumber.replace(/[^A-Za-z0-9_-]/g, "_");
|
const safe = invoiceNumber.replace(/[^A-Za-z0-9_-]/g, "_");
|
||||||
return `${safe || "nutzungsnachweis"}.pdf`;
|
return `${safe || "nutzungsnachweis"}.pdf`;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import { usageService } from "@/modules/usages/service";
|
|||||||
import { immichClient } from "@/modules/immich/client";
|
import { immichClient } from "@/modules/immich/client";
|
||||||
import { downloadDeliveryRepository } from "@/modules/downloads/stream";
|
import { downloadDeliveryRepository } from "@/modules/downloads/stream";
|
||||||
import { albumGrantService } from "@/modules/albums/grants";
|
import { albumGrantService } from "@/modules/albums/grants";
|
||||||
const archiver = require("archiver");
|
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-explicit-any
|
||||||
|
const archiver: any = require("archiver");
|
||||||
|
import * as crypto from "crypto";
|
||||||
import { Readable } from "stream";
|
import { Readable } from "stream";
|
||||||
|
|
||||||
export async function POST(request: NextRequest) {
|
export async function POST(request: NextRequest) {
|
||||||
@@ -12,49 +14,73 @@ export async function POST(request: NextRequest) {
|
|||||||
const principal = await requireActiveEditorial(request.headers);
|
const principal = await requireActiveEditorial(request.headers);
|
||||||
const { assetIds, purpose } = await request.json();
|
const { assetIds, purpose } = await request.json();
|
||||||
|
|
||||||
if (!Array.isArray(assetIds) || assetIds.length === 0 || !purpose) {
|
if (!Array.isArray(assetIds) || assetIds.length === 0 || assetIds.length > 100) {
|
||||||
return new Response("Invalid request", { status: 400 });
|
return new Response("Invalid request: assetIds must be an array of 1 to 100 items", { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
||||||
|
for (const assetId of assetIds) {
|
||||||
|
if (typeof assetId !== "string" || !uuidRegex.test(assetId)) {
|
||||||
|
return new Response(`Invalid request: assetId ${assetId} is not a valid UUID format`, { status: 400 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof purpose !== "string" || purpose.trim().length === 0 || purpose.trim().length > 500) {
|
||||||
|
return new Response("Invalid request: purpose must be a non-empty string up to 500 characters", { status: 400 });
|
||||||
|
}
|
||||||
|
const trimmedPurpose = purpose.trim();
|
||||||
|
|
||||||
const grantedAlbumIds = await albumGrantService.getGrantedAlbumIds(principal.editorialId);
|
const grantedAlbumIds = await albumGrantService.getGrantedAlbumIds(principal.editorialId);
|
||||||
const grantedSet = new Set(grantedAlbumIds);
|
const grantedSet = new Set(grantedAlbumIds);
|
||||||
|
|
||||||
const downloadsToProcess: { assetId: string, downloadId: string, filename: string, intentKind: "new_usage" | "repeat" }[] = [];
|
const downloadsToProcess: { assetId: string, downloadId: string, filename: string, intentKind: "new_usage" | "repeat" }[] = [];
|
||||||
|
|
||||||
for (const assetId of assetIds) {
|
// 1. Fetch assets and validate in parallel
|
||||||
// 1. Fetch asset to find its albums
|
const assetResults = await Promise.all(
|
||||||
let asset;
|
assetIds.map(async (assetId) => {
|
||||||
try {
|
try {
|
||||||
asset = await immichClient.getAsset(assetId);
|
const asset = await immichClient.getAsset(assetId);
|
||||||
|
return { assetId, asset };
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Asset fetch failed", assetId, err);
|
console.error("Asset fetch failed", assetId, err);
|
||||||
continue; // Skip unavailable assets
|
return { assetId, asset: null };
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
// 2. Find the first album the editorial has access to
|
// 2. Process usages serially to avoid idempotency race conditions
|
||||||
const validAlbum = asset.albums.find(a => grantedSet.has(a.id));
|
for (const { assetId, asset } of assetResults) {
|
||||||
|
if (!asset) continue;
|
||||||
|
|
||||||
|
// Find the first album the editorial has access to
|
||||||
|
const validAlbum = asset.albums.find((a: any) => grantedSet.has(a.id));
|
||||||
if (!validAlbum) continue; // Editorial does not have access
|
if (!validAlbum) continue; // Editorial does not have access
|
||||||
|
|
||||||
// 3. Check for prior usages to avoid double charging
|
// Check for prior usages to avoid double charging
|
||||||
const priorUsages = await usageService.listPriorUsages(principal.editorialId, assetId);
|
const priorUsages = await usageService.listPriorUsages(principal.editorialId, assetId);
|
||||||
const isRepeat = priorUsages.length > 0;
|
const isRepeat = priorUsages.length > 0;
|
||||||
|
|
||||||
// 4. Create new usage (or repeat download if prior usages exist)
|
let downloadId: string;
|
||||||
// Since createNewUsage handles idempotent repeats automatically, we just need to pass an idempotency key.
|
if (isRepeat) {
|
||||||
const idempotencyKey = `${principal.editorialId}-${assetId}-${purpose}`;
|
// Skip usage creation for repeat downloads
|
||||||
|
downloadId = priorUsages[0].id;
|
||||||
|
} else {
|
||||||
|
const idempotencyKey = crypto.randomUUID();
|
||||||
|
|
||||||
const newUsage = await usageService.createNewUsage({
|
const newUsage = await usageService.createNewUsage({
|
||||||
editorialId: principal.editorialId,
|
editorialId: principal.editorialId,
|
||||||
assetId,
|
assetId,
|
||||||
albumId: validAlbum.id,
|
albumId: validAlbum.id,
|
||||||
purpose,
|
purpose: trimmedPurpose,
|
||||||
reference: undefined,
|
reference: undefined,
|
||||||
idempotencyKey,
|
idempotencyKey,
|
||||||
});
|
});
|
||||||
|
downloadId = newUsage.id;
|
||||||
|
}
|
||||||
|
|
||||||
downloadsToProcess.push({
|
downloadsToProcess.push({
|
||||||
assetId,
|
assetId,
|
||||||
downloadId: newUsage.id,
|
downloadId,
|
||||||
filename: asset.originalFileName,
|
filename: asset.originalFileName,
|
||||||
intentKind: isRepeat ? "repeat" : "new_usage",
|
intentKind: isRepeat ? "repeat" : "new_usage",
|
||||||
});
|
});
|
||||||
@@ -76,6 +102,7 @@ export async function POST(request: NextRequest) {
|
|||||||
|
|
||||||
// Start appending files asynchronously
|
// Start appending files asynchronously
|
||||||
(async () => {
|
(async () => {
|
||||||
|
try {
|
||||||
for (const download of downloadsToProcess) {
|
for (const download of downloadsToProcess) {
|
||||||
// Claim the download to verify it's authorized
|
// Claim the download to verify it's authorized
|
||||||
const claim = await downloadDeliveryRepository.claimAuthorized(principal.editorialId, download.downloadId);
|
const claim = await downloadDeliveryRepository.claimAuthorized(principal.editorialId, download.downloadId);
|
||||||
@@ -107,7 +134,12 @@ export async function POST(request: NextRequest) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error("Archive stream failed", err);
|
||||||
|
archive.abort();
|
||||||
|
} finally {
|
||||||
archive.finalize();
|
archive.finalize();
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
|
|
||||||
const date = new Date().toISOString().split('T')[0];
|
const date = new Date().toISOString().split('T')[0];
|
||||||
|
|||||||
@@ -441,10 +441,15 @@ a {
|
|||||||
display: block;
|
display: block;
|
||||||
width: min(10rem, 35vw);
|
width: min(10rem, 35vw);
|
||||||
height: auto;
|
height: auto;
|
||||||
|
max-height: 2.5rem;
|
||||||
object-fit: contain;
|
object-fit: contain;
|
||||||
transition: opacity 0.2s ease;
|
transition: opacity 0.2s ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.brand-logo-dark { display: none; }
|
||||||
|
.dark .brand-logo-light { display: none; }
|
||||||
|
.dark .brand-logo-dark { display: block; }
|
||||||
|
|
||||||
.brand-logo:hover {
|
.brand-logo:hover {
|
||||||
opacity: 0.8;
|
opacity: 0.8;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ export default async function AbrechnungenPage() {
|
|||||||
<tr key={report.id} className={i !== reports.length - 1 ? "border-b border-border hover:bg-muted/30 transition-colors" : "hover:bg-muted/30 transition-colors"}>
|
<tr key={report.id} className={i !== reports.length - 1 ? "border-b border-border hover:bg-muted/30 transition-colors" : "hover:bg-muted/30 transition-colors"}>
|
||||||
<td className="py-4 px-4 font-medium">{report.invoiceNumber}</td>
|
<td className="py-4 px-4 font-medium">{report.invoiceNumber}</td>
|
||||||
<td className="py-4 px-4 text-muted-foreground">
|
<td className="py-4 px-4 text-muted-foreground">
|
||||||
{new Intl.DateTimeFormat("de-DE", { month: "long", year: "numeric" }).format(report.periodStartsAt)}
|
{new Intl.DateTimeFormat("de-DE", { month: "long", year: "numeric" }).format(new Date(report.periodStartsAt))}
|
||||||
</td>
|
</td>
|
||||||
<td className="py-4 px-4 font-medium text-right tabular-nums">
|
<td className="py-4 px-4 font-medium text-right tabular-nums">
|
||||||
{new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }).format(report.netTotalCents / 100)}
|
{new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }).format(report.netTotalCents / 100)}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export async function toggleLightboxItem(assetId: string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Revalidate routes where lightbox state is shown
|
// Revalidate routes where lightbox state is shown
|
||||||
revalidatePath("/redaktion/alben/[id]", "page");
|
revalidatePath("/redaktion/alben/[albumId]", "page");
|
||||||
revalidatePath("/redaktion/leuchtkasten", "page");
|
revalidatePath("/redaktion/leuchtkasten", "page");
|
||||||
|
|
||||||
return { success: true, isNowInLightbox: !isInLightbox };
|
return { success: true, isNowInLightbox: !isInLightbox };
|
||||||
@@ -26,6 +26,6 @@ export async function removeLightboxItemAction(assetId: string) {
|
|||||||
const principal = await requireActiveEditorial(new Headers(await headers()));
|
const principal = await requireActiveEditorial(new Headers(await headers()));
|
||||||
await lightboxService.removeLightboxItem(principal.editorialId, assetId);
|
await lightboxService.removeLightboxItem(principal.editorialId, assetId);
|
||||||
revalidatePath("/redaktion/leuchtkasten", "page");
|
revalidatePath("/redaktion/leuchtkasten", "page");
|
||||||
revalidatePath("/redaktion/alben/[id]", "page");
|
revalidatePath("/redaktion/alben/[albumId]", "page");
|
||||||
return { success: true };
|
return { success: true };
|
||||||
}
|
}
|
||||||
@@ -42,10 +42,14 @@ export default async function LightboxPage() {
|
|||||||
{items.map((item) => {
|
{items.map((item) => {
|
||||||
const asset = assetMap.get(item.assetId);
|
const asset = assetMap.get(item.assetId);
|
||||||
if (!asset) return null;
|
if (!asset) return null;
|
||||||
|
const albumId = asset.albums?.[0]?.id;
|
||||||
|
const href = albumId
|
||||||
|
? `/redaktion/alben/${encodeURIComponent(albumId)}?suche=${encodeURIComponent(asset.originalFileName)}`
|
||||||
|
: '#';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<li key={item.assetId} className="relative group rounded-xl overflow-hidden border border-border bg-card shadow-sm transition-all hover:shadow-md hover:-translate-y-1">
|
<li key={item.assetId} className="relative group rounded-xl overflow-hidden border border-border bg-card shadow-sm transition-all hover:shadow-md hover:-translate-y-1">
|
||||||
<Link href={`/redaktion/nutzungen/neu?assetId=${item.assetId}`} className="block">
|
<Link href={href} className="block">
|
||||||
<div className="aspect-[3/2] w-full overflow-hidden bg-muted">
|
<div className="aspect-[3/2] w-full overflow-hidden bg-muted">
|
||||||
<Image
|
<Image
|
||||||
alt={asset.originalFileName ?? "Bild"}
|
alt={asset.originalFileName ?? "Bild"}
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ function AttemptRow({ attempt }: Readonly<{ attempt: UsageHistoryAttempt }>) {
|
|||||||
const displayedAt = attempt.finishedAt ?? attempt.requestedAt;
|
const displayedAt = attempt.finishedAt ?? attempt.requestedAt;
|
||||||
return (
|
return (
|
||||||
<li>
|
<li>
|
||||||
<time dateTime={displayedAt.toISOString()}>
|
<time dateTime={new Date(displayedAt).toISOString()}>
|
||||||
{formatBerlinDateTime(displayedAt)}
|
{formatBerlinDateTime(displayedAt)}
|
||||||
</time>
|
</time>
|
||||||
<span className="usage-attempt-context">
|
<span className="usage-attempt-context">
|
||||||
|
|||||||
@@ -8,11 +8,21 @@ import { expect, test } from "vitest";
|
|||||||
import { PortalShell } from "@/components/layout/portal-shell";
|
import { PortalShell } from "@/components/layout/portal-shell";
|
||||||
import { BrandLogo } from "./logo";
|
import { BrandLogo } from "./logo";
|
||||||
|
|
||||||
test("uses the supplied logo's true intrinsic dimensions", () => {
|
test("uses the supplied logo's true intrinsic dimensions and renders both light and dark variants", () => {
|
||||||
render(<BrandLogo />);
|
render(<BrandLogo />);
|
||||||
const logo = screen.getByAltText("Leon Tonhäuser Sportfotografie");
|
const logos = screen.getAllByAltText("Leon Tonhäuser Sportfotografie");
|
||||||
expect(logo.getAttribute("width")).toBe("1000");
|
|
||||||
expect(logo.getAttribute("height")).toBe("1000");
|
expect(logos).toHaveLength(2);
|
||||||
|
|
||||||
|
// Light mode logo
|
||||||
|
expect(logos[0].getAttribute("width")).toBe("1000");
|
||||||
|
expect(logos[0].getAttribute("height")).toBe("1000");
|
||||||
|
expect(logos[0].className).toContain("brand-logo-light");
|
||||||
|
|
||||||
|
// Dark mode logo
|
||||||
|
expect(logos[1].getAttribute("width")).toBe("1000");
|
||||||
|
expect(logos[1].getAttribute("height")).toBe("1000");
|
||||||
|
expect(logos[1].className).toContain("brand-logo-dark");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("keeps masthead controls keyboard-focusable with a paper-coloured focus outline", () => {
|
test("keeps masthead controls keyboard-focusable with a paper-coloured focus outline", () => {
|
||||||
|
|||||||
@@ -2,12 +2,21 @@
|
|||||||
|
|
||||||
export function BrandLogo() {
|
export function BrandLogo() {
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<img
|
<img
|
||||||
alt="Leon Tonhäuser Sportfotografie"
|
alt="Leon Tonhäuser Sportfotografie"
|
||||||
className="brand-logo"
|
className="brand-logo brand-logo-light"
|
||||||
height={250}
|
height={1000}
|
||||||
src="/brand/logo-black.png"
|
src="/brand/logo-black.png"
|
||||||
width={250}
|
width={1000}
|
||||||
/>
|
/>
|
||||||
|
<img
|
||||||
|
alt="Leon Tonhäuser Sportfotografie"
|
||||||
|
className="brand-logo brand-logo-dark"
|
||||||
|
height={1000}
|
||||||
|
src="/brand/logo-white.png"
|
||||||
|
width={1000}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -55,6 +55,7 @@ export const usages = pgTable(
|
|||||||
table.createdAt.desc(),
|
table.createdAt.desc(),
|
||||||
table.id.desc(),
|
table.id.desc(),
|
||||||
),
|
),
|
||||||
|
index("usages_created_at_idx").on(table.createdAt),
|
||||||
check(
|
check(
|
||||||
"usages_canonical_immich_asset_id_check",
|
"usages_canonical_immich_asset_id_check",
|
||||||
sql`${table.immichAssetId} ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'`,
|
sql`${table.immichAssetId} ~ '^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'`,
|
||||||
|
|||||||
@@ -96,13 +96,13 @@ export function PhotoContactSheet({
|
|||||||
<figcaption className="contact-strip">
|
<figcaption className="contact-strip">
|
||||||
<span className="contact-strip-name">{asset.originalFileName}</span>
|
<span className="contact-strip-name">{asset.originalFileName}</span>
|
||||||
{showAlbumName && (asset as any).albums && (asset as any).albums.length > 0 && (
|
{showAlbumName && (asset as any).albums && (asset as any).albums.length > 0 && (
|
||||||
<span className="contact-strip-album">{(asset as any).albums[0].id}</span>
|
<span className="contact-strip-album">{(asset as any).albums[0].albumName}</span>
|
||||||
)}
|
)}
|
||||||
<span>{formatDate(asset.localDateTime ?? asset.fileCreatedAt)}</span>
|
<span>{formatDate(asset.localDateTime ?? asset.fileCreatedAt)}</span>
|
||||||
</figcaption>
|
</figcaption>
|
||||||
{albumId && downloadOptions ? (
|
{(albumId ?? asset.albums?.[0]?.id) && downloadOptions ? (
|
||||||
<UsageDialog
|
<UsageDialog
|
||||||
albumId={albumId}
|
albumId={albumId ?? (asset.albums?.[0]?.id as string)}
|
||||||
assetId={asset.id}
|
assetId={asset.id}
|
||||||
filename={asset.originalFileName}
|
filename={asset.originalFileName}
|
||||||
newUsagePriceCents={downloadOptions.priceCents}
|
newUsagePriceCents={downloadOptions.priceCents}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export function EditorialDetailContent({
|
|||||||
|
|
||||||
{editorial.archivedAt && (
|
{editorial.archivedAt && (
|
||||||
<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">
|
||||||
Diese Redaktion wurde am {editorial.archivedAt.toLocaleDateString('de-DE')} archiviert.
|
Diese Redaktion wurde am {new Date(editorial.archivedAt).toLocaleDateString('de-DE')} archiviert.
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -89,16 +89,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 getValidatedAsset(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 getValidatedAsset(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),
|
||||||
@@ -330,31 +330,21 @@ function normalizeNewUsageInput(input: CreateNewUsageInput): CreateNewUsageInput
|
|||||||
|
|
||||||
async function loadRequestedAlbum(
|
async function loadRequestedAlbum(
|
||||||
immich: UsageImmich,
|
immich: UsageImmich,
|
||||||
assetId: string,
|
asset: { albums: Array<{ id: string }> },
|
||||||
albumId: string,
|
albumId: string,
|
||||||
): Promise<{ id: string; albumName: string }> {
|
): Promise<{ id: string; albumName: string }> {
|
||||||
let asset;
|
|
||||||
try {
|
|
||||||
asset = await immich.getAsset(assetId);
|
|
||||||
} catch {
|
|
||||||
throw new UsageAccountingError("IMMICH_UNAVAILABLE");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!asset.albums.some((a) => a.id === albumId)) {
|
if (!asset.albums.some((a) => a.id === albumId)) {
|
||||||
throw new UsageAccountingError("ASSET_NOT_IN_ALBUM");
|
throw new UsageAccountingError("ASSET_NOT_IN_ALBUM");
|
||||||
}
|
}
|
||||||
|
|
||||||
let album;
|
|
||||||
try {
|
try {
|
||||||
album = await immich.getAlbum(albumId);
|
return await immich.getAlbum(albumId);
|
||||||
} catch {
|
} catch {
|
||||||
throw new UsageAccountingError("IMMICH_UNAVAILABLE");
|
throw new UsageAccountingError("IMMICH_UNAVAILABLE");
|
||||||
}
|
}
|
||||||
|
|
||||||
return album;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadImageAsset(immich: UsageImmich, assetId: string) {
|
async function getValidatedAsset(immich: UsageImmich, assetId: string) {
|
||||||
let asset: Awaited<ReturnType<UsageImmich["getAsset"]>>;
|
let asset: Awaited<ReturnType<UsageImmich["getAsset"]>>;
|
||||||
try {
|
try {
|
||||||
asset = await immich.getAsset(assetId);
|
asset = await immich.getAsset(assetId);
|
||||||
|
|||||||
Reference in new issue
Block a user