-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.js
51 lines (45 loc) · 1.27 KB
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const router = require("express").Router();
const fs = require("fs");
const { config, hash } = require("./util");
router.get("/config", (req, res) => {
res.json(config());
});
router.get("/translation", (req, res) => {
res.json(
JSON.parse(
fs.readFileSync(
`translations/${config("language") || "en"}.json`,
"utf-8"
)
)
);
});
router.get("/permissions", (req, res) => {
if (!fs.existsSync(`secrets/${hash(req.query.token)}.json`)) {
res.status(403).json([]);
return;
}
let info = JSON.parse(
fs.readFileSync(`secrets/${hash(req.query.token)}.json`, "utf-8")
);
res.json(info.permissions);
});
router.get("/plan/:day", (req, res) => {
if (!fs.existsSync(`plan/${req.params.day}`)) {
res.status(404).json([]);
return;
}
let data = fs.readdirSync(`plan/${req.params.day}`);
if (data.length == 0) {
res.status(404).json([]);
return;
}
data = data.sort().reverse();
res.json({
updated: fs.statSync(`plan/${req.params.day}/${data[0]}`).mtimeMs || "-",
plan: JSON.parse(
fs.readFileSync(`plan/${req.params.day}/${data[0]}`, "utf-8")
),
});
});
module.exports = router;