forked from macedonga/lofi.twitch.auto.stream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
39 lines (30 loc) · 1 KB
/
server.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
const express = require("express");
const osu = require("node-os-utils");
const stream = require("./stream");
const cpu = osu.cpu;
const mem = osu.mem;
const netstat = osu.netstat;
const os = osu.os;
const app = express();
app.set("view engine", "ejs");
app.get("/", async (req, res) => {
const cpuPerc = await cpu.usage();
const ramPerc = await mem.info();
const uptime = await os.uptime();
res.render("index", { cpu: cpuPerc, ram: 100 - ramPerc.freeMemPercentage, uptime: uptime, started: stream.Started });
});
app.get("/start", (req, res) => {
if (req.headers.authorization == process.env.AUTH) {
if (stream.Started) stream.Stop();
else stream.Start();
return res.send({ message: "Ok!" });
} else return res.send({ message: "Wrong key!" });
});
app.get("/bkg", (req, res) => {
res.sendFile(__dirname + "/assets/bkg.gif");
})
module.exports.Listen = (PORT) => {
app.listen(PORT, () => {
console.log(`Listening on http://localhost:${PORT}`);
});
}