a249fb038c
- Add Word document parsing and translation export - Add database configuration management - Add AI/LLM translation configuration - Add translation vocabulary management - Add export settings (colors, page orientation, headers) - Separate database and AI configurations - Add debounced search to prevent database overload
58 lines
1.4 KiB
TypeScript
58 lines
1.4 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { getConfig, saveDBConfig, saveAIConfig, type DBConfig, type AIConfig } from "@/lib/config";
|
|
|
|
// GET /api/config - 获取完整配置
|
|
export async function GET() {
|
|
try {
|
|
const config = getConfig();
|
|
return NextResponse.json({
|
|
success: true,
|
|
data: config,
|
|
});
|
|
} catch (error) {
|
|
return NextResponse.json(
|
|
{ success: false, error: "读取配置失败" },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|
|
|
|
// POST /api/config - 保存配置
|
|
// Body 格式: { db?: DBConfig, ai?: AIConfig }
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const body = await request.json();
|
|
const { db, ai } = body;
|
|
|
|
if (db) {
|
|
saveDBConfig(db);
|
|
}
|
|
|
|
if (ai) {
|
|
saveAIConfig(ai);
|
|
}
|
|
|
|
// 如果同时发送了完整配置
|
|
if (!db && !ai && body.db === undefined && body.ai === undefined) {
|
|
// 可能是旧的扁平格式,尝试兼容
|
|
if (body.apiKey !== undefined || body.baseUrl !== undefined || body.model !== undefined) {
|
|
saveAIConfig({
|
|
apiKey: body.apiKey,
|
|
baseUrl: body.baseUrl,
|
|
model: body.model,
|
|
});
|
|
}
|
|
}
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
message: "配置已保存",
|
|
});
|
|
} catch (error) {
|
|
return NextResponse.json(
|
|
{ success: false, error: "保存失败" },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|