"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 { formatBytes } from "@/lib/format"; /** Remove one selected file (all parts of a split file) from the model and from disk. */ export function RemoveFileButton({ modelId, name, paths, size, disabled, reason }: { modelId: string; name: string; paths: string[]; size: number; disabled: boolean; reason?: string }) { const router = useRouter(); const [busy, setBusy] = useState(false); async function remove() { setBusy(true); try { const res = await fetch(`/api/models/${modelId}/files`, { method: "DELETE", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ remove: paths }) }); const json = await res.json().catch(() => ({})); if (!res.ok) return toast.error(json.error?.message ?? `Could not remove (${res.status})`); toast.success(`Removing ${name}`); router.refresh(); } finally { setBusy(false); } } return ( } > Remove {name}? {paths.length > 1 ? `All ${paths.length} parts (${formatBytes(size)})` : `The file (${formatBytes(size)})`} will be deleted from the models folder and taken out of this model's selection. The rest of the model stays. You can download it again later with Download more. Cancel Remove ); }