Milestone (c): worker and downloads with live progress

- Worker queue with per-model exclusivity and MAX_CONCURRENT_DOWNLOADS,
  spawns `hf download --revision <sha> --local-dir ... --include <exact paths>`
  with HF_TOKEN via env only
- Progress from bytes on disk (final + .incomplete files matched by etag),
  per job and per file, with speed and ETA; post-download size/etag check
- Job logs (sanitized), cancel, graceful interrupt on shutdown,
  partial-file cleanup (hf 2.1.1 does not resume partials)
- Single-worker DB lease, free-space check
- SSE live updates for library, model and job pages
- Dockerfile + compose.yaml (web, worker, data/models volumes)
- HF_HUB_DISABLE_XET default on for measurable progress

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pascal LinxweilerandClaude Opus 5.5 committed 2026-10-05 16:57:12 +02:00
1 parent 8f7ac60ccf
commit 49440154a2
42 files changed
+2974 -110

No files matched your search

+19
View File
@@ -0,0 +1,19 @@
"use client";
import { toast } from "sonner";
async function post(url: string): Promise<boolean> {
const res = await fetch(url, { method: "POST" });
if (res.ok) return true;
const body = await res.json().catch(() => ({}));
toast.error(body.error?.message ?? `Request failed (${res.status})`);
return false;
}
export async function startDownload(modelId: string) {
if (await post(`/api/models/${modelId}/download`)) toast.success("Download queued");
}
export async function cancelJob(jobId: string) {
if (await post(`/api/jobs/${jobId}/cancel`)) toast.info("Cancelling…");
}
+41
View File
@@ -0,0 +1,41 @@
import { Progress } from "@/components/ui/progress";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import { formatBytes, percent } from "@/lib/format";
import type { JobFileSnapshot } from "@/lib/jobs";
/** Per-file progress of one job. */
export function JobFilesTable({ files }: { files: JobFileSnapshot[] }) {
return (
<Table>
<TableHeader>
<TableRow>
<TableHead>File</TableHead>
<TableHead className="w-40 sm:w-56">Progress</TableHead>
<TableHead className="text-right">Size</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{files.map((f) => {
const pct = percent(f.doneBytes, f.expectedBytes);
return (
<TableRow key={f.modelFileId}>
<TableCell className="font-mono text-xs break-all whitespace-normal">{f.path}</TableCell>
<TableCell>
<div className="flex items-center gap-2">
<Progress value={pct} className="flex-1" />
<span className="w-12 text-right text-xs text-muted-foreground tabular-nums">
{f.state === "failed" ? "missing" : `${pct.toFixed(0)}%`}
</span>
</div>
</TableCell>
<TableCell className="text-right text-xs tabular-nums">
{f.doneBytes < f.expectedBytes && f.doneBytes > 0 ? `${formatBytes(f.doneBytes)} / ` : ""}
{formatBytes(f.expectedBytes)}
</TableCell>
</TableRow>
);
})}
</TableBody>
</Table>
);
}
+42
View File
@@ -0,0 +1,42 @@
import { Badge } from "@/components/ui/badge";
import { Progress } from "@/components/ui/progress";
import { formatBytes, formatDuration, formatSpeed, percent } from "@/lib/format";
import type { JobSnapshot } from "@/lib/jobs";
const STATE_VARIANT: Record<string, "default" | "secondary" | "destructive" | "outline"> = {
queued: "outline",
downloading: "secondary",
verifying: "secondary",
completed: "default",
failed: "destructive",
cancelled: "outline",
interrupted: "destructive",
};
export function JobStateBadge({ job }: { job: Pick<JobSnapshot, "state" | "cancelRequested"> }) {
const label = job.cancelRequested && !["cancelled", "completed", "failed"].includes(job.state) ? "cancelling" : job.state;
return <Badge variant={STATE_VARIANT[job.state] ?? "outline"}>{label}</Badge>;
}
/** Overall progress line for a job: bar, bytes, %, speed, ETA. */
export function JobProgress({ job, compact = false }: { job: JobSnapshot; compact?: boolean }) {
const pct = percent(job.doneBytes, job.totalBytes);
const running = job.state === "downloading" || job.state === "verifying";
return (
<div className="flex min-w-0 flex-col gap-1.5">
<Progress value={pct} />
<div className="flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground tabular-nums">
{!compact && <JobStateBadge job={job} />}
<span>
{formatBytes(job.doneBytes)} / {formatBytes(job.totalBytes)} · {pct.toFixed(1)}%
</span>
{running && (
<>
<span>{formatSpeed(job.speedBps)}</span>
<span>ETA {formatDuration(job.etaSeconds)}</span>
</>
)}
</div>
</div>
);
}
+25
View File
@@ -0,0 +1,25 @@
"use client";
import { useSyncExternalStore } from "react";
import { formatDate } from "@/lib/format";
const subscribe = () => () => {};
/**
* Date/time in the browser's timezone. Renders empty during SSR (the server, e.g. a UTC container,
* would format in its own timezone) and fills in on the client.
*/
export function LocalTime({ value }: { value: Date | string | number | null | undefined }) {
const isClient = useSyncExternalStore(
subscribe,
() => true,
() => false,
);
if (value == null) return <>–</>;
const d = new Date(value);
return (
<time dateTime={d.toISOString()} suppressHydrationWarning>
{isClient ? formatDate(d) : ""}
</time>
);
}
+82
View File
@@ -0,0 +1,82 @@
"use client"
import { Progress as ProgressPrimitive } from "@base-ui/react/progress"
import { cn } from "cn"
function Progress({
className,
children,
value,
...props
}: ProgressPrimitive.Root.Props) {
return (
<ProgressPrimitive.Root
value={value}
data-slot="progress"
className={cn("flex flex-wrap gap-3", className)}
{...props}
>
{children}
<ProgressTrack>
<ProgressIndicator />
</ProgressTrack>
</ProgressPrimitive.Root>
)
}
function ProgressTrack({ className, ...props }: ProgressPrimitive.Track.Props) {
return (
<ProgressPrimitive.Track
className={cn(
"relative flex h-1 w-full items-center overflow-x-hidden rounded-full bg-muted",
className
)}
data-slot="progress-track"
{...props}
/>
)
}
function ProgressIndicator({
className,
...props
}: ProgressPrimitive.Indicator.Props) {
return (
<ProgressPrimitive.Indicator
data-slot="progress-indicator"
className={cn("h-full bg-primary transition-all", className)}
{...props}
/>
)
}
function ProgressLabel({ className, ...props }: ProgressPrimitive.Label.Props) {
return (
<ProgressPrimitive.Label
className={cn("text-sm font-medium", className)}
data-slot="progress-label"
{...props}
/>
)
}
function ProgressValue({ className, ...props }: ProgressPrimitive.Value.Props) {
return (
<ProgressPrimitive.Value
className={cn(
"ml-auto text-sm text-muted-foreground tabular-nums",
className
)}
data-slot="progress-value"
{...props}
/>
)
}
export {
Progress,
ProgressTrack,
ProgressIndicator,
ProgressLabel,
ProgressValue,
}