Revert CivitAI downloads

Removes the CivitAI work again (765dac2, a1acd8c): the API client and
link parser, CIVITAI_TOKEN, adding CivitAI models, migration 0027 and
the model page changes. Kaname downloads from Hugging Face only, as in
0.21.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pascal LinxweilerandClaude Opus 5.5 committed 2026-11-11 21:32:02 +01:00
1 parent a1acd8c0a5
commit 7d1a8fb85a
25 files changed
+17 -2849

No files matched your search

+4 -59
View File
@@ -2,7 +2,6 @@ import {
ArrowDownIcon,
BoxIcon,
CpuIcon,
ExternalLinkIcon,
FileTextIcon,
FolderIcon,
HistoryIcon,
@@ -15,8 +14,6 @@ import {
TriangleAlertIcon,
} from "lucide-react";
import type { Metadata } from "next";
import { civitaiPageUrl } from "@/lib/civitai/input";
import { CIVITAI_LATEST, civitaiModelId } from "@/lib/civitai/paths";
import Link from "next/link";
import { notFound, redirect } from "next/navigation";
import { Suspense } from "react";
@@ -98,11 +95,6 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
// A local model has no Hub repo: no commit, Hub checks or model tree; its README is the model card.
const local = model.source === "local";
// A CivitAI model: pinned to a model version (pinnedSha), no Hub repo, commit or model tree.
const civitai = model.source === "civitai";
const noHub = local || civitai;
const civitaiId = civitai ? civitaiModelId(model.repoId) : null;
const civitaiPage = civitaiId ? civitaiPageUrl(civitaiId, { nsfw: model.nsfw }) : null;
const tab: TabId = TABS.some((t) => t.id === sp.tab) ? (sp.tab as TabId) : "files";
const [author, name] = model.repoId.split("/");
const hub = `https://huggingface.co/${model.repoId}`;
@@ -143,31 +135,13 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
title={
<span className="flex flex-wrap items-center gap-x-2 gap-y-2">
<Avatar url={model.authorAvatarUrl} name={author} />
{civitai ? (
<span className="break-all">{model.displayName ?? model.repoId}</span>
) : (
<>
<Link href={`/?author=${encodeURIComponent(author)}`} className="font-normal text-muted-foreground hover:text-foreground hover:underline">
{author}
</Link>
<span className="font-normal text-muted-foreground">/</span>
<span className="break-all">{name}</span>
</>
)}
<CopyButton value={model.repoId} label={local ? "Copy name" : "Copy repo ID"} />
{civitaiPage && (
<a
href={civitaiPage}
target="_blank"
rel="noreferrer"
title="Open on CivitAI"
aria-label="Open on CivitAI"
className="inline-flex size-7 items-center justify-center rounded-md text-muted-foreground hover:bg-muted hover:text-foreground"
>
<ExternalLinkIcon className="size-4" />
</a>
)}
{!noHub && (
{!local && (
<a
href={hub}
target="_blank"
@@ -292,14 +266,6 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
<div className="p-5 sm:p-6">
{local ? (
<LocalModelCardSection markdown={model.localReadme} localPath={model.localPath} />
) : civitai ? (
<p className="text-sm text-muted-foreground">
The creator&apos;s description is on{" "}
<a href={civitaiPage ?? "#"} target="_blank" rel="noreferrer" className="underline">
CivitAI
</a>
.
</p>
) : (
<Suspense fallback={<ModelCardSkeleton />}>
<ModelCardSection repoId={model.repoId} sha={model.pinnedSha} />
@@ -317,7 +283,7 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
freeBytes={worker.online ? worker.modelsDirFreeBytes : null}
busy={model.status === "downloading"}
hubMissing={hubMissing}
local={noHub}
local={local}
/>
)}
{tab === "jobs" && (
@@ -367,27 +333,6 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
<dt className="text-muted-foreground">Source</dt>
<dd>Local folder, no Hugging Face repo</dd>
</>
) : civitai ? (
<>
<dt className="text-muted-foreground">Version</dt>
<dd className="flex items-center gap-1">
<a
href={civitaiId ? civitaiPageUrl(civitaiId, { nsfw: model.nsfw, versionId: Number(model.pinnedSha) }) : "#"}
target="_blank"
rel="noreferrer"
className="font-mono hover:underline"
>
{model.pinnedSha}
</a>
<span className="text-muted-foreground">
{model.trackedRevision === CIVITAI_LATEST ? "following new versions" : "pinned"}
</span>
</dd>
<dt className="text-muted-foreground">Downloaded</dt>
<dd>
<LocalTime value={model.downloadedAt} />
</dd>
</>
) : (
<>
<dt className="text-muted-foreground">Commit</dt>
@@ -423,7 +368,7 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
<dd className="flex flex-col font-mono text-xs">{model.excludePatterns.map((p) => <span key={p} className="break-all">{p}</span>)}</dd>
</>
)}
{!noHub && (
{!local && (
<>
<dt className="text-muted-foreground">On the Hub</dt>
<dd className="flex flex-col items-start gap-0.5">
@@ -455,7 +400,7 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
</dl>
</SideCard>
{!noHub && (
{!local && (
<SideCard title="Model tree" icon={SparklesIcon}>
<ModelTree
repoId={model.repoId}
+4 -44
View File
@@ -18,11 +18,8 @@ import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@
import { useRecommended } from "@/hooks/use-recommended";
import { groupSplitFiles } from "@/lib/file-groups";
import { formatBytes, shortSha } from "@/lib/format";
import type { CivitaiLookupResult } from "@/lib/civitai/lookup";
import { isCivitaiInput } from "@/lib/civitai/input";
import type { LookupResult } from "@/lib/hub/lookup";
import { escapeGlob, matchesAny, parsePatternList, quantGroup } from "@/lib/selection";
import { CivitaiSelection } from "./civitai-selection";
type ApiErrorBody = { error?: { code: string; message: string } };
@@ -55,9 +52,6 @@ export function AddModelForm({
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
const [result, setResult] = useState<LookupResult | null>(null);
const [civitai, setCivitai] = useState<CivitaiLookupResult | null>(null);
// Not while importing a folder: imports match a folder against a Hub repo.
const civitaiInput = !importFolder && isCivitaiInput(repo);
const [checked, setChecked] = useState<Set<string>>(new Set());
const [includeText, setIncludeText] = useState("");
@@ -88,11 +82,6 @@ export function AddModelForm({
e?.preventDefault();
setLoading(true);
setError(null);
if (civitaiInput) {
await lookupCivitai();
return;
}
setCivitai(null);
try {
const r = await postJson<LookupResult>("/api/hub/lookup", { repo, revision });
setResult(r);
@@ -111,21 +100,6 @@ export function AddModelForm({
}
}
/** CivitAI: the model behind the pasted link, at `versionId` (the version picker) or the link's version. */
async function lookupCivitai(versionId?: number) {
setLoading(true);
setError(null);
setResult(null);
try {
setCivitai(await postJson<CivitaiLookupResult>("/api/civitai/lookup", { input: repo, versionId }));
} catch (err) {
setCivitai(null);
setError(err instanceof Error ? err.message : String(err));
} finally {
setLoading(false);
}
}
const autoLookup = useRef(false);
useEffect(() => {
if (importFolder && !autoLookup.current) {
@@ -242,17 +216,17 @@ export function AddModelForm({
<div className="flex flex-col gap-4">
<Card>
<CardHeader>
<CardTitle>{importFolder ? `Import ${importFolder.path}` : "Hugging Face or CivitAI"}</CardTitle>
<CardTitle>{importFolder ? `Import ${importFolder.path}` : "Hugging Face repository"}</CardTitle>
<CardDescription>
{importFolder
? `The folder's files are matched against this Hub repo${importFolder.commit ? " at the commit hf recorded when it downloaded them" : ""}. Change the repo or revision if they don't fit.`
: "Repo ID like unsloth/Qwen3-8B-GGUF or the repo URL, or a CivitAI model link (civitai.com or civitai.red)."}
: "Repo ID like unsloth/Qwen3-8B-GGUF, or paste the repo URL."}
</CardDescription>
</CardHeader>
<CardContent>
<form onSubmit={lookup} className="flex flex-col gap-3 sm:flex-row sm:items-end">
<div className="flex flex-1 flex-col gap-1.5">
<Label htmlFor="repo">{importFolder ? "Repo ID" : "Repo ID or link"}</Label>
<Label htmlFor="repo">Repo ID</Label>
<Input
id="repo"
value={repo}
@@ -269,9 +243,7 @@ export function AddModelForm({
id="revision"
value={revision}
onChange={(e) => setRevision(e.target.value)}
placeholder={civitaiInput ? "picked after the lookup" : "main"}
disabled={civitaiInput}
title={civitaiInput ? "CivitAI versions are picked after the lookup" : undefined}
placeholder="main"
spellCheck={false}
/>
</div>
@@ -299,18 +271,6 @@ export function AddModelForm({
</CardContent>
</Card>
{civitai && (
<CivitaiSelection
key={civitai.version.id}
result={civitai}
freeBytes={freeBytes}
loading={loading}
onVersion={(v) => void lookupCivitai(v)}
onAdded={onAdded}
postJson={postJson}
/>
)}
{result && (
<>
<Card>
-247
View File
@@ -1,247 +0,0 @@
"use client";
import { XIcon } from "lucide-react";
import Link from "next/link";
import { useState } from "react";
import { toast } from "sonner";
import { FileRoleBadge } from "@/components/labels";
import { TagBadge } from "@/components/tag-badge";
import { TagPicker } from "@/components/tag-picker";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
import { Checkbox } from "@/components/ui/checkbox";
import { Label } from "@/components/ui/label";
import { NativeSelect } from "@/components/ui/native-select";
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
import type { CivitaiLookupResult } from "@/lib/civitai/lookup";
import { formatBytes } from "@/lib/format";
/** Files picked by default: the primary file, else the first one. */
export function defaultCivitaiPick(result: CivitaiLookupResult): Set<number> {
const primary = result.files.find((f) => f.primary) ?? result.files[0];
return new Set(primary ? [primary.fileId] : []);
}
/** Pick a CivitAI version and its files, then add the model (the CivitAI half of the add form). */
export function CivitaiSelection({
result,
freeBytes,
loading,
onVersion,
onAdded,
postJson,
}: {
result: CivitaiLookupResult;
freeBytes: number | null;
/** Another version is being looked up. */
loading: boolean;
onVersion: (versionId: number) => void;
onAdded: (modelId: string) => void;
postJson: <T>(url: string, body: unknown) => Promise<T>;
}) {
// The parent remounts this component (key) for every looked-up version, so state starts fresh.
const [picked, setPicked] = useState<Set<number>>(() => defaultCivitaiPick(result));
const [follow, setFollow] = useState(result.version.latest);
const [tags, setTags] = useState<{ name: string; color?: string | null }[]>([]);
const [submitting, setSubmitting] = useState(false);
const selected = result.files.filter((f) => picked.has(f.fileId));
const totalBytes = selected.reduce((s, f) => s + f.size, 0);
const notEnoughSpace = freeBytes != null && totalBytes > freeBytes;
const { access } = result;
const earlyAccess = access.checkPermission && access.earlyAccessEndsAt && new Date(access.earlyAccessEndsAt) > new Date();
function toggle(fileId: number, on: boolean) {
setPicked((prev) => {
const next = new Set(prev);
if (on) next.add(fileId);
else next.delete(fileId);
return next;
});
}
async function add() {
setSubmitting(true);
try {
const { id } = await postJson<{ id: string }>("/api/models", {
source: "civitai",
modelId: result.modelId,
versionId: result.version.id,
track: follow ? "latest" : "pinned",
fileIds: selected.map((f) => f.fileId),
tags: tags.map((t) => t.name),
});
toast.success(`${result.name} added, download queued`);
onAdded(id);
} catch (err) {
toast.error(err instanceof Error ? err.message : String(err));
} finally {
setSubmitting(false);
}
}
return (
<>
<Card>
<CardHeader>
<CardTitle className="flex flex-wrap items-center gap-2">
<a href={result.pageUrl} target="_blank" rel="noreferrer" className="hover:underline">
{result.name}
</a>
<Badge variant="outline">{result.type}</Badge>
{result.nsfw && <Badge variant="outline">mature</Badge>}
</CardTitle>
<CardDescription>
CivitAI model {result.modelId}
{result.creator && <> by {result.creator}</>}
{" · "}
{result.versions.length} version{result.versions.length === 1 ? "" : "s"}
</CardDescription>
</CardHeader>
<CardContent className="flex flex-col gap-4">
{result.existingModelId && (
<p className="rounded-md bg-muted px-3 py-2 text-sm">
This model is already in the library.{" "}
<Link href={`/${result.repoId}`} className="underline">
Open it
</Link>
</p>
)}
{earlyAccess && (
<p role="alert" className="rounded-md bg-amber-500/10 px-3 py-2 text-sm text-amber-800 dark:text-amber-200">
This version is in early access until {new Date(access.earlyAccessEndsAt!).toLocaleDateString()}. Unlock it on
CivitAI first, or pick another version; Kaname never spends Buzz.
</p>
)}
{!earlyAccess && access.requireAuth && (
<p className="rounded-md bg-muted px-3 py-2 text-sm text-muted-foreground">
The creator requires a login to download: this needs <code>CIVITAI_TOKEN</code> on the server.
</p>
)}
<div className="grid gap-3 sm:grid-cols-2">
<div className="flex flex-col gap-1.5">
<Label htmlFor="civitai-version">Version</Label>
<NativeSelect
id="civitai-version"
value={result.version.id}
disabled={loading}
onChange={(e) => onVersion(Number(e.target.value))}
>
{result.versions.map((v, i) => (
<option key={v.id} value={v.id}>
{v.name}
{v.baseModel ? ` · ${v.baseModel}` : ""}
{i === 0 ? " (newest)" : ""}
</option>
))}
</NativeSelect>
</div>
<label className="flex items-center gap-2 self-end pb-1.5 text-sm">
<Checkbox checked={follow} onCheckedChange={(v) => setFollow(v === true)} />
Follow new versions (update checks offer the newest)
</label>
</div>
<div className="flex flex-col gap-1.5">
<Label>Tags</Label>
<div className="flex flex-wrap items-center gap-1.5">
{tags.map((t) => (
<TagBadge key={t.name.toLowerCase()} name={t.name} color={t.color}>
<button
type="button"
aria-label={`Remove tag ${t.name}`}
onClick={() => setTags((prev) => prev.filter((x) => x !== t))}
className="opacity-60 hover:opacity-100"
>
<XIcon className="size-3" />
</button>
</TagBadge>
))}
<TagPicker
exclude={tags.map((t) => t.name)}
onPick={(name, tag) =>
setTags((prev) => (prev.some((x) => x.name.toLowerCase() === name.toLowerCase()) ? prev : [...prev, { name, color: tag?.color }]))
}
/>
</div>
<p className="text-xs text-muted-foreground">Optional. Editable later on the model page.</p>
</div>
</CardContent>
</Card>
<Card className="py-0">
<Table>
<TableHeader>
<TableRow>
<TableHead className="w-10" />
<TableHead>File</TableHead>
<TableHead className="hidden sm:table-cell">Variant</TableHead>
<TableHead className="text-right">Size</TableHead>
</TableRow>
</TableHeader>
<TableBody>
{result.files.length === 0 && (
<TableRow>
<TableCell colSpan={4} className="text-center text-sm text-muted-foreground">
This version has no downloadable files.
</TableCell>
</TableRow>
)}
{result.files.map((f) => {
const on = picked.has(f.fileId);
const variant = [f.type, f.format, f.sizeVariant, f.fp].filter(Boolean).join(" · ");
return (
<TableRow key={f.fileId} data-state={on ? "selected" : undefined}>
<TableCell>
<Checkbox checked={on} onCheckedChange={(v) => toggle(f.fileId, v === true)} aria-label={`Select ${f.path}`} />
</TableCell>
<TableCell className="whitespace-normal">
<span className="flex items-center gap-2">
<FileRoleBadge path={f.path} />
<span className="font-mono text-xs break-all">{f.path}</span>
{f.primary && (
<span className="shrink-0 rounded border px-1 text-[10px] leading-4 text-muted-foreground">primary</span>
)}
</span>
</TableCell>
<TableCell className="hidden text-xs text-muted-foreground sm:table-cell">{variant}</TableCell>
<TableCell className="text-right tabular-nums">{formatBytes(f.size)}</TableCell>
</TableRow>
);
})}
</TableBody>
</Table>
</Card>
<div className="sticky bottom-3 z-10 rounded-xl bg-card/95 px-4 py-3 text-card-foreground shadow-lg ring-1 ring-foreground/10 backdrop-blur">
<div className="flex flex-wrap items-center gap-x-4 gap-y-2">
<div className="text-sm">
<span className="font-medium">
{selected.length} file{selected.length === 1 ? "" : "s"} · {formatBytes(totalBytes)}
</span>{" "}
selected
{freeBytes != null && (
<span className={notEnoughSpace ? "ml-2 text-destructive" : "ml-2 text-muted-foreground"}>
({formatBytes(freeBytes)} free on the models volume)
</span>
)}
</div>
<div className="ml-auto flex gap-2">
<Button type="button" variant="ghost" onClick={() => setPicked(new Set())}>
Clear
</Button>
<Button
type="button"
onClick={add}
disabled={selected.length === 0 || submitting || loading || !!result.existingModelId || !!earlyAccess}
>
{submitting ? "Adding…" : "Add & download"}
</Button>
</div>
</div>
</div>
</>
);
}
+1 -1
View File
@@ -203,7 +203,7 @@ export function LibraryView({ rows }: { rows: LibraryRow[] }) {
<TableCell className="pl-4 whitespace-normal">
<Link href={`/${r.repoId}`} className="hover:underline">
<span className="text-muted-foreground">{r.author}/</span>
<span className="font-medium">{r.displayName ?? r.repoId.slice(r.author.length + 1)}</span>
<span className="font-medium">{r.repoId.slice(r.author.length + 1)}</span>
</Link>
<div className="mt-0.5 flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-muted-foreground">
{base && base !== r.repoId && <span>base {base}</span>}
-21
View File
@@ -1,21 +0,0 @@
import { NextResponse } from "next/server";
import { z } from "zod";
import { withAuth } from "@/lib/api-auth";
import { handleApiError } from "@/lib/api-errors";
import { lookupCivitai } from "@/lib/civitai/lookup";
const Body = z.object({
input: z.string().trim().min(1).max(2048),
/** Another version of the same model (the version picker). */
versionId: z.number().int().positive().optional(),
});
/** Look up a CivitAI model link or id: the model, its versions and one version's files. */
export const POST = withAuth(async (req) => {
try {
const body = Body.parse(await req.json());
return NextResponse.json(await lookupCivitai(body.input, body.versionId));
} catch (err) {
return handleApiError(err);
}
});
@@ -9,7 +9,5 @@ export const POST = withAuth<RouteContext<"/api/models/[id]/hub-check">>(async (
const model = await getCheckedModel(id);
if (!model) return apiError(404, "not_found", "Model not found.");
if (model.source === "local") return apiError(409, "local_model", "This is a local model without a Hugging Face repo.");
// Checking CivitAI for new versions comes with CivitAI updates; the Hub would report it missing.
if (model.source === "civitai") return apiError(409, "civitai_model", "Checks for new CivitAI versions aren't available yet.");
return NextResponse.json(await checkHub(model));
});
+2 -22
View File
@@ -4,7 +4,7 @@ import { withAuth } from "@/lib/api-auth";
import { apiError, handleApiError } from "@/lib/api-errors";
import { REPO_ID_RE, SHA_RE } from "@/lib/hub/client";
import { queueDownload } from "@/lib/jobs";
import { addCivitaiModel, addLocalModel, addModel, ModelError } from "@/lib/models";
import { addLocalModel, addModel, ModelError } from "@/lib/models";
import { addTag, normalizeTagName, TagError } from "@/lib/tags";
const Body = z.object({
@@ -26,33 +26,13 @@ const LocalBody = z.object({
tags: z.array(z.string()).max(50).default([]),
});
/** A CivitAI model at the version the user reviewed. */
const CivitaiBody = z.object({
source: z.literal("civitai"),
modelId: z.number().int().positive(),
versionId: z.number().int().positive(),
track: z.enum(["latest", "pinned"]).default("latest"),
fileIds: z.array(z.number().int().positive()).min(1).max(1_000),
download: z.boolean().default(true),
tags: z.array(z.string()).max(50).default([]),
});
/**
* Add a model to the library, pinned to the SHA the user reviewed, and queue its download. With
* `source: "civitai"`, a CivitAI model pinned to a version. With `source: "local"`, add a folder
* from the models folder that has no Hub repo instead (nothing queued).
* `source: "local"`, add a folder from the models folder that has no Hub repo instead (nothing queued).
*/
export const POST = withAuth(async (req) => {
try {
const json = await req.json();
if (json?.source === "civitai") {
const body = CivitaiBody.parse(json);
body.tags.forEach(normalizeTagName);
const { id } = await addCivitaiModel(body);
for (const tag of body.tags) await addTag(id, tag);
const job = body.download ? await queueDownload(id, "initial") : null;
return NextResponse.json({ id, jobId: job?.jobId ?? null }, { status: 201 });
}
if (json?.source === "local") {
const body = LocalBody.parse(json);
body.tags.forEach(normalizeTagName);