- Der Schalter zum Aktivieren/Deaktivieren der TDR-Funktion ist nun nur für Admins sichtbar. - Umsetzung über `useAdminAuth` analog zum Firmware-Update-Button. - CHANGELOG.md und README.md entsprechend aktualisiert.
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
// /utils/goTDR.ts
|
|
export const goTDR = async (
|
|
slotIndex: number,
|
|
setLoading: (loading: boolean) => void
|
|
) => {
|
|
if (slotIndex >= 32) return;
|
|
|
|
setLoading(true);
|
|
|
|
// ✅ ENV-Variable prüfen (funktioniert nur mit NEXT_PUBLIC_)
|
|
const isMock = process.env.NEXT_PUBLIC_USE_MOCK_BACKEND_TDR_START === "true";
|
|
|
|
if (isMock) {
|
|
// 🔁 MOCK-MODUS
|
|
try {
|
|
const response = await fetch(
|
|
`/api/cpl/tdrMessungStartenMockHandler?slot=${slotIndex + 1}`
|
|
);
|
|
const data = await response.json();
|
|
|
|
alert(`(MOCK) ${data.message}`);
|
|
console.log("(MOCK)", data.message);
|
|
} catch (error) {
|
|
console.error("(MOCK) Fehler:", error);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
return;
|
|
}
|
|
|
|
// 🚀 ECHTER Backend-Aufruf über CGI
|
|
try {
|
|
const response = await fetch(
|
|
`${window.location.origin}/CPL?kabelueberwachung.html&KTT${slotIndex}=1`,
|
|
{
|
|
method: "GET",
|
|
}
|
|
);
|
|
|
|
if (response.ok) {
|
|
alert(
|
|
`Die TDR-Messung wird durchgeführt. Das Messergebnis ist in wenigen Minuten verfügbar.`
|
|
);
|
|
console.log("TDR erfolgreich gestartet für Slot", slotIndex + 1);
|
|
} else {
|
|
console.error("Fehler beim Senden der TDR-Anfrage");
|
|
}
|
|
} catch (error) {
|
|
console.error("Fehler:", error);
|
|
} finally {
|
|
setLoading(false);
|
|
}
|
|
};
|