35 lines
1003 B
TypeScript
35 lines
1003 B
TypeScript
import { NextResponse, type NextRequest } from "next/server";
|
|
import { requireApiAdmin } from "@/lib/api-auth";
|
|
import { setDefaultMonthlyQuota } from "@/lib/db";
|
|
import { jsonError, normalizeError } from "@/lib/http";
|
|
|
|
export const runtime = "nodejs";
|
|
|
|
export async function PUT(request: NextRequest) {
|
|
try {
|
|
requireApiAdmin(request);
|
|
|
|
const body = (await request.json()) as {
|
|
defaultMonthlyQuota?: unknown;
|
|
};
|
|
const numericValue = Number.parseInt(
|
|
String(body?.defaultMonthlyQuota ?? ""),
|
|
10,
|
|
);
|
|
|
|
if (!Number.isFinite(numericValue) || numericValue < 0) {
|
|
return jsonError("默认额度必须是大于等于 0 的整数。", 400);
|
|
}
|
|
|
|
const settings = setDefaultMonthlyQuota(numericValue);
|
|
|
|
return NextResponse.json({
|
|
ok: true,
|
|
settings,
|
|
});
|
|
} catch (error) {
|
|
const normalizedError = normalizeError(error, "保存默认额度失败。");
|
|
return jsonError(normalizedError.message, normalizedError.statusCode);
|
|
}
|
|
}
|