9
0
mirror of https://github.com/Lomanic/presence-button-web synced 2024-11-22 21:47:29 +00:00

💕🍠 Checkpoint

./server.js:933874/12086
This commit is contained in:
Glitch (hello-express) 2019-11-03 19:43:00 +00:00
parent b98583d32d
commit 3f0b9967cc

View File

@ -8,10 +8,10 @@ const db = "./.data/data.json";
try { try {
var content = fs.readFileSync(db, "utf8"); var content = fs.readFileSync(db, "utf8");
fuzIsOpen = JSON.parse(content)["fuzIsOpen"]; fuzIsOpen = JSON.parse(content)["fuzIsOpen"] || fuzIsOpen;
lastSeen = new Date(JSON.parse(content)["lastSeen"]); lastSeen = new Date(JSON.parse(content)["lastSeen"] || lastSeen);
lastNofified = new Date(JSON.parse(content)["lastNofified"]); lastNofified = new Date(JSON.parse(content)["lastNofified"] || lastNofified);
lastClosed = new Date(JSON.parse(content)["lastClosed"]); lastClosed = new Date(JSON.parse(content)["lastClosed"] || lastClosed);
} catch (err) {} } catch (err) {}
const express = require("express"); const express = require("express");
@ -73,11 +73,14 @@ const listener = app.listen(process.env.PORT, function() {
console.log("Your app is listening on port " + listener.address().port); console.log("Your app is listening on port " + listener.address().port);
}); });
setTimeout(() => { const loop = () => {
if (!fuzIsOpen || lastSeen < new Date() - 2 * 60 * 1000) { console.log("loop", lastClosed);
if (lastSeen < new Date() - 2 * 60 * 1000 && lastClosed < lastSeen) {
lastClosed = new Date();
} }
}, 10 * 1000) setTimeout(loop, 10 * 1000);
};
setTimeout(loop, 1 * 1000); // give some time for presence button to show up (1 min)
if (process.env.PROJECT_DOMAIN != "") { if (process.env.PROJECT_DOMAIN != "") {
process.on("SIGTERM", function() { process.on("SIGTERM", function() {