File size: 1,359 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 46 | import { NextResponse } from "next/server";
import fs from "fs";
import path from "path";
export async function GET(request) {
try {
const { searchParams } = new URL(request.url);
const file = searchParams.get("file");
if (!file) {
return NextResponse.json({ success: false, error: "File parameter 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");
const filePath = path.join(logsDir, file);
// Check if file exists
if (!fs.existsSync(filePath)) {
return NextResponse.json({ success: false, error: "File not found" }, { status: 404 });
}
const content = fs.readFileSync(filePath, "utf-8");
return NextResponse.json({ success: true, content });
} catch (error) {
console.error("Error loading file:", error);
return NextResponse.json({ success: false, error: error.message }, { status: 500 });
}
}
|