themes im backend etzala

This commit is contained in:
Flummi
2021-04-17 19:55:25 +02:00
parent 65454961ce
commit 97519de05b
7 changed files with 63 additions and 23 deletions

View File

@ -46,7 +46,8 @@ router.get(/^\/(audio\/?|image\/?|video\/?)?(p\/\d+)?$/, async (req, res) => {
link: `/${mime ? mime + "/" : ""}p/`
},
last: query[query.length - 1].id,
filter: mime ? mime : undefined
filter: mime ? mime : undefined,
theme: (typeof req.cookies.theme !== "undefined" && cfg.websrv.themes.includes(req.cookies.theme)) ? req.cookies.theme : cfg.websrv.themes[0]
};
res.reply({ body: tpl.render("views/index", data) });
@ -117,11 +118,16 @@ router.get(/^\/((audio\/|video\/|image\/)?[0-9]+)$/, async (req, res) => {
cheat: cheat,
link: `/${mime ? mime + "/" : ""}`
},
filter: mime ? mime : undefined
filter: mime ? mime : undefined,
theme: (typeof req.cookies.theme !== "undefined" && cfg.websrv.themes.includes(req.cookies.theme)) ? req.cookies.theme : cfg.websrv.themes[0]
};
res.reply({ body: tpl.render("views/item", data) });
});
router.get(/^\/(contact|help|about)$/, (req, res) => {
res.reply({ body: tpl.render(`views/${req.url.split[0]}`) });
res.reply({
body: tpl.render(`views/${req.url.split[0]}`, {
theme: (typeof req.cookies.theme !== "undefined" && cfg.websrv.themes.includes(req.cookies.theme)) ? req.cookies.theme : cfg.websrv.themes[0]
})
});
});

View File

@ -37,6 +37,14 @@ import router from "./inc/router.mjs";
"Cache-Control": "no-cache, public",
"Location": target
}).end();
req.cookies = {};
if(req.headers.cookie) {
req.headers.cookie.split("; ").forEach(c => {
const parts = c.split('=');
req.cookies[parts.shift().trim()] = decodeURI(parts.join('='));
});
}
!(r = router.routes.getRoute(req.url.pathname, req.method)) ? res.writeHead(404).end(`404 - ${req.url.pathname}`) : await r(req, res);
console.log([