The worker scans MODELS_DIR (startup, every 2 min, on "Rescan") for <org>/<name> folders that no model uses and stores them in local_folders. The library lists them; Import opens Add model prefilled with the folder, the commit hf recorded and the files on disk preselected. The import job runs hf download into the existing folder: hf 2.1.1 hashes files it didn't download itself, keeps matching ones and re-downloads the rest (verified in Docker, including a corrupted file being replaced). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
26 lines
1017 B
TypeScript
26 lines
1017 B
TypeScript
import "server-only";
|
|
import { asc, eq, notInArray } from "drizzle-orm";
|
|
import { db } from "@/lib/db/client";
|
|
import { localFolders, models, workerState } from "@/lib/db/schema";
|
|
|
|
export type LocalFolder = typeof localFolders.$inferSelect;
|
|
|
|
/** Folders in MODELS_DIR that no model uses (from the worker's last scan). */
|
|
export async function listLocalFolders(): Promise<LocalFolder[]> {
|
|
const d = db();
|
|
return d
|
|
.select()
|
|
.from(localFolders)
|
|
.where(notInArray(localFolders.path, d.select({ p: models.localPath }).from(models)))
|
|
.orderBy(asc(localFolders.path));
|
|
}
|
|
|
|
export async function getLocalFolder(path: string): Promise<LocalFolder | undefined> {
|
|
return db().query.localFolders.findFirst({ where: eq(localFolders.path, path) });
|
|
}
|
|
|
|
/** Ask the worker to scan MODELS_DIR now (it picks this up with its next heartbeat). */
|
|
export async function requestFolderScan(): Promise<void> {
|
|
await db().update(workerState).set({ scanRequestedAt: new Date() }).where(eq(workerState.id, "worker"));
|
|
}
|