9
0
mirror of https://github.com/Lomanic/presence-button-web synced 2024-11-22 13:37: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 {
var content = fs.readFileSync(db, "utf8");
fuzIsOpen = JSON.parse(content)["fuzIsOpen"];
lastSeen = new Date(JSON.parse(content)["lastSeen"]);
lastNofified = new Date(JSON.parse(content)["lastNofified"]);
lastClosed = new Date(JSON.parse(content)["lastClosed"]);
fuzIsOpen = JSON.parse(content)["fuzIsOpen"] || fuzIsOpen;
lastSeen = new Date(JSON.parse(content)["lastSeen"] || lastSeen);
lastNofified = new Date(JSON.parse(content)["lastNofified"] || lastNofified);
lastClosed = new Date(JSON.parse(content)["lastClosed"] || lastClosed);
} catch (err) {}
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);
});
setTimeout(() => {
if (!fuzIsOpen || lastSeen < new Date() - 2 * 60 * 1000) {
const loop = () => {
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 != "") {
process.on("SIGTERM", function() {