hf has no bandwidth option, so the worker pauses hf (SIGSTOP/SIGCONT) whenever it is ahead of a token bucket over bytes on disk. The limit is shared by all running downloads and re-read every 5 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { z } from "zod";
|
|
import { withAuth } from "@/lib/api-auth";
|
|
import { apiError, handleApiError } from "@/lib/api-errors";
|
|
import { getDownloadSpeedLimit, getRecommendedRoles, saveDownloadSpeedLimit, saveRecommendedRoles, SettingsError } from "@/lib/settings";
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
async function current() {
|
|
return { recommendedRoles: await getRecommendedRoles(), maxBytesPerSecond: await getDownloadSpeedLimit() };
|
|
}
|
|
|
|
/** Download settings: which file kinds are picked along with model weights, and the speed limit. */
|
|
export const GET = withAuth(async () => NextResponse.json(await current()));
|
|
|
|
const Body = z.object({
|
|
recommendedRoles: z.array(z.string()).max(32).optional(),
|
|
maxBytesPerSecond: z.number().nullable().optional(),
|
|
});
|
|
|
|
export const PUT = withAuth(async (req) => {
|
|
try {
|
|
const body = Body.parse(await req.json());
|
|
if (body.recommendedRoles) await saveRecommendedRoles(body.recommendedRoles);
|
|
if (body.maxBytesPerSecond !== undefined) await saveDownloadSpeedLimit(body.maxBytesPerSecond);
|
|
return NextResponse.json(await current());
|
|
} catch (err) {
|
|
if (err instanceof SettingsError) return apiError(err.status, err.code, err.message);
|
|
return handleApiError(err);
|
|
}
|
|
});
|