feat: stream originals with download accounting
This commit is contained in:
1 parent
c400167b8f
commit
8871e4794a
28 files changed
+4081
-8
No files matched your search
@@ -0,0 +1,120 @@
|
||||
import Link from "next/link";
|
||||
|
||||
import type { UsageHistoryAttempt, UsageHistoryPage } from "@/modules/downloads/stream";
|
||||
|
||||
const dateTimeFormatter = new Intl.DateTimeFormat("de-DE", {
|
||||
dateStyle: "medium",
|
||||
timeStyle: "short",
|
||||
});
|
||||
const priceFormatter = new Intl.NumberFormat("de-DE", {
|
||||
style: "currency",
|
||||
currency: "EUR",
|
||||
});
|
||||
const byteFormatter = new Intl.NumberFormat("de-DE", {
|
||||
style: "unit",
|
||||
unit: "byte",
|
||||
unitDisplay: "short",
|
||||
maximumFractionDigits: 0,
|
||||
});
|
||||
|
||||
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>
|
||||
|
||||
{history.items.length === 0 ? (
|
||||
<div className="usage-history-empty">
|
||||
<p>Noch keine Nutzungen erfasst. Wählen Sie ein Foto aus einem freigegebenen Album.</p>
|
||||
<Link className="quiet-link" href="/redaktion/alben">
|
||||
Zu den Alben
|
||||
</Link>
|
||||
</div>
|
||||
) : (
|
||||
<ol className="usage-ledger">
|
||||
{history.items.map((usage) => (
|
||||
<li key={usage.usageId}>
|
||||
<article className="usage-ledger-entry">
|
||||
<header>
|
||||
<p>{formatDateTime(usage.createdAt)}</p>
|
||||
<h2>{usage.filename}</h2>
|
||||
</header>
|
||||
<dl className="usage-snapshot">
|
||||
<div>
|
||||
<dt>Album</dt>
|
||||
<dd>{usage.albumName}</dd>
|
||||
</div>
|
||||
<div>
|
||||
<dt>Verwendungszweck</dt>
|
||||
<dd>{usage.purpose}</dd>
|
||||
</div>
|
||||
{usage.reference ? (
|
||||
<div>
|
||||
<dt>Interne Referenz</dt>
|
||||
<dd>{usage.reference}</dd>
|
||||
</div>
|
||||
) : null}
|
||||
</dl>
|
||||
{usage.attempts.length === 0 ? (
|
||||
<p className="usage-attempt-empty">Noch kein abgeschlossener Auslieferungsversuch.</p>
|
||||
) : (
|
||||
<ol className="usage-attempts" aria-label={`Auslieferungen für ${usage.filename}`}>
|
||||
{usage.attempts.map((attempt) => (
|
||||
<AttemptRow attempt={attempt} key={attempt.downloadId} />
|
||||
))}
|
||||
</ol>
|
||||
)}
|
||||
</article>
|
||||
</li>
|
||||
))}
|
||||
</ol>
|
||||
)}
|
||||
|
||||
<HistoryPagination history={history} />
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
function AttemptRow({ attempt }: Readonly<{ attempt: UsageHistoryAttempt }>) {
|
||||
return (
|
||||
<li>
|
||||
<time dateTime={attempt.finishedAt.toISOString()}>{formatDateTime(attempt.finishedAt)}</time>
|
||||
<strong>{statusLabel(attempt.status)}</strong>
|
||||
<span>{attempt.repeat ? "Wiederholter Abruf" : "Neue Nutzung"}</span>
|
||||
<span>{byteFormatter.format(attempt.transferredBytes)}</span>
|
||||
<b>{priceFormatter.format(attempt.billableCents / 100)}</b>
|
||||
</li>
|
||||
);
|
||||
}
|
||||
|
||||
function HistoryPagination({ history }: Readonly<{ history: UsageHistoryPage }>) {
|
||||
if (history.page === 1 && !history.hasNext) return null;
|
||||
return (
|
||||
<nav aria-label="Seiten der Nutzungshistorie" className="photo-pagination">
|
||||
{history.page > 1 ? (
|
||||
<Link href={`/redaktion/nutzungen?page=${history.page - 1}`}>Vorherige Seite</Link>
|
||||
) : (
|
||||
<span />
|
||||
)}
|
||||
{history.hasNext ? (
|
||||
<Link href={`/redaktion/nutzungen?page=${history.page + 1}`}>Nächste Seite</Link>
|
||||
) : null}
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
function statusLabel(status: UsageHistoryAttempt["status"]): string {
|
||||
const labels: Record<UsageHistoryAttempt["status"], string> = {
|
||||
completed: "Abgeschlossen",
|
||||
interrupted: "Unterbrochen",
|
||||
failed_before_delivery: "Vor Auslieferung fehlgeschlagen",
|
||||
};
|
||||
return labels[status];
|
||||
}
|
||||
|
||||
function formatDateTime(value: Date): string {
|
||||
return dateTimeFormatter.format(value);
|
||||
}
|
||||
Reference in new issue
Block a user