- 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>
100 lines
3.4 KiB
TypeScript
100 lines
3.4 KiB
TypeScript
"use client";
|
|
|
|
import { Trash2Icon } from "lucide-react";
|
|
import { useRouter } from "next/navigation";
|
|
import { useState } from "react";
|
|
import { toast } from "sonner";
|
|
import {
|
|
AlertDialog,
|
|
AlertDialogAction,
|
|
AlertDialogCancel,
|
|
AlertDialogContent,
|
|
AlertDialogDescription,
|
|
AlertDialogFooter,
|
|
AlertDialogHeader,
|
|
AlertDialogTitle,
|
|
AlertDialogTrigger,
|
|
} from "@/components/ui/alert-dialog";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Checkbox } from "@/components/ui/checkbox";
|
|
|
|
/**
|
|
* Delete a model, whatever its state (failed, incomplete, ready, …). By default its files are
|
|
* deleted from disk too (by the worker); unchecked, only the library entry goes.
|
|
*/
|
|
export function DeleteModelButton({
|
|
id,
|
|
repoId,
|
|
localPath,
|
|
mayHaveFiles,
|
|
}: {
|
|
id: string;
|
|
repoId: string;
|
|
localPath: string;
|
|
/** False if nothing was ever downloaded, so there's nothing on disk to ask about. */
|
|
mayHaveFiles: boolean;
|
|
}) {
|
|
const router = useRouter();
|
|
const [deleteFiles, setDeleteFiles] = useState(true);
|
|
const [pending, setPending] = useState(false);
|
|
|
|
async function remove() {
|
|
setPending(true);
|
|
const res = await fetch(`/api/models/${id}${mayHaveFiles && deleteFiles ? "?files=1" : ""}`, { method: "DELETE" });
|
|
if (res.ok) {
|
|
toast.success(res.status === 202 ? `Deleting ${repoId} and its files…` : `${repoId} removed from the library`);
|
|
router.push("/");
|
|
router.refresh();
|
|
} else {
|
|
const body = await res.json().catch(() => ({}));
|
|
toast.error(body.error?.message ?? `Delete failed (${res.status})`);
|
|
setPending(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<AlertDialog>
|
|
<AlertDialogTrigger
|
|
render={
|
|
<Button
|
|
variant="outline"
|
|
size="sm"
|
|
className="text-destructive hover:bg-destructive/10 hover:text-destructive"
|
|
/>
|
|
}
|
|
>
|
|
<Trash2Icon />
|
|
Delete
|
|
</AlertDialogTrigger>
|
|
<AlertDialogContent>
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>Delete {repoId}?</AlertDialogTitle>
|
|
<AlertDialogDescription>
|
|
{mayHaveFiles
|
|
? "The model is removed from the library, including its tags and job history."
|
|
: "Nothing was downloaded yet, so this only removes the library entry."}
|
|
</AlertDialogDescription>
|
|
</AlertDialogHeader>
|
|
{mayHaveFiles && (
|
|
<label className="flex cursor-pointer items-start gap-2.5 rounded-md bg-muted/50 px-3 py-2.5 text-sm">
|
|
<Checkbox checked={deleteFiles} onCheckedChange={(v) => setDeleteFiles(v === true)} className="mt-0.5" />
|
|
<span className="flex flex-col gap-0.5">
|
|
<span>Also delete the files from disk</span>
|
|
<span className="text-xs text-muted-foreground">
|
|
Deletes the repo's files in <code className="font-mono">{localPath}</code>. Files you put there yourself are
|
|
kept. Unchecked, the folder stays and shows up under “Found in the models folder”.
|
|
</span>
|
|
</span>
|
|
</label>
|
|
)}
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
<AlertDialogAction variant="destructive" onClick={remove} disabled={pending}>
|
|
{mayHaveFiles && deleteFiles ? "Delete with files" : "Delete"}
|
|
</AlertDialogAction>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
);
|
|
}
|