From 8ec085f4c72ddf9114b0ae4909de7f34a3cb687f Mon Sep 17 00:00:00 2001 From: Ashley Date: Mon, 5 Dec 2022 17:43:26 +0000 Subject: [PATCH] add timeout :3 --- src/libpoketube/init/superinit.js | 122 +++++++++++++++++------------- 1 file changed, 68 insertions(+), 54 deletions(-) diff --git a/src/libpoketube/init/superinit.js b/src/libpoketube/init/superinit.js index ee354341..d52f3a0c 100644 --- a/src/libpoketube/init/superinit.js +++ b/src/libpoketube/init/superinit.js @@ -20,68 +20,82 @@ const { const { api } = require("../init/pages-api.js"); function init(app, config, rendertemplate) { - initlog("Starting superinit"); + var didstart = false; + initlog("wait a few mins... pt on timeout rn"); - initlog("[START] Load pages"); + app.get("/*", function (req, res, next) { + if (didstart) return next(); - /* PokeTube Update daemon - checks for updates in poketube */ - (async () => { - const url = `https://poketube.fun/api/version.json`; + return rendertemplate(res, req, "timeout.ejs"); + }); - let f = await modules - .fetch(url) - .then((res) => res.text()) - .then((json) => JSON.parse(json)); + setTimeout(function () { + didstart = true; - if (f.vernum == api) { - console.log("[UPDATE DAEMON] PokeTube is up to date!"); + initlog("Starting superinit"); + + initlog("[START] Load pages"); + + if (Math.random() < 0.5) { + initlog("https://poketube.fun/watch?v=lpiB2wMc49g"); } - if (f.vernum != api) { - console.warn( - "[UPDATE DAEMON] PokeTube is out of date! please re-clone the poketube repo :p " + 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 ); + + 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 () { + /* 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 " + ); + } + })(); + }, 125000); + } catch (err) { + initlog("[FAILED] Load pages \n" + err); } - })(); - - if (Math.random() < 0.5) { - initlog("https://poketube.fun/watch?v=lpiB2wMc49g"); - } - - 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 - ); - - 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"); - } catch (err) { - initlog("[FAILED] Load pages \n" + err); - } + }, 120000); } module.exports = {