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>
131 lines
4.3 KiB
TypeScript
131 lines
4.3 KiB
TypeScript
"use client";
|
|
|
|
import { FolderInputIcon, RefreshCwIcon } from "lucide-react";
|
|
import { useRouter } from "next/navigation";
|
|
import { useState } from "react";
|
|
import { toast } from "sonner";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Card, CardAction, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
|
import { formatBytes, shortSha } from "@/lib/format";
|
|
import { cn } from "@/lib/utils";
|
|
import { AddModelForm, type ImportFolder } from "./add-model-form";
|
|
|
|
type Folder = ImportFolder & { totalBytes: number };
|
|
|
|
/** The "Add model" / "Close" toggle (shown in the library hero). */
|
|
export function AddModelToggle({ open, onToggle }: { open: boolean; onToggle: () => void }) {
|
|
return (
|
|
<Button variant={open ? "outline" : "default"} onClick={onToggle}>
|
|
{open ? "Close" : "Add model"}
|
|
</Button>
|
|
);
|
|
}
|
|
|
|
/**
|
|
* The lookup/selection form, opened inline by the "Add model" toggle, and the folders in the models
|
|
* folder that aren't in the library yet, each with "Import".
|
|
*/
|
|
export function AddModelPanel({
|
|
freeBytes,
|
|
folders,
|
|
open,
|
|
setOpen,
|
|
}: {
|
|
freeBytes: number | null;
|
|
folders: Folder[];
|
|
open: boolean;
|
|
setOpen: (open: boolean) => void;
|
|
}) {
|
|
const router = useRouter();
|
|
const [importing, setImporting] = useState<Folder | null>(null);
|
|
// Closed from outside (the toggle in the hero): forget the folder being imported.
|
|
const [wasOpen, setWasOpen] = useState(open);
|
|
if (open !== wasOpen) {
|
|
setWasOpen(open);
|
|
if (!open) setImporting(null);
|
|
}
|
|
const [scanning, setScanning] = useState(false);
|
|
|
|
function close() {
|
|
setOpen(false);
|
|
setImporting(null);
|
|
}
|
|
|
|
async function rescan() {
|
|
setScanning(true);
|
|
try {
|
|
const res = await fetch("/api/local-folders/scan", { method: "POST" });
|
|
if (!res.ok) {
|
|
toast.error(`Could not start a scan (${res.status})`);
|
|
return;
|
|
}
|
|
// The worker picks the request up with its next heartbeat (every 5 s).
|
|
await new Promise((r) => setTimeout(r, 7_000));
|
|
router.refresh();
|
|
} finally {
|
|
setScanning(false);
|
|
}
|
|
}
|
|
|
|
return (
|
|
<>
|
|
{open && (
|
|
<AddModelForm
|
|
key={importing?.path ?? "new"}
|
|
freeBytes={freeBytes}
|
|
importFolder={importing ?? undefined}
|
|
onAdded={() => {
|
|
close();
|
|
router.refresh();
|
|
}}
|
|
/>
|
|
)}
|
|
{!open && folders.length > 0 && (
|
|
<Card size="sm">
|
|
<CardHeader>
|
|
<CardTitle className="flex items-center gap-2">
|
|
<FolderInputIcon className="size-4 text-muted-foreground" />
|
|
Found in the models folder
|
|
</CardTitle>
|
|
<CardDescription>
|
|
{folders.length} folder{folders.length === 1 ? " isn't" : "s aren't"} in the library yet. Import matches
|
|
{folders.length === 1 ? " it" : " them"} with the Hub repo and verifies the files instead of downloading them again.
|
|
</CardDescription>
|
|
<CardAction>
|
|
<Button variant="ghost" size="sm" onClick={rescan} disabled={scanning}>
|
|
<RefreshCwIcon className={cn(scanning && "animate-spin")} />
|
|
{scanning ? "Scanning…" : "Rescan"}
|
|
</Button>
|
|
</CardAction>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<ul className="divide-y rounded-lg ring-1 ring-foreground/10">
|
|
{folders.map((f) => (
|
|
<li key={f.path} className="flex flex-wrap items-center gap-x-4 gap-y-1 px-3 py-2">
|
|
<span className="min-w-0 flex-1 truncate font-mono text-sm" title={f.path}>
|
|
{f.path}
|
|
</span>
|
|
<span className="text-xs text-muted-foreground tabular-nums">
|
|
{f.fileCount} file{f.fileCount === 1 ? "" : "s"} · {formatBytes(f.totalBytes)}
|
|
{f.commit && <> · hf commit {shortSha(f.commit)}</>}
|
|
</span>
|
|
<Button
|
|
size="sm"
|
|
variant="outline"
|
|
onClick={() => {
|
|
setImporting(f);
|
|
setOpen(true);
|
|
}}
|
|
>
|
|
Import
|
|
</Button>
|
|
</li>
|
|
))}
|
|
</ul>
|
|
</CardContent>
|
|
</Card>
|
|
)}
|
|
</>
|
|
);
|
|
}
|