CivitAI: add models from civitai.com / civitai.red links
Paste a CivitAI model link (civitai.com, .red or .green), a download link or an AIR id into "Add model": pick a version and its files, and whether to follow new versions. The model is stored as source "civitai" with repoId civitai/<modelId>, pinned to the version id, in the folder civitai/<id>-<name>; files keep CivitAI's SHA-256 for deep verify. Early access and creator-required logins are caught before anything is queued. Migration 0027 adds models.display_name, nsfw and source_card, and model_files.civitai (file id and attributes). The model page links to CivitAI instead of the Hub, and Hub checks, updates and adding files are refused for CivitAI models for now. The worker fails CivitAI download jobs until it can run them (next step). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
765dac2ed2
commit
a1acd8c0a5
19 files changed
+2276
-16
No files matched your search
@@ -18,8 +18,11 @@ 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 } };
|
||||
|
||||
@@ -52,6 +55,9 @@ 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("");
|
||||
@@ -82,6 +88,11 @@ 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);
|
||||
@@ -100,6 +111,21 @@ 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) {
|
||||
@@ -216,17 +242,17 @@ export function AddModelForm({
|
||||
<div className="flex flex-col gap-4">
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>{importFolder ? `Import ${importFolder.path}` : "Hugging Face repository"}</CardTitle>
|
||||
<CardTitle>{importFolder ? `Import ${importFolder.path}` : "Hugging Face or CivitAI"}</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 paste the repo URL."}
|
||||
: "Repo ID like unsloth/Qwen3-8B-GGUF or the repo URL, or a CivitAI model link (civitai.com or civitai.red)."}
|
||||
</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">Repo ID</Label>
|
||||
<Label htmlFor="repo">{importFolder ? "Repo ID" : "Repo ID or link"}</Label>
|
||||
<Input
|
||||
id="repo"
|
||||
value={repo}
|
||||
@@ -243,7 +269,9 @@ export function AddModelForm({
|
||||
id="revision"
|
||||
value={revision}
|
||||
onChange={(e) => setRevision(e.target.value)}
|
||||
placeholder="main"
|
||||
placeholder={civitaiInput ? "picked after the lookup" : "main"}
|
||||
disabled={civitaiInput}
|
||||
title={civitaiInput ? "CivitAI versions are picked after the lookup" : undefined}
|
||||
spellCheck={false}
|
||||
/>
|
||||
</div>
|
||||
@@ -271,6 +299,18 @@ 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>
|
||||
|
||||
Reference in new issue
Block a user