From 355e721c6fae61377583fcb721e5ff9e3a952531 Mon Sep 17 00:00:00 2001 From: Ashley Date: Sat, 9 Sep 2023 16:51:15 +0000 Subject: [PATCH] add bundle app.js :3 --- src/libpoketube/init/pages-static.js | 36 ++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/libpoketube/init/pages-static.js b/src/libpoketube/init/pages-static.js index d2d6aa43..cf6edd1d 100644 --- a/src/libpoketube/init/pages-static.js +++ b/src/libpoketube/init/pages-static.js @@ -112,10 +112,30 @@ module.exports = function (app, config, renderTemplate) { } }); - app.get("/static/:id", (req, res) => { - if (req.params.id.endsWith(".css")) { - res.redirect("/css/" + req.params.id); - } else if (req.params.id.endsWith(".js")) { +app.get("/static/:id", (req, res) => { + if (req.params.id.endsWith(".css")) { + res.redirect("/css/" + req.params.id); + } else if (req.params.id.endsWith(".js")) { + if (req.params.id.endsWith(".bundle.js")) { + // Define the paths to the three input JavaScript files + const file1Path = path.join(html_location, 'app.js'); + const file2Path = path.join(html_location, 'custom-css.js'); + const file3Path = path.join(html_location, 'emojis.js'); + + // Read the contents of the three input files + const file1Content = fs.readFileSync(file1Path, 'utf-8'); + const file2Content = fs.readFileSync(file2Path, 'utf-8'); + const file3Content = fs.readFileSync(file3Path, 'utf-8'); + + // Combine the contents of the three files + const combinedContent = `${file1Content}\n${file2Content}\n${file3Content}`; + + // Serve the combined content as JavaScript + res.header("Content-Type", "text/javascript"); + const minimizedJs = require("uglify-js").minify(combinedContent).code; + res.send("// @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-3.0-or-later" + `\n` + `// Includes app.js, emojis.js and custom-css.js. source code can be found for these 3 files in https://codeberg.org/Ashley/poketube/src/branch/main/css/` + +`\n` + minimizedJs + `\n` +"// @license-end"); + } else { const filePath = path.join(html_location, req.params.id); if (!fs.existsSync(filePath)) { res.status(404).send("File not found"); @@ -135,8 +155,10 @@ module.exports = function (app, config, renderTemplate) { `\n` + "// @license-end" ); - } else { - res.sendFile(req.params.id, { root: html_location }); } - }); + } else { + res.sendFile(req.params.id, { root: html_location }); + } +}); + };