import { d as private_env } from './shared-server-49TKSBDM.js'; import { resolve } from 'path'; import { readdirSync, readFileSync } from 'fs'; import ExcelJS from 'exceljs'; import { format } from 'date-fns'; async function combineJSONToExcel() { const logsDirectory = resolve(private_env.LOGS_ROOT_FOLDER + "/llama"); const jsonFiles = readdirSync(logsDirectory).filter((file) => file.endsWith(".json")); if (jsonFiles.length === 0) { console.log("No JSON files found."); return; } const workbook = new ExcelJS.Workbook(); const worksheet = workbook.addWorksheet("Combined Data"); worksheet.addRow(["Request", "Response"]); for (const jsonFile of jsonFiles) { const filePath = resolve(logsDirectory, jsonFile); const jsonContent = readFileSync(filePath, "utf-8"); const jsonData = JSON.parse(jsonContent); worksheet.addRow([ jsonData.request, jsonData.response, jsonFile.replace(".json", "") ]); } const buffer = await workbook.xlsx.writeBuffer(); return buffer; } const GET = async ({ locals, request }) => { try { const excelBuffer = await combineJSONToExcel(); const currentDate = /* @__PURE__ */ new Date(); const formattedDate = format(currentDate, "yyyy-MM-dd"); const filename = `llm-queries-${formattedDate}.xlsx`; return new Response(excelBuffer, { headers: { "Content-Type": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Content-Disposition": "attachment; filename=" + filename } }); } catch (e) { return new Response( JSON.stringify({ success: false, error: e.message }), { headers: { "Content-Type": "application/json" } } ); } }; export { GET }; //# sourceMappingURL=_server.ts-raOsdHbt.js.map