030fce2813
- Add export configuration (untranslated text color, page orientation) - Add second page header option for multi-page exports - Integrate export settings into main export flow - Separate export settings page with visual preview
62 lines
1.6 KiB
TypeScript
62 lines
1.6 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { getConfig, saveDBConfig, saveAIConfig, saveExportConfig, type DBConfig, type AIConfig, type ExportConfig } 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?: ExportConfig }
|
|
export async function POST(request: Request) {
|
|
try {
|
|
const body = await request.json();
|
|
const { db, ai, export: exportConfig } = body;
|
|
|
|
if (db) {
|
|
saveDBConfig(db);
|
|
}
|
|
|
|
if (ai) {
|
|
saveAIConfig(ai);
|
|
}
|
|
|
|
if (exportConfig) {
|
|
saveExportConfig(exportConfig);
|
|
}
|
|
|
|
// 如果同时发送了完整配置
|
|
if (!db && !ai && !exportConfig && body.db === undefined && body.ai === undefined && body.export === 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 }
|
|
);
|
|
}
|
|
}
|