2023-10-20 21:53:49 -05:00
|
|
|
const express = require('express'),
|
2023-11-16 19:29:22 -06:00
|
|
|
path = require('path'),
|
|
|
|
fs = require('fs'),
|
2024-02-28 09:09:44 -06:00
|
|
|
pageUpdater = require('./pageUpdater.js')
|
2023-10-20 21:53:49 -05:00
|
|
|
|
|
|
|
var app = express()
|
|
|
|
|
|
|
|
const PORT = process.env.PORT || 8080
|
|
|
|
|
2023-11-16 15:16:22 -06:00
|
|
|
const staticpath = path.join(__dirname, 'static')
|
|
|
|
|
2024-01-25 23:29:28 -06:00
|
|
|
var config = JSON.parse(fs.readFileSync(path.join(__dirname, 'config.json')))
|
|
|
|
|
2023-11-16 15:16:22 -06:00
|
|
|
app.listen(PORT, () => {
|
|
|
|
console.log("Violet's Purgatory is now listening on port: " + PORT)
|
2023-11-03 13:01:13 -05:00
|
|
|
})
|
|
|
|
|
2024-02-18 08:01:58 -06:00
|
|
|
var cachePath = path.join(staticpath, 'cached')
|
2024-03-03 21:44:49 -06:00
|
|
|
var fontPath = path.join(staticpath, "fonts")
|
2024-02-29 08:50:37 -06:00
|
|
|
|
2024-03-03 21:44:49 -06:00
|
|
|
app.use("/fonts", express.static(fontPath))
|
2024-03-08 10:49:47 -06:00
|
|
|
app.use("/cached", express.static(cachePath))
|
|
|
|
|
|
|
|
app.get("/disc", (req, res) => {
|
|
|
|
res.setHeader("X-Accel-Buffering", "no")
|
|
|
|
res.write(fs.readFileSync(path.join(__dirname, "resources/disc.html")))
|
|
|
|
|
|
|
|
var iterations = 0
|
|
|
|
var lastAct = null
|
|
|
|
|
|
|
|
function loop() {
|
|
|
|
var currentAct = pageUpdater.getActivities()
|
|
|
|
if (currentAct != lastAct) {
|
|
|
|
lastAct = currentAct
|
|
|
|
iterations += 1
|
|
|
|
res.write(`<div id="loop${iterations}">`)
|
|
|
|
res.write(currentAct.substring(currentAct.indexOf("<div")))
|
|
|
|
res.write(`</div>`)
|
|
|
|
res.write(`<style>#loop${iterations - 1} {display: none;}</style>`)
|
|
|
|
}
|
|
|
|
setTimeout(() => {
|
2024-03-08 10:55:02 -06:00
|
|
|
if (!res.closed) {
|
|
|
|
loop()
|
2024-03-08 11:13:38 -06:00
|
|
|
res.write(" ")
|
2024-03-08 10:55:02 -06:00
|
|
|
}
|
2024-03-08 10:50:31 -06:00
|
|
|
}, 1000);
|
2024-03-08 10:49:47 -06:00
|
|
|
}
|
|
|
|
loop()
|
|
|
|
})
|
2024-03-03 21:44:49 -06:00
|
|
|
|
2024-02-18 08:01:58 -06:00
|
|
|
if (!fs.existsSync(cachePath)) {
|
|
|
|
fs.mkdirSync(cachePath)
|
|
|
|
} else {
|
|
|
|
var files = fs.readdirSync(cachePath)
|
|
|
|
for (let index = 0; index < files.length; index++) {
|
|
|
|
const file = files[index];
|
|
|
|
fs.rmSync(path.join(cachePath, file))
|
2024-01-25 23:07:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-29 08:50:37 -06:00
|
|
|
app.use(pageUpdater.middleWare)
|