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:
@@ -0,0 +1,65 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import pool from "@/lib/database";
|
||||
|
||||
// 更新词组
|
||||
export async function PATCH(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params;
|
||||
const body = await request.json();
|
||||
const { word, english } = body;
|
||||
|
||||
if (!word || !english) {
|
||||
return NextResponse.json(
|
||||
{ error: "中文和英文翻译不能为空" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
await pool.execute("UPDATE words SET word = ?, english = ? WHERE id = ?", [
|
||||
word.trim(),
|
||||
english.trim(),
|
||||
parseInt(id),
|
||||
]);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: {
|
||||
id: parseInt(id),
|
||||
word: word.trim(),
|
||||
english: english.trim(),
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Database error:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "更新失败", details: String(error) },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 删除词组
|
||||
export async function DELETE(
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params;
|
||||
|
||||
await pool.execute("DELETE FROM words WHERE id = ?", [parseInt(id)]);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "删除成功",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Database error:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "删除失败", details: String(error) },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user