Release 0.15.1: schedule for the models folder scan
Release / release (push) Successful in 3m49s

Settings -> Downloads lets you scan the models folder every 2 minutes
(default, as before), hourly, daily, weekly, monthly at a chosen local
time, or only manually, with a Scan now button and the last/next scan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pascal LinxweilerandClaude Opus 5.5 committed 2026-10-27 16:42:56 +01:00
1 parent 276108932d
commit c6bcb514e6
14 files changed
+1940 -12

No files matched your search

+42 -1
View File
@@ -1,10 +1,11 @@
import "server-only";
import { eq } from "drizzle-orm";
import { db } from "@/lib/db/client";
import { settings } from "@/lib/db/schema";
import { settings, workerState } from "@/lib/db/schema";
import { isLabelColor } from "@/lib/colors";
import { FILE_ROLE_ORDER, FILE_ROLES, type FileRole, type FileRoleStyles } from "@/lib/file-roles";
import { MIN_SPEED_LIMIT, parseSpeedLimit, SPEED_LIMIT_KEY } from "@/lib/download-limit";
import { nextScanAt, parseScanSchedule, SCAN_SCHEDULE_KEY, type ScanSchedule, ScanScheduleError, validateScanSchedule } from "@/lib/folder-scan";
import { DEFAULT_RECOMMENDED_ROLES, RECOMMENDABLE_ROLES } from "@/lib/recommend";
const FILE_ROLES_KEY = "labels.fileRoles";
@@ -99,3 +100,43 @@ export async function saveDownloadSpeedLimit(bytesPerSecond: number | null): Pro
else await write(SPEED_LIMIT_KEY, Math.round(bytesPerSecond));
return getDownloadSpeedLimit();
}
/** When the worker scans the models folder for importable folders (Settings → Downloads). */
export async function getScanSchedule(): Promise<ScanSchedule> {
return parseScanSchedule(await read<unknown>(SCAN_SCHEDULE_KEY));
}
export async function saveScanSchedule(input: unknown): Promise<ScanSchedule> {
try {
await write(SCAN_SCHEDULE_KEY, validateScanSchedule(input));
} catch (err) {
if (err instanceof ScanScheduleError) throw new SettingsError(err.message);
throw err;
}
return getScanSchedule();
}
export type ScanStatus = {
schedule: ScanSchedule;
lastScanAt: number | null;
lastScanFound: number | null;
/** A "Scan now" the worker hasn't started yet. */
requested: boolean;
nextScanAt: number | null;
};
export async function getScanStatus(): Promise<ScanStatus> {
const [schedule, ws] = await Promise.all([
getScanSchedule(),
db().query.workerState.findFirst({ columns: { lastScanAt: true, lastScanFound: true, scanRequestedAt: true }, where: eq(workerState.id, "worker") }),
]);
const last = ws?.lastScanAt ?? null;
const next = schedule.every === "manual" ? null : last ? nextScanAt(schedule, last) : new Date();
return {
schedule,
lastScanAt: last?.getTime() ?? null,
lastScanFound: ws?.lastScanFound ?? null,
requested: !!ws?.scanRequestedAt && (!last || ws.scanRequestedAt > last),
nextScanAt: next?.getTime() ?? null,
};
}