{"version":3,"file":"_server.ts-E0wsS0-8.js","sources":["../../../.svelte-kit/adapter-node/entries/endpoints/log/export/_server.ts.js"],"sourcesContent":["import { resolve } from \"path\";\nimport { readdirSync, readFileSync } from \"fs\";\nimport ExcelJS from \"exceljs\";\nimport { format } from \"date-fns\";\nasync function combineJSONToExcel() {\n const logsDirectory = resolve(\"/logs/llama\");\n const jsonFiles = readdirSync(logsDirectory).filter((file) => file.endsWith(\".json\"));\n if (jsonFiles.length === 0) {\n console.log(\"No JSON files found.\");\n return;\n }\n const workbook = new ExcelJS.Workbook();\n const worksheet = workbook.addWorksheet(\"Combined Data\");\n worksheet.addRow([\"Request\", \"Response\"]);\n for (const jsonFile of jsonFiles) {\n const filePath = resolve(logsDirectory, jsonFile);\n const jsonContent = readFileSync(filePath, \"utf-8\");\n const jsonData = JSON.parse(jsonContent);\n worksheet.addRow([\n jsonData.request,\n jsonData.response,\n jsonFile.replace(\".json\", \"\")\n ]);\n }\n const buffer = await workbook.xlsx.writeBuffer();\n return buffer;\n}\nconst GET = async ({ locals, request }) => {\n try {\n const excelBuffer = await combineJSONToExcel();\n const currentDate = /* @__PURE__ */ new Date();\n const formattedDate = format(currentDate, \"yyyy-MM-dd\");\n const filename = `llm-queries-${formattedDate}.xlsx`;\n return new Response(excelBuffer, {\n headers: {\n \"Content-Type\": \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\",\n \"Content-Disposition\": \"attachment; filename=\" + filename\n }\n });\n } catch (e) {\n return new Response(\n JSON.stringify({ success: false, error: e.message }),\n {\n headers: { \"Content-Type\": \"application/json\" }\n }\n );\n }\n};\nexport {\n GET\n};\n"],"names":[],"mappings":";;;;;AAIA,eAAe,kBAAkB,GAAG;AACpC,EAAE,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAC/C,EAAE,MAAM,SAAS,GAAG,WAAW,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,QAAQ,CAAC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