"use client"; import { toast } from "sonner"; async function post(url: string): Promise { 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 { const ok = await post(`/api/models/${modelId}/update`); if (ok) toast.success("Update queued"); return ok; } export async function approveJob(jobId: string): Promise { 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; }