{"version":3,"file":"_server.ts-NqmkUF0a.js","sources":["../../../.svelte-kit/adapter-node/entries/endpoints/log/response/export/excel/_server.ts.js"],"sourcesContent":["import { d as private_env } from \"../../../../../../chunks/shared-server.js\";\nimport { resolve } from \"path\";\nimport { readdirSync, readFileSync } from \"fs\";\nimport ExcelJS from \"exceljs\";\nimport { format } from \"date-fns\";\nasync function combineJSONToExcel() {\n const logsDirectory = resolve(private_env.LOGS_ROOT_FOLDER);\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([\"Prompt\", \"Template\", \"Search Results\", \"LLM Response\", \"User Score\", \"User Comment\", \"Timestamp\"]);\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.prompt,\n jsonData.template,\n jsonData.search_results,\n jsonData.llm_response,\n jsonData.user_score,\n jsonData.user_comment,\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 = `user-responses-${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":";;;;;;AAKA,eAAe,kBAAkB,GAAG;AACpC,EAA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