Release / release (push) Successful in 4m33s
- Dot-matrix "Creation of Adam" page banners behind a floating menu, glass cards and tables, library header with live stats, table toolbar with pagination, Cmd/Ctrl+K search across models, endpoints, runs, tags, settings and actions. - Remove single files from a model (selection + disk, via a worker job). - Containers start as root to prepare folders and drop to PUID:PGID; AUTH_SECRET is generated when unset; sandbox runs as nobody; KANAME_IMAGE and image docs in the README. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
100 lines
3.6 KiB
TypeScript
100 lines
3.6 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="border-foreground/20 bg-background/90 font-medium text-red-600 shadow-xs backdrop-blur-sm hover:bg-destructive/15 hover:text-red-600 dark:border-foreground/20 dark:bg-background/90 dark:text-red-400 dark:hover:bg-destructive/25 dark:hover:text-red-300"
|
|
/>
|
|
}
|
|
>
|
|
<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>
|
|
);
|
|
}
|