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:
Pascal LinxweilerandClaude Opus 5.5 committed 2026-11-10 15:14:14 +01:00
1 parent 765dac2ed2
commit a1acd8c0a5
19 files changed
+2276 -16

No files matched your search

+59 -4
View File
@@ -2,6 +2,7 @@ import {
ArrowDownIcon,
BoxIcon,
CpuIcon,
ExternalLinkIcon,
FileTextIcon,
FolderIcon,
HistoryIcon,
@@ -14,6 +15,8 @@ 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";
@@ -95,6 +98,11 @@ 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}`;
@@ -135,13 +143,31 @@ 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"} />
{!local && (
{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 && (
<a
href={hub}
target="_blank"
@@ -266,6 +292,14 @@ 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} />
@@ -283,7 +317,7 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
freeBytes={worker.online ? worker.modelsDirFreeBytes : null}
busy={model.status === "downloading"}
hubMissing={hubMissing}
local={local}
local={noHub}
/>
)}
{tab === "jobs" && (
@@ -333,6 +367,27 @@ 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>
@@ -368,7 +423,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>
</>
)}
{!local && (
{!noHub && (
<>
<dt className="text-muted-foreground">On the Hub</dt>
<dd className="flex flex-col items-start gap-0.5">
@@ -400,7 +455,7 @@ export default async function ModelPage({ params, searchParams }: PageProps<"/[o
</dl>
</SideCard>
{!local && (
{!noHub && (
<SideCard title="Model tree" icon={SparklesIcon}>
<ModelTree
repoId={model.repoId}