Refactor code :3

This commit is contained in:
Ashley 2023-09-13 17:25:51 +00:00
parent 68caecb6f2
commit 7d2506f8a2

View file

@ -1,5 +1,21 @@
const { fetcher, core, wiki, musicInfo, modules, version, initlog } = require("../libpoketube-initsys.js"); const {
const { IsJsonString, convert, getFirstLine, capitalizeFirstLetter, turntomins, getRandomInt, getRandomArbitrary } = require("../ptutils/libpt-coreutils.js"); fetcher,
core,
wiki,
musicInfo,
modules,
version,
initlog,
} = require("../libpoketube-initsys.js");
const {
IsJsonString,
convert,
getFirstLine,
capitalizeFirstLetter,
turntomins,
getRandomInt,
getRandomArbitrary,
} = require("../ptutils/libpt-coreutils.js");
const { api } = require("../init/pages-api.js"); const { api } = require("../init/pages-api.js");
function init(app, config, rendertemplate) { function init(app, config, rendertemplate) {
@ -8,9 +24,9 @@ function init(app, config, rendertemplate) {
initlog("wait a few mins... pt on timeout rn"); initlog("wait a few mins... pt on timeout rn");
app.get("/*", function (req, res, next) { app.get("/*", function (req, res, next) {
if (didstart) return next(); if (didstart) return next();
return rendertemplate(res, req, "timeout.ejs"); return rendertemplate(res, req, "timeout.ejs");
}); });
setTimeout(function () { setTimeout(function () {
@ -25,36 +41,24 @@ function init(app, config, rendertemplate) {
} }
try { try {
initlog("Loading video pages "); const modulesToLoad = [
require("../init/pages-video.js")(app, config, rendertemplate); { name: "video pages", path: "../init/pages-video.js" },
{ name: "redirects/old pages", path: "../init/pages-redir.js" },
{ name: "Download and channel pages", path: "../init/pages-channel-and-download.js",},
{ name: "api pages", path: "../init/pages-api.js" },
{ name: "static pages", path: "../init/pages-static.js" },
{ name: "main pages", path: "../init/pages-404-and-main.js" },
];
initlog("Loaded video pages "); for (const moduleInfo of modulesToLoad) {
initlog("Loading redirects/old pages "); initlog(`Loading ${moduleInfo.name}`);
require("../init/pages-redir.js")(app, config, rendertemplate); require(moduleInfo.path)(app, config, rendertemplate);
initlog("Loaded redirects/old pages "); initlog(`Loaded ${moduleInfo.name}`);
}
initlog("Loading Download and channel pages");
require("../init/pages-channel-and-download.js")(
app,
config,
rendertemplate
);
initlog("Loaded Download and channel pages");
initlog("Loading api pages");
require("../init/pages-api.js")(app, config, rendertemplate);
initlog("Loaded api pages");
initlog("Loading static pages");
require("../init/pages-static.js")(app, config, rendertemplate);
initlog("Loaded static pages");
initlog("Loading main pages");
require("../init/pages-404-and-main.js")(app, config, rendertemplate);
initlog("Loaded main pages");
initlog("[OK] Load pages"); initlog("[OK] Load pages");
initlog("Loaded pages - initing poketube finnished :3"); initlog("Loaded pages - initing poketube finnished :3");
setTimeout(function () { setTimeout(function () {
setInterval(function () { setInterval(function () {
/* PokeTube Update daemon - checks for updates in poketube */ /* PokeTube Update daemon - checks for updates in poketube */
@ -80,11 +84,11 @@ function init(app, config, rendertemplate) {
}, 30000); }, 30000);
} catch (err) { } catch (err) {
initlog("[FAILED] Load pages \n" + err); initlog("[FAILED] Load pages \n" + err);
console.error(err) console.error(err);
} }
}, 30000); }, 30000);
} }
module.exports = { module.exports = {
sinit: init, sinit: init,
}; };