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

+5 -2
View File
@@ -3,6 +3,7 @@ import { z } from "zod";
import { withAuth } from "@/lib/api-auth";
import { apiError, handleApiError } from "@/lib/api-errors";
import { REPO_ID_RE, SHA_RE } from "@/lib/hub/client";
import { queueDownload } from "@/lib/jobs";
import { addModel, ModelError } from "@/lib/models";
const Body = z.object({
@@ -11,9 +12,10 @@ const Body = z.object({
sha: z.string().regex(SHA_RE, "must be a full 40-character commit SHA"),
include: z.array(z.string().min(1).max(1024)).max(10_000),
exclude: z.array(z.string().min(1).max(1024)).max(1_000),
download: z.boolean().default(true),
});
/** Add a model to the library, pinned to the SHA the user reviewed. */
/** Add a model to the library, pinned to the SHA the user reviewed, and queue its download. */
export const POST = withAuth(async (req) => {
try {
const body = Body.parse(await req.json());
@@ -23,7 +25,8 @@ export const POST = withAuth(async (req) => {
sha: body.sha,
rule: { include: body.include, exclude: body.exclude },
});
return NextResponse.json({ id }, { status: 201 });
const job = body.download ? await queueDownload(id) : null;
return NextResponse.json({ id, jobId: job?.jobId ?? null }, { status: 201 });
} catch (err) {
if (err instanceof ModelError) return apiError(err.status, err.code, err.message);
return handleApiError(err);