This commit is contained in:
Ismail Ali
2025-06-26 22:56:20 +02:00
parent 137839da98
commit b9651a53a9
82 changed files with 7476 additions and 4171 deletions

View File

@@ -9,7 +9,7 @@ export default async function handler(
res: NextApiResponse
) {
try {
const result: Record<number, any[]> = {};
const result: Record<number, unknown[]> = {};
for (let i = 1; i <= 8; i++) {
const filePath = path.join(
@@ -22,10 +22,11 @@ export default async function handler(
try {
const fileContent = await fs.readFile(filePath, "utf-8");
result[99 + i] = JSON.parse(fileContent); // z.B. 100 für AE1, 101 für AE2
} catch (err) {
result[99 + i] = JSON.parse(fileContent); // z. B. 100 für AE1, 101 für AE2
} catch (error) {
console.warn(
`Mock-Datei für analogInput${i} nicht gefunden oder fehlerhaft.`
`Mock-Datei für analogInput${i} nicht gefunden oder fehlerhaft.`,
error
);
result[99 + i] = [];
}

View File

@@ -1,4 +1,4 @@
// /pages/api/cpl/getDigitalOutputsJsonHandler.ts
// /pages/api/cpl/getDigitalOutputsHandler.ts
import { NextApiRequest, NextApiResponse } from "next";
import path from "path";
@@ -12,7 +12,7 @@ export default async function handler(
const mode = process.env.NEXT_PUBLIC_CPL_MODE ?? "json";
if (mode === "json") {
// Lese JSON-Datei z.B. digitalOutputsMockData.json
// Lese JSON-Datei z.B. digitalOutputsMockData.json
const filePath = path.join(
process.cwd(),
"mocks/api/SERVICE/digitalOutputsMockData.json"

View File

@@ -20,6 +20,10 @@ export default async function handler(
const data = await fs.readFile(filePath, "utf-8");
res.status(200).send(data);
} catch (error) {
res.status(404).json({ error: "File not found" });
console.error(
"Fehler bei der Verarbeitung von kabelueberwachungAPIHandler:",
error
);
res.status(500).json({ error: "Interner Serverfehler" });
}
}

View File

@@ -21,6 +21,7 @@ export default async function handler(
res.setHeader("Content-Type", "text/javascript"); // wichtig!
res.status(200).send(data);
} catch (error) {
res.status(404).json({ error: "File not found" });
console.error("Fehler beim Laden der letzten 20 Meldungen:", error);
res.status(500).json({ error: "Interner Serverfehler" });
}
}

View File

@@ -6,6 +6,13 @@ import { promises as fs } from "fs";
function parseDate(str: string): Date {
return new Date(str.replace(" ", "T"));
}
export type Message = {
id: number;
timestamp: string;
text: string;
level: string;
// oder alles, was dein `result` konkret enthält
};
export default async function handler(
req: NextApiRequest,
@@ -38,8 +45,8 @@ export default async function handler(
}
if (fromDate && toDate) {
const filtered = data.filter((msg: any) => {
const messageDate = parseDate(msg.t);
const filtered = data.filter((msg: Message) => {
const messageDate = parseDate(msg.timestamp);
return messageDate >= fromDate! && messageDate <= toDate!;
});

View File

@@ -20,6 +20,7 @@ export default async function handler(
const data = await fs.readFile(filePath, "utf-8");
res.status(200).send(data);
} catch (error) {
console.error("Error processing opcuaAPIHandler:", error);
res.status(404).json({ error: "File not found" });
}
}

View File

@@ -3,10 +3,24 @@ import { NextApiRequest, NextApiResponse } from "next";
import path from "path";
import fs from "fs/promises";
// Typ für einzelne Einträge im JSON-Array
type ChartDataEntry = {
timestamp?: string;
zeit?: string;
time?: string;
[key: string]: unknown; // zusätzliche Werte erlaubt
};
// Hilfsfunktion: JSON-Datei laden
async function loadJsonData(filePath: string) {
async function loadJsonData(filePath: string): Promise<ChartDataEntry[]> {
const data = await fs.readFile(filePath, "utf8");
return JSON.parse(data);
const parsed = JSON.parse(data);
if (!Array.isArray(parsed)) {
throw new Error("Ungültiges Format: Erwartet ein Array");
}
return parsed;
}
export default async function handler(
@@ -32,20 +46,23 @@ export default async function handler(
try {
const jsonData = await loadJsonData(jsonFilePath);
// Filtern nach Datum, wenn angegeben
let filteredData = jsonData;
if (vonDatum && bisDatum) {
const von = new Date(`${vonDatum}T00:00:00`);
const bis = new Date(`${bisDatum}T23:59:59`);
filteredData = jsonData.filter((item: any) => {
const timestamp = new Date(item.t);
return timestamp >= von && timestamp <= bis;
filteredData = jsonData.filter((item) => {
const dateString = item.timestamp ?? item.zeit ?? item.time;
const itemDate = dateString ? new Date(dateString) : null;
return itemDate !== null && itemDate >= von && itemDate <= bis;
});
}
return res.status(200).json(filteredData);
res.status(200).json(filteredData);
} catch (error) {
return res.status(404).json({ error: "File not found or read error" });
console.error("Fehler beim Lesen der Slot-Daten:", error);
res.status(500).json({ error: "Fehler beim Lesen der Slot-Daten" });
}
}

View File

@@ -20,6 +20,7 @@ export default async function handler(
const data = await fs.readFile(filePath, "utf-8");
res.status(200).send(data);
} catch (error) {
console.error("Error processing systemAPIHandler:", error);
res.status(404).json({ error: "File not found" });
}
}

View File

@@ -20,6 +20,7 @@ export default async function handler(
const data = await fs.readFile(filePath, "utf-8");
res.status(200).send(data);
} catch (error) {
console.error("Error processing systemVoltTempAPIHandler:", error);
res.status(404).json({ error: "File not found" });
}
}

View File

@@ -26,6 +26,7 @@ export default async function handler(
const data = await fs.readFile(filePath, "utf-8");
res.status(200).json(JSON.parse(data));
} catch (error) {
console.error("Error processing tdmDataAPIHandler:", error);
res.status(404).json({ error: "File not found" });
}
}

View File

@@ -26,6 +26,7 @@ export default async function handler(
const data = await fs.readFile(filePath, "utf-8");
res.status(200).json(JSON.parse(data));
} catch (error) {
console.error("Error processing tdrDataAPIHandler:", error);
res.status(404).json({ error: "File not found" });
}
}

View File

@@ -21,6 +21,7 @@ export default async function handler(
const fileContent = await fs.readFile(filePath, "utf-8");
res.status(200).json(JSON.parse(fileContent));
} catch (error) {
console.error("Error processing tdrReferenceCurveAPIHandler:", error);
res.status(404).json({ error: "File not found" });
}
}

View File

@@ -34,7 +34,6 @@ if (!mockFilePath) {
// Funktion zum Parsen bei jsSimulatedProd
function extractMockData(raw: string) {
const context = {};
const func = new Function(
"context",
`
@@ -81,11 +80,9 @@ export default async function handler(
const rawContent = fs.readFileSync(mockFilePath!, "utf-8");
// 3⃣ JSON vs JS Verarbeitung
const data =
mode === "json" ? JSON.parse(rawContent) : extractMockData(rawContent);
// 4⃣ Aktualisieren der Felder
if (typeof label === "string") data.win_de_label[id - 1] = label;
if (typeof invert === "number") data.win_de_invert[id - 1] = invert;
if (typeof timeFilter === "number")
@@ -97,7 +94,6 @@ export default async function handler(
if (typeof eingangOffline === "number")
data.win_de_offline[id - 1] = eingangOffline;
// 5⃣ Speichern
if (mode === "json") {
fs.writeFileSync(mockFilePath!, JSON.stringify(data, null, 2), "utf-8");
} else {
@@ -128,8 +124,12 @@ var win_de_label = ${JSON.stringify(data.win_de_label, null, 2)};
weighting,
eingangOffline,
});
} catch (err: any) {
console.error("Fehler beim Schreiben:", err);
} catch (err: unknown) {
if (err instanceof Error) {
console.error("Fehler beim Schreiben:", err.message);
} else {
console.error("Unbekannter Fehler beim Schreiben:", err);
}
return res.status(500).json({ error: "Update fehlgeschlagen" });
}
}

View File

@@ -6,7 +6,7 @@ export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
let { key, value, slot } = req.query;
const { key, value, slot } = req.query;
if (
typeof key !== "string" ||

View File

@@ -29,6 +29,7 @@ export default async function handler(
await fs.writeFile(filePath, JSON.stringify(data, null, 2), "utf-8");
res.status(200).json({ success: true });
} catch (error) {
console.error("Error processing updateTdrReferenceCurveAPIHandler:", error);
res.status(500).json({ error: "Failed to save file" });
}
}

View File

@@ -32,7 +32,7 @@ export default async function handler(
}
const arrayRaw = match[0].match(/\[(.*)\]/s)?.[1] || "";
let values = arrayRaw
const values = arrayRaw
.split(",")
.map((v) => v.trim())
.map((v) => (v === "" ? "0" : v))
@@ -45,10 +45,7 @@ export default async function handler(
}
// Bereinige kaputte Endzeilen wie ")"
fileContent = fileContent.replace(
/^\s*[\)\(a-zA-Z0-9\/\:\. ]{2,40}\s*$/gm,
""
);
fileContent = fileContent.replace(/^\s*[)(a-zA-Z0-9/:. ]{2,40}\s*$/gm, "");
await fs.writeFile(filePath, fileContent, "utf-8");