Add chat endpoint
Adds an endpoint for fetching the 10 most recent messages from #osu
This commit is contained in:
parent
4d062101f0
commit
776b06af36
2 changed files with 56 additions and 7 deletions
28
Binato.js
28
Binato.js
|
@ -16,13 +16,29 @@ app.use((req, res) => {
|
||||||
req.on("end", () => {
|
req.on("end", () => {
|
||||||
switch (req.method) {
|
switch (req.method) {
|
||||||
case "GET":
|
case "GET":
|
||||||
fs.readFile("serverPage.html", (err, data) => {
|
if (req.url == "/" || req.url == "/index.html" || req.url == "/index.html") {
|
||||||
if (err) throw err;
|
fs.readFile("./web/serverPage.html", (err, data) => {
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
if (debugMode) data = data.toString().replace("|isdebug?|", '<b style="color:red;">DEBUG</b>');
|
if (debugMode) data = data.toString().replace("|isdebug?|", '<b style="color:red;">DEBUG</b>');
|
||||||
else data = data.toString().replace("|isdebug?|", '');
|
else data = data.toString().replace("|isdebug?|", '');
|
||||||
res.send(data);
|
res.send(data);
|
||||||
});
|
});
|
||||||
|
} else if (req.url == "/chat") {
|
||||||
|
fs.readFile("./web/chatPageTemplate.html", (err, data) => {
|
||||||
|
if (err) throw err;
|
||||||
|
|
||||||
|
let lines = "", flip = false;
|
||||||
|
const limit = global.chatHistory.length < 10 ? 10 : global.chatHistory.length;
|
||||||
|
for (let i = global.chatHistory.length - 10; i < limit; i++) {
|
||||||
|
if (i < 0) i = 0;
|
||||||
|
lines += `<div class="line line${flip ? 1 : 0}">${global.chatHistory[i] == null ? "<hidden>blank</hidden>" : global.chatHistory[i]}</div>`
|
||||||
|
flip = !flip;
|
||||||
|
}
|
||||||
|
|
||||||
|
res.send(data.toString().replace("|content|", lines));
|
||||||
|
});
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "POST":
|
case "POST":
|
||||||
|
|
33
web/chatPageTemplate.html
Normal file
33
web/chatPageTemplate.html
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
.container {
|
||||||
|
width: 482px;
|
||||||
|
height: 165px;
|
||||||
|
}
|
||||||
|
|
||||||
|
hidden {
|
||||||
|
visibility: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.line {
|
||||||
|
padding: 2px;
|
||||||
|
font-size: 8pt;
|
||||||
|
font-family: sans-serif;
|
||||||
|
}
|
||||||
|
|
||||||
|
.line0 {
|
||||||
|
background-color: #edebfa;
|
||||||
|
}
|
||||||
|
|
||||||
|
.line1 {
|
||||||
|
background-color: #e3e1fa;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="container">
|
||||||
|
|content|
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in a new issue