Import folders without a Hub repo as local models

The Import form gets "Add as local model": every file in the folder,
kept as it is, named after the folder. A new models.source column
(hub | local) marks them; local models skip Hub checks, metadata,
downloads, updates and deep verify, and Verify checks existence and
size only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pascal LinxweilerandClaude Opus 5.5 committed 2026-11-08 00:14:56 +01:00
1 parent 90d6007b55
commit 80ccf800df
21 files changed
+1747 -39

No files matched your search

+21 -3
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 { addModel, ModelError } from "@/lib/models";
import { addLocalModel, addModel, ModelError } from "@/lib/models";
import { addTag, normalizeTagName, TagError } from "@/lib/tags";
const Body = z.object({
@@ -19,10 +19,28 @@ const Body = z.object({
localPath: z.string().min(1).max(512).optional(),
});
/** Add a model to the library, pinned to the SHA the user reviewed, and queue its download. */
/** A folder from the models folder without a Hub repo, added as it is. */
const LocalBody = z.object({
source: z.literal("local"),
localPath: z.string().min(1).max(512),
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: "local"`, add a folder from the models folder that has no Hub repo instead (nothing queued).
*/
export const POST = withAuth(async (req) => {
try {
const body = Body.parse(await req.json());
const json = await req.json();
if (json?.source === "local") {
const body = LocalBody.parse(json);
body.tags.forEach(normalizeTagName);
const { id } = await addLocalModel({ localPath: body.localPath });
for (const tag of body.tags) await addTag(id, tag);
return NextResponse.json({ id, jobId: null }, { status: 201 });
}
const body = Body.parse(json);
body.tags.forEach(normalizeTagName); // validate before anything is written
const { id } = await addModel({
repoId: body.repoId,