更新安全配置项目

This commit is contained in:
2026-04-18 23:52:15 +08:00
parent 70d3020035
commit 59b3117eb9
7 changed files with 332 additions and 377 deletions
+35 -35
View File
@@ -1,48 +1,48 @@
import { NextRequest, NextResponse } from "next/server";
import { getTranslation, getTranslations } from "@/lib/database";
import {NextRequest, NextResponse} from "next/server";
import {getTranslation, getTranslations} from "@/lib/database";
// 单个翻译查询
export async function GET(request: NextRequest) {
const { searchParams } = new URL(request.url);
const chineseName = searchParams.get("name");
const {searchParams} = new URL(request.url);
const chineseName = searchParams.get("name");
if (!chineseName) {
return NextResponse.json({ error: "缺少 name 参数" }, { status: 400 });
}
if (!chineseName) {
return NextResponse.json({error: "缺少 name 参数"}, {status: 400});
}
const translation = await getTranslation(chineseName);
const translation = await getTranslation(chineseName);
return NextResponse.json({
chinese: chineseName,
english: translation,
found: translation !== null,
});
return NextResponse.json({
chinese: chineseName,
english: translation,
found: translation !== null,
});
}
// 批量翻译查询
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { names } = body as { names: string[] };
try {
const body = await request.json();
const {names} = body as { names: string[] };
if (!names || !Array.isArray(names)) {
return NextResponse.json({ error: "缺少 names 参数(数组)" }, { status: 400 });
if (!names || !Array.isArray(names)) {
return NextResponse.json({error: "缺少 names 参数(数组)"}, {status: 400});
}
const translations = await getTranslations(names);
const result: Record<string, string | null> = {};
for (const name of names) {
result[name] = translations.get(name) || null;
}
return NextResponse.json({
translations: result,
total: names.length,
found: translations.size,
});
} catch (error) {
console.error("Translation API error:", error);
return NextResponse.json({error: "请求格式错误"}, {status: 400});
}
const translations = await getTranslations(names);
const result: Record<string, string | null> = {};
for (const name of names) {
result[name] = translations.get(name) || null;
}
return NextResponse.json({
translations: result,
total: names.length,
found: translations.size,
});
} catch (error) {
console.error("Translation API error:", error);
return NextResponse.json({ error: "请求格式错误" }, { status: 400 });
}
}