-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
68 lines (59 loc) · 1.51 KB
/
index.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const express = require("express");
const fs = require("fs");
const app = express();
app.use(express.json());
app.get("/", (req, res) => {
res.sendFile(__dirname + `/public/landing.html`);
});
app.use(express.static("public"));
app.get("/:roomname", (req, res) => {
res.sendFile(__dirname + `/public/index.html`);
});
app.get("/:roomname/screenshare", (req, res) => {
res.sendFile(__dirname + `/public/screenshare/index.html`);
});
const logFiles = fs.readdirSync("./public/logs");
let logIndex = logFiles.length;
app.post("/report", (req, res) => {
const { problem, logs, userId } = req.body;
let fileName = req.body.fileName;
if (problem) {
let logContent = {
recordedAt: Date.now(),
problem,
reporter: userId,
};
logContent[userId] = logs;
fileName = `${logIndex}.json`;
fs.writeFile(
`./public/logs/${fileName}`,
JSON.stringify(logContent, null, 2),
() => {}
);
logIndex += 1;
return res.json({
url: `/logs/${fileName}`,
fileName,
});
}
fs.readFile(`./public/logs/${fileName}`, (err, data) => {
if (err) {
return res.json({
status: "unsuccessful",
});
}
const existingLogs = JSON.parse(data);
existingLogs[userId] = logs;
fs.writeFile(
`./public/logs/${fileName}`,
JSON.stringify(existingLogs, null, 2),
() => {}
);
return res.json({
status: "successful",
});
});
});
app.listen(3006, () => {
console.log("listening on *:3006, webrtc.songz.dev");
});