File size: 1,298 Bytes
88c4c60 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | import { NextResponse } from "next/server";
import fs from "fs";
import path from "path";
export async function POST(request) {
try {
const { file, content } = await request.json();
if (!file || content === undefined) {
return NextResponse.json({ success: false, error: "File and content required" }, { status: 400 });
}
// Security: only allow specific filenames
const allowedFiles = [
"1_req_client.json",
"2_req_source.json",
"3_req_openai.json",
"4_req_target.json",
"5_res_provider.txt",
"6_res_openai.txt",
"7_res_client.txt",
"7_res_client.json",
];
if (!allowedFiles.includes(file)) {
return NextResponse.json({ success: false, error: "Invalid file name" }, { status: 400 });
}
const logsDir = path.join(process.cwd(), "logs", "translator");
// Create directory if not exists
if (!fs.existsSync(logsDir)) {
fs.mkdirSync(logsDir, { recursive: true });
}
const filePath = path.join(logsDir, file);
fs.writeFileSync(filePath, content, "utf-8");
return NextResponse.json({ success: true });
} catch (error) {
console.error("Error saving file:", error);
return NextResponse.json({ success: false, error: error.message }, { status: 500 });
}
}
|