1
0
mirror of https://api.glitch.com/git/presence-button synced 2024-12-05 02:37: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 {
var content = fs.readFileSync(db, "utf8");
fuzIsOpen = JSON.parse(content)[""]
fuzIsOpen = JSON.parse(content)["fuzIsOpen"];
lastSeen = new Date(JSON.parse(content)["lastSeen"]);
} catch (err) {}
console.log(JSON.stringify({ fuzIsOpen, lastSeen }));
const express = require("express");
const app = express();
@ -23,18 +25,25 @@ app.get("/", (req, res) => {
// http://expressjs.com/en/starter/basic-routing.html
app.get("/img", (req, res) => {
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
app.get("/status", (req, res) => {
if (req.query.password !== process.env.PASSWORD) {
return res.sendStatus(401);
}
if (req.query.fuzisopen === "1") {
fuzIsOpen = true;
}
fuzIsOpen = req.query.fuzisopen === "1";
lastSeen = Date();
try {
fs.writeFileSync(db, JSON.stringify({ fuzIsOpen, lastSeen }));
} catch (err) {}
res.sendStatus(200);
});