{/* Content card with the tabs as a segmented control in its header */}
@@ -305,9 +326,11 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
)}
+ You have {shortSha(pinnedSha)}.{" "}
+ {changes === 0
+ ? "None of your selected files changed; updating only moves the pin."
+ : `${changes} of your selected files would change (${formatBytes(download)} to download).`}{" "}
+ Checked .
+
+
+
+ }>Update
+
+
+ Update to {shortSha(diff.sha)}?
+
+ The model is pinned to the new commit (the old one stays in the history) and changed or new files are
+ downloaded. Files that are no longer part of your selection are deleted after the download succeeded.
+
+
+
+ Cancel
+
+ Update
+
+
+
+
+
+ {changes > 0 && (
+
+
+
+
+
+ )}
+
+ );
+}
diff --git a/src/app/(app)/jobs/[id]/job-live.tsx b/src/app/(app)/jobs/[id]/job-live.tsx
index 3b4615b..d4db1b4 100644
--- a/src/app/(app)/jobs/[id]/job-live.tsx
+++ b/src/app/(app)/jobs/[id]/job-live.tsx
@@ -10,6 +10,7 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { useLive } from "@/hooks/use-live";
import { formatDuration } from "@/lib/format";
import { LocalTime } from "@/components/local-time";
+import { jobLabel } from "@/lib/job-labels";
import type { JobSnapshot } from "@/lib/jobs";
const OPEN = ["queued", "downloading", "verifying"];
@@ -40,7 +41,7 @@ export function JobLive({ initial }: { initial: JobSnapshot }) {
- {job.kind === "download" ? "Download" : job.kind} ·{" "}
+ {jobLabel(job)} ·{" "}
{job.repoId}
diff --git a/src/app/(app)/library-view.tsx b/src/app/(app)/library-view.tsx
index b5a8f49..25c94d6 100644
--- a/src/app/(app)/library-view.tsx
+++ b/src/app/(app)/library-view.tsx
@@ -56,7 +56,12 @@ function toSearchable(r: LibraryRow): SearchableModel {
pipelineTag: r.pipelineTag,
license: r.license,
status: r.status,
- hubStatus: r.hubState && r.hubState !== "available" ? HUB_STATE_LABEL[r.hubState].label : null,
+ hubStatus:
+ r.hubState && r.hubState !== "available"
+ ? HUB_STATE_LABEL[r.hubState].label
+ : r.updateAvailable
+ ? "update available"
+ : null,
};
}
@@ -223,6 +228,11 @@ export function LibraryView({ rows }: { rows: LibraryRow[] }) {
+ {r.updateAvailable && (r.hubState === "available" || !r.hubState) && (
+
+ update available
+
+ )}
)}
diff --git a/src/app/api/models/[id]/hub-check/route.ts b/src/app/api/models/[id]/hub-check/route.ts
index 0f8c5b9..a433190 100644
--- a/src/app/api/models/[id]/hub-check/route.ts
+++ b/src/app/api/models/[id]/hub-check/route.ts
@@ -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>(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));
});
diff --git a/src/app/api/models/[id]/repair/route.ts b/src/app/api/models/[id]/repair/route.ts
new file mode 100644
index 0000000..5108e4e
--- /dev/null
+++ b/src/app/api/models/[id]/repair/route.ts
@@ -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>(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;
+ }
+});
diff --git a/src/app/api/models/[id]/route.ts b/src/app/api/models/[id]/route.ts
index aadfe53..7314ce4 100644
--- a/src/app/api/models/[id]/route.ts
+++ b/src/app/api/models/[id]/route.ts
@@ -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>(async (_req, { params }) => {
+/** Delete a model; `?files=1` also deletes its files from disk (queued for the worker). */
+export const DELETE = withAuth>(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;
diff --git a/src/app/api/models/[id]/update/route.ts b/src/app/api/models/[id]/update/route.ts
new file mode 100644
index 0000000..cc7461f
--- /dev/null
+++ b/src/app/api/models/[id]/update/route.ts
@@ -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>(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);
+ }
+});
diff --git a/src/app/api/models/[id]/verify/route.ts b/src/app/api/models/[id]/verify/route.ts
new file mode 100644
index 0000000..2024a15
--- /dev/null
+++ b/src/app/api/models/[id]/verify/route.ts
@@ -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>(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;
+ }
+});
diff --git a/src/components/job-actions.ts b/src/components/job-actions.ts
index f6d54eb..4169c06 100644
--- a/src/components/job-actions.ts
+++ b/src/components/job-actions.ts
@@ -17,3 +17,17 @@ export async function startDownload(modelId: string) {
export async function cancelJob(jobId: string) {
if (await post(`/api/jobs/${jobId}/cancel`)) toast.info("Cancelling…");
}
+
+export async function startVerify(modelId: string, deep: boolean) {
+ if (await post(`/api/models/${modelId}/verify${deep ? "?deep=1" : ""}`)) toast.success(deep ? "Deep verify queued" : "Verify queued");
+}
+
+export async function startRepair(modelId: string) {
+ if (await post(`/api/models/${modelId}/repair`)) toast.success("Repair queued");
+}
+
+export async function startUpdate(modelId: string): Promise {
+ const ok = await post(`/api/models/${modelId}/update`);
+ if (ok) toast.success("Update queued");
+ return ok;
+}
diff --git a/src/components/verify-result.tsx b/src/components/verify-result.tsx
new file mode 100644
index 0000000..0b2584c
--- /dev/null
+++ b/src/components/verify-result.tsx
@@ -0,0 +1,52 @@
+import { CircleAlertIcon, CircleCheckIcon } from "lucide-react";
+import type { JobResult } from "@/lib/db/schema";
+import { formatBytes } from "@/lib/format";
+import { cn } from "@/lib/utils";
+
+function PathList({ title, paths, tone }: { title: string; paths: string[]; tone: "bad" | "muted" }) {
+ if (paths.length === 0) return null;
+ return (
+
+
+ {title} ({paths.length})
+
+
+ {paths.slice(0, 50).map((p) => (
+
{p}
+ ))}
+ {paths.length > 50 &&
… {paths.length - 50} more
}
+
+
+ );
+}
+
+/** Outcome of a (deep) verify: problems per kind, plus extra files in the folder. */
+export function VerifyResult({ result, deep }: { result: JobResult; deep: boolean }) {
+ const missing = result.missing ?? [];
+ const sizeMismatch = result.sizeMismatch ?? [];
+ const hashMismatch = result.hashMismatch ?? [];
+ const extra = result.extra ?? [];
+ const problems = missing.length + sizeMismatch.length + hashMismatch.length;
+ const extraBytes = extra.reduce((s, e) => s + e.size, 0);
+
+ return (
+