mirror of
https://github.com/Lomanic/presence-button-web
synced 2024-11-22 21:47:29 +00:00
🙅👛 Checkpoint
./server.js:933874/10152
This commit is contained in:
parent
840560b793
commit
0845a22b8d
19
server.js
19
server.js
@ -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);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user