Minor refactoring

This commit is contained in:
Pax1601
2023-12-01 13:00:02 +01:00
parent 775148cec8
commit fda0b21fb0
22 changed files with 418 additions and 92 deletions

View File

@@ -1,11 +1,41 @@
const express = require('express');
const router = express.Router();
const { v4: uuidv4 } = require('uuid');
var themesMap = {};
// TODO should be user selectable or at least configurable from configuration file
var theme = "olympus";
router.get('/theme/*', function (req, res, next) {
res.redirect(req.url.replace("theme", "themes/" + theme));
if (!req.cookies.id) {
const id = uuidv4();
res.cookie('id', id, { httpOnly: true });
themesMap[id] = "olympus";
reqTheme = "olympus";
}
else {
if (!(req.cookies.id in themesMap)) {
themesMap[req.cookies.id] = "olympus";
}
reqTheme = themesMap[req.cookies.id];
}
/* Yes, this in an easter egg! :D Feel free to ignore it, or activate the parrot theme to check what it does */
if (reqTheme === "parrot" && !req.url.includes(".css"))
res.redirect('/themes/parrot/images/parrot.svg');
else
res.redirect(req.url.replace("theme", "themes/" + reqTheme));
});
router.put('/theme/:newTheme', function (req, res, next) {
const newTheme = req.params.newTheme;
if (req.cookies.id) {
themesMap[req.cookies.id] = newTheme;
console.log("Theme set to " + newTheme + " for session " + req.cookies.id);
} else {
console.log("Failed to set theme to " + newTheme + ", no session id");
}
res.end("Ok");
});
module.exports = router;