wip digitale Eingänge sind sichtbar aber keine Werte in Modal
This commit is contained in:
@@ -1,26 +0,0 @@
|
||||
// /pages/api/cpl/digitaleEingaengeAPIHandler.ts
|
||||
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
|
||||
export default async function handler(
|
||||
req: NextApiRequest,
|
||||
res: NextApiResponse
|
||||
) {
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
"apiMockData",
|
||||
"SERVICE",
|
||||
"digitaleEingaengeMockData.js"
|
||||
);
|
||||
|
||||
try {
|
||||
const data = await fs.readFile(filePath, "utf-8");
|
||||
|
||||
res.setHeader("Content-Type", "text/javascript"); // wichtig!
|
||||
res.status(200).send(data);
|
||||
} catch (error) {
|
||||
res.status(404).json({ error: "File not found" });
|
||||
}
|
||||
}
|
||||
63
pages/api/cpl/getDigitalInputsHandler.ts
Normal file
63
pages/api/cpl/getDigitalInputsHandler.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
// /pages/api/cpl/getDgitalInputsHandler.ts
|
||||
import fs from "fs";
|
||||
import path from "path";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
try {
|
||||
const mode = process.env.NEXT_PUBLIC_CPL_MODE;
|
||||
|
||||
if (mode === "json") {
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
"mocks",
|
||||
"api",
|
||||
"SERVICE",
|
||||
"digitalInputsMockData.json"
|
||||
);
|
||||
const fileContent = fs.readFileSync(filePath, "utf-8");
|
||||
const json = JSON.parse(fileContent);
|
||||
return res.status(200).json(json);
|
||||
}
|
||||
|
||||
if (mode === "jsmock") {
|
||||
const jsPath = path.join(
|
||||
process.cwd(),
|
||||
"mocks/device-cgi-simulator/SERVICE/digitalInputsMockData.js"
|
||||
);
|
||||
const fileContent = fs.readFileSync(jsPath, "utf-8");
|
||||
|
||||
const extractArray = (name: string) => {
|
||||
const match = fileContent.match(
|
||||
new RegExp(`var\\s+${name}\\s*=\\s*\\[([\\s\\S]*?)\\];`)
|
||||
);
|
||||
if (!match) throw new Error(`Feld ${name} nicht gefunden`);
|
||||
return match[1]
|
||||
.split(",")
|
||||
.map((s) => s.trim().replace(/^["']|["']$/g, ""));
|
||||
};
|
||||
|
||||
const data = {
|
||||
win_de_state: extractArray("win_de_state").map(Number),
|
||||
win_de_invert: extractArray("win_de_invert").map(Number),
|
||||
win_de_counter: extractArray("win_de_counter").map(Number),
|
||||
win_de_time_filter: extractArray("win_de_time_filter").map(Number),
|
||||
win_de_weighting: extractArray("win_de_weighting").map(Number),
|
||||
win_de_counter_active: extractArray("win_de_counter_active").map(
|
||||
Number
|
||||
),
|
||||
win_de_offline: extractArray("win_de_offline").map(Number),
|
||||
win_de_label: extractArray("win_de_label"),
|
||||
};
|
||||
|
||||
return res.status(200).json(data);
|
||||
}
|
||||
|
||||
return res.status(400).json({ error: "Ungültiger Modus" });
|
||||
} catch (error) {
|
||||
console.error("❌ Fehler beim Parsen der digitalen Eingänge:", error);
|
||||
return res
|
||||
.status(500)
|
||||
.json({ error: "Fehler beim Parsen der digitalen Eingänge" });
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// /pages/api/cpl/updateDigitaleEingaenge.ts
|
||||
// /pages/api/cpl/updateDigitalInputs.ts
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
import path from "path";
|
||||
import fs from "fs";
|
||||
@@ -8,7 +8,7 @@ const mockFilePath = path.join(
|
||||
process.cwd(),
|
||||
"apiMockData",
|
||||
"SERVICE",
|
||||
"digitaleEingaengeMockData.js"
|
||||
"digitalInputsMockData.js"
|
||||
);
|
||||
|
||||
// Funktion zum Parsen des JS-Datei-Inhalts in ein eval-fähiges Objekt
|
||||
Reference in New Issue
Block a user