mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-26 16:58:14 +01:00
Refactor code :3
This commit is contained in:
parent
cb9a60dd13
commit
c7cda4f0b4
1 changed files with 64 additions and 47 deletions
|
@ -24,7 +24,8 @@ const fs = require("node:fs");
|
||||||
const CleanCSS = require("clean-css");
|
const CleanCSS = require("clean-css");
|
||||||
|
|
||||||
const sha384 = modules.hash;
|
const sha384 = modules.hash;
|
||||||
const notice = "/* the code is Licensed in gpl-3.0-or-later. This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the GNU General Public License for more detailsYou should have received a copy of the GNU General Public Licensealong with this program. If not, see <https://www.gnu.org/licenses/>. - add the param nomin to view source code. (eg poketube.fun/css/poketube.css?nomin=true) */"
|
const notice =
|
||||||
|
"/* the code is Licensed in gpl-3.0-or-later. This program comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to redistribute it under certain conditions. See the GNU General Public License for more detailsYou should have received a copy of the GNU General Public Licensealong with this program. If not, see <https://www.gnu.org/licenses/>. - add the param nomin to view source code. (eg poketube.fun/css/poketube.css?nomin=true) */";
|
||||||
|
|
||||||
module.exports = function (app, config, renderTemplate) {
|
module.exports = function (app, config, renderTemplate) {
|
||||||
var html_location = "./css/";
|
var html_location = "./css/";
|
||||||
|
@ -43,12 +44,21 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
var number_easteregg = getRandomArbitrary(0, 143);
|
var number_easteregg = getRandomArbitrary(0, 143);
|
||||||
|
|
||||||
if (number_easteregg == "143") {
|
if (number_easteregg == "143") {
|
||||||
renderTemplate(res, req, "143.ejs");
|
renderTemplate(res, req, "143.ejs", {
|
||||||
|
something: req.query.something,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (req.query.number == "143") {
|
if (req.query.number == "143") {
|
||||||
renderTemplate(res, req, "143.ejs");
|
renderTemplate(res, req, "143.ejs", {
|
||||||
|
something: req.query.something,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req.query.something == "143") {
|
||||||
|
renderTemplate(res, req, "143.ejs", {
|
||||||
|
something: req.query.something,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (number_easteregg != "143") {
|
if (number_easteregg != "143") {
|
||||||
|
@ -76,9 +86,9 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
const cssDir = "./css/";
|
const cssDir = "./css/";
|
||||||
|
|
||||||
app.get("/css/:id", (req, res) => {
|
app.get("/css/:id", (req, res) => {
|
||||||
const filePath = path.join(cssDir, req.params.id);
|
const filePath = path.join(cssDir, req.params.id);
|
||||||
if (!fs.existsSync(filePath)) {
|
if (!fs.existsSync(filePath)) {
|
||||||
res.status(404).send("File not found");
|
res.status(404).send("File not found");
|
||||||
|
@ -100,9 +110,9 @@ app.get("/css/:id", (req, res) => {
|
||||||
if (req.params.id.endsWith(".js")) {
|
if (req.params.id.endsWith(".js")) {
|
||||||
res.redirect("/static/" + req.params.id);
|
res.redirect("/static/" + req.params.id);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/static/:id", (req, res) => {
|
app.get("/static/:id", (req, res) => {
|
||||||
if (req.params.id.endsWith(".css")) {
|
if (req.params.id.endsWith(".css")) {
|
||||||
res.redirect("/css/" + req.params.id);
|
res.redirect("/css/" + req.params.id);
|
||||||
} else if (req.params.id.endsWith(".js")) {
|
} else if (req.params.id.endsWith(".js")) {
|
||||||
|
@ -116,10 +126,17 @@ app.get("/static/:id", (req, res) => {
|
||||||
const minimizedJs = require("uglify-js").minify(js).code;
|
const minimizedJs = require("uglify-js").minify(js).code;
|
||||||
// Serve the minimized JavaScript file
|
// Serve the minimized JavaScript file
|
||||||
res.header("Content-Type", "text/javascript");
|
res.header("Content-Type", "text/javascript");
|
||||||
res.send("// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-3.0-or-later" + `\n` + `// Source code can be found in: https://codeberg.org/Ashley/poketube/src/branch/main/css/${req.params.id}` + `\n` + minimizedJs + `\n` + "// @license-end");
|
res.send(
|
||||||
|
"// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-3.0-or-later" +
|
||||||
|
`\n` +
|
||||||
|
`// Source code can be found in: https://codeberg.org/Ashley/poketube/src/branch/main/css/${req.params.id}` +
|
||||||
|
`\n` +
|
||||||
|
minimizedJs +
|
||||||
|
`\n` +
|
||||||
|
"// @license-end"
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
res.sendFile(req.params.id, { root: html_location });
|
res.sendFile(req.params.id, { root: html_location });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue