feat: add recipe translation tool with AI translation and settings management

- 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
This commit is contained in:
2026-04-12 23:50:54 +08:00
parent 57e119635e
commit a249fb038c
24 changed files with 3383 additions and 70 deletions
+57
View File
@@ -0,0 +1,57 @@
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 }
);
}
}