From aa844560546c2a7c4c5ab3f74217130dc28be6ff Mon Sep 17 00:00:00 2001 From: Aelita4 Date: Wed, 17 Aug 2022 12:13:29 +0200 Subject: [PATCH] Add downtime counter --- src/index.js | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index d5120d1..a39b869 100644 --- a/src/index.js +++ b/src/index.js @@ -12,12 +12,15 @@ const ping = async host => { const app = new express(); -app.get("/", async (req, res) => { - if(!fs.existsSync("data.json")) fs.writeFileSync("data.json", "[]"); - const addresses = JSON.parse(fs.readFileSync("./data.json", {encoding:'utf8', flag:'r'})) +const pings = new Map(); - const timeoutDelay = 60000; - +if(!fs.existsSync("data.json")) fs.writeFileSync("data.json", "[]"); +let addresses = JSON.parse(fs.readFileSync("./data.json", {encoding:'utf8', flag:'r'})) +addresses.forEach(a => pings.set(a, -1)); +const timeoutDelay = 60000; + +app.get("/", async (req, res) => { + addresses = JSON.parse(fs.readFileSync("./data.json", {encoding:'utf8', flag:'r'})) let out = `