poke/src/libpoketube/init/superinit.js

91 lines
2.7 KiB
JavaScript
Raw Normal View History

2023-03-02 20:57:20 +01:00
const { fetcher, core, wiki, musicInfo, modules, version, initlog } = require("../libpoketube-initsys.js");
const { IsJsonString, convert, getFirstLine, capitalizeFirstLetter, turntomins, getRandomInt, getRandomArbitrary } = require("../ptutils/libpt-coreutils.js");
2022-11-16 11:26:47 +01:00
const { api } = require("../init/pages-api.js");
2022-11-09 17:47:46 +01:00
function init(app, config, rendertemplate) {
2022-12-05 18:43:26 +01:00
var didstart = false;
2022-12-25 17:10:51 +01:00
2022-12-05 18:43:26 +01:00
initlog("wait a few mins... pt on timeout rn");
2022-11-16 11:26:47 +01:00
2022-12-05 18:43:26 +01:00
app.get("/*", function (req, res, next) {
if (didstart) return next();
2022-11-16 11:26:47 +01:00
2022-12-05 18:43:26 +01:00
return rendertemplate(res, req, "timeout.ejs");
});
2023-02-09 17:35:22 +01:00
2022-11-16 11:26:47 +01:00
2022-12-05 18:43:26 +01:00
setTimeout(function () {
didstart = true;
2022-11-16 11:26:47 +01:00
2022-12-05 18:43:26 +01:00
initlog("Starting superinit");
initlog("[START] Load pages");
if (Math.random() < 0.5) {
initlog("https://poketube.fun/watch?v=lpiB2wMc49g");
2022-11-16 11:26:47 +01:00
}
2022-12-05 18:43:26 +01:00
try {
initlog("Loading video pages ");
require("../init/pages-video.js")(app, config, rendertemplate);
initlog("Loaded video pages ");
initlog("Loading redirects/old pages ");
require("../init/pages-redir.js")(app, config, rendertemplate);
initlog("Loaded redirects/old pages ");
initlog("Loading Download and channel pages");
require("../init/pages-channel-and-download.js")(
app,
config,
rendertemplate
2022-11-16 11:26:47 +01:00
);
2022-12-05 18:43:26 +01:00
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("Loaded pages - initing poketube finnished :3");
setTimeout(function () {
2023-01-31 11:47:34 +01:00
setInterval(function () {
/* PokeTube Update daemon - checks for updates in poketube */
(async () => {
const url = `https://poketube.fun/api/version.json`;
let f = await modules
.fetch(url)
.then((res) => res.text())
.then((json) => JSON.parse(json));
if (f.vernum == api) {
console.log("[UPDATE DAEMON] PokeTube is up to date!");
}
if (f.vernum != api) {
console.warn(
"[UPDATE DAEMON] PokeTube is out of date! please re-clone the poketube repo :p "
);
}
})();
2023-03-06 20:35:40 +01:00
}, 46000); /* setInterval */
}, 46000);
2022-12-05 18:43:26 +01:00
} catch (err) {
initlog("[FAILED] Load pages \n" + err);
2022-11-16 11:26:47 +01:00
}
2023-01-07 20:08:01 +01:00
}, 120000);
2022-11-09 17:47:46 +01:00
}
module.exports = {
sinit: init,
};