Files
harheimertc/.output/server/chunks/routes/api/termine.get.mjs

66 lines
1.8 KiB
JavaScript

import { d as defineEventHandler } from '../../nitro/nitro.mjs';
import { promises } from 'fs';
import path from 'path';
import 'node:http';
import 'node:https';
import 'node:events';
import 'node:buffer';
import 'node:fs';
import 'node:path';
import 'node:crypto';
import 'node:url';
const termine_get = defineEventHandler(async (event) => {
try {
const cwd = process.cwd();
let csvPath;
if (cwd.endsWith(".output")) {
csvPath = path.join(cwd, "../public/data/termine.csv");
} else {
csvPath = path.join(cwd, "public/data/termine.csv");
}
const csv = await promises.readFile(csvPath, "utf-8");
const lines = csv.split("\n").filter((line) => line.trim() !== "");
if (lines.length < 2) {
return { success: true, termine: [] };
}
const termine = [];
for (let i = 1; i < lines.length; i++) {
const values = [];
let current = "";
let inQuotes = false;
for (let j = 0; j < lines[i].length; j++) {
const char = lines[i][j];
if (char === '"') {
inQuotes = !inQuotes;
} else if (char === "," && !inQuotes) {
values.push(current.trim());
current = "";
} else {
current += char;
}
}
values.push(current.trim());
if (values.length >= 4) {
termine.push({
datum: values[0],
uhrzeit: values[1] || "",
titel: values[2] || "",
beschreibung: values[3] || "",
kategorie: values[4] || "Sonstiges"
});
}
}
return {
success: true,
termine
};
} catch (error) {
console.error("Fehler beim Laden der Termine:", error);
return { success: true, termine: [] };
}
});
export { termine_get as default };
//# sourceMappingURL=termine.get.mjs.map