- Webservice-Antworten werden nun korrekt mit vorherigen Daten verglichen - Bei Änderungen wird automatisch eine neue JSON-Datei unter /debug erstellt - Keine Datei-Erstellung bei identischen Antworten - Funktion `saveJsonIfChanged` erfolgreich in utils/websocket ausgelagert
33 lines
977 B
JavaScript
33 lines
977 B
JavaScript
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
function saveJsonIfChanged(newJson, lastStatisRef) {
|
|
const newStatis = newJson?.Statis || [];
|
|
|
|
const hasChanged =
|
|
newStatis.length !== lastStatisRef.length ||
|
|
newStatis.some((entry, index) => {
|
|
const prev = lastStatisRef[index];
|
|
return (
|
|
!prev ||
|
|
entry.Modul !== prev.Modul ||
|
|
entry.ModulName !== prev.ModulName ||
|
|
entry.Value !== prev.Value ||
|
|
entry.Level !== prev.Level
|
|
);
|
|
});
|
|
|
|
if (hasChanged) {
|
|
lastStatisRef.splice(0, lastStatisRef.length, ...newStatis);
|
|
|
|
const outputPath = path.join(process.cwd(), "debug", `webserviceDump-${Date.now()}.json`);
|
|
fs.mkdirSync(path.dirname(outputPath), { recursive: true });
|
|
fs.writeFileSync(outputPath, JSON.stringify(newJson, null, 2), "utf-8");
|
|
console.log("📝 Webservice-Daten wurden gespeichert:", outputPath);
|
|
}
|
|
|
|
return hasChanged;
|
|
}
|
|
|
|
module.exports = { saveJsonIfChanged };
|