Delete, verify/deep verify, repair and update checks

- Delete any model (incl. failed ones); the worker removes the repo's
  files (keeps foreign files and empty-folder cleanup), then the rows.
- Verify (existence, size, hf metadata) and deep verify (SHA-256 /
  git blob SHA-1 against the Hub) with missing/mismatch/extra report.
- Repair = download of the selection; broken files are deleted first
  because hf skips files whose metadata matches without checking them.
- Hub check resolves the tracked revision and stores which selected
  files a newer commit changes/adds/removes; Update pins it (old commit
  kept in model_revisions), downloads, then removes dropped files.
- Worker runs verify/delete jobs next to downloads (2 local slots).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pascal LinxweilerandClaude Opus 5.5 committed 2026-10-06 01:00:55 +02:00
1 parent c2c239bf16
commit 7864a492c9
37 files changed
+2365 -191

No files matched your search

+2 -2
View File
@@ -1,12 +1,12 @@
import { NextResponse } from "next/server";
import { withAuth } from "@/lib/api-auth";
import { apiError } from "@/lib/api-errors";
import { checkHubAvailability, getCheckedModel } from "@/lib/hub/availability";
import { checkHub, getCheckedModel } from "@/lib/hub/availability";
/** Check right now whether the repo and pinned commit are still on the Hub. */
export const POST = withAuth<RouteContext<"/api/models/[id]/hub-check">>(async (_req, { params }) => {
const { id } = await params;
const model = await getCheckedModel(id);
if (!model) return apiError(404, "not_found", "Model not found.");
return NextResponse.json(await checkHubAvailability(model));
return NextResponse.json(await checkHub(model));
});
+15
View File
@@ -0,0 +1,15 @@
import { NextResponse } from "next/server";
import { withAuth } from "@/lib/api-auth";
import { apiError } from "@/lib/api-errors";
import { JobError, queueDownload } from "@/lib/jobs";
/** Download again what's missing or broken (the worker deletes broken files first). */
export const POST = withAuth<RouteContext<"/api/models/[id]/repair">>(async (_req, { params }) => {
const { id } = await params;
try {
return NextResponse.json(await queueDownload(id, "repair"), { status: 201 });
} catch (err) {
if (err instanceof JobError) return apiError(err.status, err.code, err.message);
throw err;
}
});
+6 -4
View File
@@ -1,13 +1,15 @@
import { NextResponse } from "next/server";
import { withAuth } from "@/lib/api-auth";
import { apiError } from "@/lib/api-errors";
import { ModelError, removeModel } from "@/lib/models";
import { deleteModel, ModelError } from "@/lib/models";
export const DELETE = withAuth<RouteContext<"/api/models/[id]">>(async (_req, { params }) => {
/** Delete a model; `?files=1` also deletes its files from disk (queued for the worker). */
export const DELETE = withAuth<RouteContext<"/api/models/[id]">>(async (req, { params }) => {
const { id } = await params;
try {
await removeModel(id);
return new NextResponse(null, { status: 204 });
const deleteFiles = new URL(req.url).searchParams.get("files") === "1";
const { queued } = await deleteModel(id, { deleteFiles });
return queued ? NextResponse.json({ queued }, { status: 202 }) : new NextResponse(null, { status: 204 });
} catch (err) {
if (err instanceof ModelError) return apiError(err.status, err.code, err.message);
throw err;
+15
View File
@@ -0,0 +1,15 @@
import { NextResponse } from "next/server";
import { withAuth } from "@/lib/api-auth";
import { apiError, handleApiError } from "@/lib/api-errors";
import { applyUpdate, ModelError } from "@/lib/models";
/** Update to the newer commit found by the last Hub check (deliberate, never automatic). */
export const POST = withAuth<RouteContext<"/api/models/[id]/update">>(async (_req, { params }) => {
const { id } = await params;
try {
return NextResponse.json(await applyUpdate(id), { status: 201 });
} catch (err) {
if (err instanceof ModelError) return apiError(err.status, err.code, err.message);
return handleApiError(err);
}
});
+16
View File
@@ -0,0 +1,16 @@
import { NextResponse } from "next/server";
import { withAuth } from "@/lib/api-auth";
import { apiError } from "@/lib/api-errors";
import { JobError, queueVerify } from "@/lib/jobs";
/** Queue a verify (`?deep=1`: hash every file) of the model's selected files. */
export const POST = withAuth<RouteContext<"/api/models/[id]/verify">>(async (req, { params }) => {
const { id } = await params;
try {
const deep = new URL(req.url).searchParams.get("deep") === "1";
return NextResponse.json(await queueVerify(id, deep), { status: 201 });
} catch (err) {
if (err instanceof JobError) return apiError(err.status, err.code, err.message);
throw err;
}
});