1
0
Fork 0
mirror of https://codeberg.org/ashley/poke.git synced 2025-02-21 17:48:49 -05:00
poke/src/libpoketube/init/pages-static.js

105 lines
2.4 KiB
JavaScript
Raw Normal View History

2022-12-19 11:52:57 +00:00
const {
fetcher,
core,
wiki,
musicInfo,
modules,
version,
initlog,
init,
} = require("../libpoketube-initsys.js");
2022-11-09 17:54:00 +01:00
const {
IsJsonString,
convert,
getFirstLine,
capitalizeFirstLetter,
turntomins,
getRandomInt,
getRandomArbitrary,
} = require("../ptutils/libpt-coreutils.js");
const sha384 = modules.hash;
module.exports = function (app, config, renderTemplate) {
2022-12-19 11:52:57 +00:00
var html_location = "./css/";
app.get("/privacy", function (req, res) {
2023-04-12 20:41:37 +00:00
if (req.hostname == "poketube.fun") {
renderTemplate(res, req, "priv.ejs", {
2023-03-19 11:25:06 +00:00
isMobile: req.useragent.isMobile,
2023-04-12 20:41:37 +00:00
});
2023-02-20 15:44:30 +00:00
} else {
2023-04-12 20:41:37 +00:00
renderTemplate(res, req, "priv-custom.ejs");
2023-02-20 15:44:30 +00:00
}
2022-12-19 11:52:57 +00:00
});
app.get("/143", function (req, res) {
var number_easteregg = getRandomArbitrary(0, 143);
if (number_easteregg == "143") {
renderTemplate(res, req, "143.ejs");
}
if (number_easteregg != "143") {
return res.redirect("/");
}
});
app.get("/domains", function (req, res) {
renderTemplate(res, req, "domains.ejs");
});
app.get("/license", function (req, res) {
renderTemplate(res, req, "license.ejs");
});
2022-12-26 23:54:55 +00:00
app.get("/credits", function (req, res) {
renderTemplate(res, req, "want-you-gone.ejs");
});
2023-04-12 20:41:37 +00:00
2023-02-23 15:58:19 +00:00
app.get("/customize", function (req, res) {
2023-04-12 20:41:37 +00:00
const tab = req.query.tab;
2023-02-23 15:58:19 +00:00
2023-04-12 20:41:37 +00:00
renderTemplate(res, req, "custom-css.ejs", {
tab,
});
2023-02-22 16:02:06 +00:00
});
2022-12-26 23:54:55 +00:00
2023-04-12 20:41:37 +00:00
const path = require("path");
const fs = require("fs");
const CleanCSS = require("clean-css");
2023-03-11 14:34:31 +00:00
2023-04-12 20:41:37 +00:00
const cssDir = "./css/";
2023-02-09 16:36:57 +00:00
2023-04-12 20:41:37 +00:00
app.get("/css/:id", (req, res) => {
const filePath = path.join(cssDir, req.params.id);
if (!fs.existsSync(filePath)) {
res.status(404).send("File not found");
return;
}
if (req.params.id.endsWith(".css")) {
// Minimize the CSS file
const css = fs.readFileSync(filePath, "utf8");
const minimizedCss = new CleanCSS().minify(css).styles;
// Serve the minimized CSS file
res.header("Content-Type", "text/css");
res.send(minimizedCss);
} else {
// Serve the original file
res.sendFile(req.params.id, { root: html_location });
}
if (req.params.id.endsWith(".js")) {
res.redirect("/static/" + req.params.id);
}
});
app.get("/static/:id", (req, res) => {
if (req.params.id.endsWith(".css")) {
res.redirect("/css/" + req.params.id);
}
res.sendFile(req.params.id, { root: html_location });
});
2022-12-19 11:52:57 +00:00
};