9
0
mirror of https://github.com/Lomanic/presence-button-web synced 2024-11-23 05:57:30 +00:00

🙅👛 Checkpoint

./server.js:933874/10152
This commit is contained in:
Glitch (hello-express) 2019-11-03 11:56:59 +00:00
parent 840560b793
commit 0845a22b8d

View File

@ -6,9 +6,11 @@ const db = "./.data/data.json";
try { try {
var content = fs.readFileSync(db, "utf8"); var content = fs.readFileSync(db, "utf8");
fuzIsOpen = JSON.parse(content)[""] fuzIsOpen = JSON.parse(content)["fuzIsOpen"];
lastSeen = new Date(JSON.parse(content)["lastSeen"]);
} catch (err) {} } catch (err) {}
console.log(JSON.stringify({ fuzIsOpen, lastSeen }));
const express = require("express"); const express = require("express");
const app = express(); const app = express();
@ -23,18 +25,25 @@ app.get("/", (req, res) => {
// http://expressjs.com/en/starter/basic-routing.html // http://expressjs.com/en/starter/basic-routing.html
app.get("/img", (req, res) => { app.get("/img", (req, res) => {
res.sendFile(__dirname + "/views/index.html"); res.sendFile(__dirname + "/views/index.html");
if (fuzIsOpen) { if (fuzIsOpen && Date() - 5 * 60 * 1000 < lastSeen) {
} }
}); });
app.get("/api", (req, res) => {
res.send(fuzIsOpen && Date() - 5 * 1000 < lastSeen)
});
// http://expressjs.com/en/starter/basic-routing.html // http://expressjs.com/en/starter/basic-routing.html
app.get("/status", (req, res) => { app.get("/status", (req, res) => {
if (req.query.password !== process.env.PASSWORD) { if (req.query.password !== process.env.PASSWORD) {
return res.sendStatus(401); return res.sendStatus(401);
} }
if (req.query.fuzisopen === "1") { fuzIsOpen = req.query.fuzisopen === "1";
fuzIsOpen = true; lastSeen = Date();
} try {
fs.writeFileSync(db, JSON.stringify({ fuzIsOpen, lastSeen }));
} catch (err) {}
res.sendStatus(200); res.sendStatus(200);
}); });