poke/src/libpoketube/init/superinit.js

106 lines
3.2 KiB
JavaScript
Raw Normal View History

2023-09-13 19:25:51 +02: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
2023-10-16 17:57:51 +02:00
2023-12-01 13:59:25 +01:00
app.get("/*", function (req, res, next) {
2024-04-17 19:30:52 +02:00
if (didstart) return next();
2022-11-16 11:26:47 +01:00
2024-04-17 19:35:42 +02:00
const userAgent = req.useragent.source
2024-04-17 19:30:52 +02:00
if (userAgent && (userAgent.includes('MSIE') || userAgent.includes('Trident'))) {
const htmlContent = `<!DOCTYPE html><html><head><title>Browser is not supported :p</title><style>body{margin-left:auto;margin-right:auto;display:flex;max-width:43em;font-family:sans-serif;}</style></head><body><h1>Heyo :3</h1><br><p style="margin-top:4em;margin-left:-7.4em;">hoi - poke does and <b>will not work</b> on Internet Explorer :p<br>if u wanna use poke try using Firefox (firefox.com) or Chromium :3<br>love u :3</p></body></html>`;
res.send(htmlContent);
} else {
didstart = true;
next();
}
2023-12-01 13:59:25 +01:00
});
2022-11-16 11:26:47 +01:00
2023-10-16 17:57:51 +02: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 {
2023-09-13 19:25:51 +02:00
const modulesToLoad = [
{ 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" },
2023-10-08 08:44:43 +02:00
{ name: "account pages", path: "../init/pages-account.js" },
2023-09-13 19:25:51 +02:00
{ name: "main pages", path: "../init/pages-404-and-main.js" },
];
for (const moduleInfo of modulesToLoad) {
initlog(`Loading ${moduleInfo.name}`);
require(moduleInfo.path)(app, config, rendertemplate);
initlog(`Loaded ${moduleInfo.name}`);
}
2022-12-05 18:43:26 +01:00
initlog("[OK] Load pages");
initlog("Loaded pages - initing poketube finnished :3");
2023-09-13 19:25:51 +02:00
2022-12-05 18:43:26 +01:00
setTimeout(function () {
2023-10-16 19:10:24 +02:00
/* setInterval(function () {
PokeTube Update daemon - checks for updates in poketube
2023-01-31 11:47:34 +01:00
(async () => {
2023-03-09 16:50:19 +01:00
const url = `https://poketube.fun/api/version.json?v=3`;
2023-01-31 11:47:34 +01:00
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-10-16 19:10:24 +02:00
}, 999999999999999999999999999999); /* setInterval */
2024-03-30 08:13:38 +01:00
}, 100);
2022-12-05 18:43:26 +01:00
} catch (err) {
initlog("[FAILED] Load pages \n" + err);
2023-09-13 19:25:51 +02:00
console.error(err);
2022-11-16 11:26:47 +01:00
}
2024-03-30 08:13:38 +01:00
}, 100);
2022-11-09 17:47:46 +01:00
}
module.exports = {
sinit: init,
2023-09-13 19:25:51 +02:00
};