- Scoped bearer tokens (models:read, downloads:create), stored as SHA-256, managed in Settings -> API tokens. Only /api/v1 accepts them; the rest stays OIDC-only. - /api/v1: Hub lookup, library list with the search filters, download requests through the existing add-model/queue path (idempotent), compact job status, disk space. - Guardrails: approval mode (default approve), max size per request, minimum free space incl. reserved bytes, max open agent jobs, author allowlist. Approve/reject in the UI; "requested by" shown and filterable. - docs/api.md (incl. Traefik forward-auth bypass), docs/agent/SKILL.md, DB-backed API tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
52 lines
1.8 KiB
TypeScript
52 lines
1.8 KiB
TypeScript
"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…");
|
|
}
|
|
|
|
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<boolean> {
|
|
const ok = await post(`/api/models/${modelId}/update`);
|
|
if (ok) toast.success("Update queued");
|
|
return ok;
|
|
}
|
|
|
|
export async function approveJob(jobId: string): Promise<boolean> {
|
|
const ok = await post(`/api/jobs/${jobId}/approve`);
|
|
if (ok) toast.success("Approved; the download is queued");
|
|
return ok;
|
|
}
|
|
|
|
/** Returns whether the model left the library (it was only added by this request), or null on error. */
|
|
export async function rejectJob(jobId: string): Promise<{ removedModel: boolean } | null> {
|
|
const res = await fetch(`/api/jobs/${jobId}/reject`, { method: "POST" });
|
|
const body = await res.json().catch(() => ({}));
|
|
if (!res.ok) {
|
|
toast.error(body.error?.message ?? `Request failed (${res.status})`);
|
|
return null;
|
|
}
|
|
toast.info(body.removedModel ? "Rejected; the model was removed from the library" : "Rejected");
|
|
return body;
|
|
}
|