feat(project): init
This commit is contained in:
34
app/api/admin/settings/route.ts
Normal file
34
app/api/admin/settings/route.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user