libpoketube 2.0!

This commit is contained in:
Ashley 2022-11-09 15:27:56 +01:00
parent fddb34e4aa
commit 1c8ca99160

View file

@ -24,7 +24,22 @@ const {
wiki, wiki,
musicInfo, musicInfo,
modules, modules,
} = require("./src/libpoketube/loader.js"); version,
initlog,
init,
} = require("./src/libpoketube/libpoketube-initsys.js");
initlog("Loading...");
initlog(
"[Welcome] Welcome To PokeTube :3 " +
"Running " +
`Node ${process.version} - V8 v${
process.versions.v8
} - ${process.platform.replace("linux", "GNU/Linux")} ${
process.arch
} Server - libpt ${version}`
);
const { const {
IsJsonString, IsJsonString,
convert, convert,
@ -35,6 +50,8 @@ const {
getRandomArbitrary, getRandomArbitrary,
} = require("./src/libpoketube/ptutils/libpt-coreutils.js"); } = require("./src/libpoketube/ptutils/libpt-coreutils.js");
initlog("Loaded libpt-coreutils");
const templateDir = modules.path.resolve( const templateDir = modules.path.resolve(
`${process.cwd()}${modules.path.sep}html` `${process.cwd()}${modules.path.sep}html`
); );
@ -42,6 +59,7 @@ const templateDir = modules.path.resolve(
const sha384 = modules.hash; const sha384 = modules.hash;
var app = modules.express(); var app = modules.express();
initlog("Loaded express.js");
app.engine("html", require("ejs").renderFile); app.engine("html", require("ejs").renderFile);
app.use(modules.express.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded app.use(modules.express.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.use(modules.useragent.express()); app.use(modules.useragent.express());
@ -84,6 +102,10 @@ app.use(function (req, res, next) {
next(); next();
}); });
////
initlog("Loading pages ");
///
app.get("/encryption", async function (req, res) { app.get("/encryption", async function (req, res) {
var v = req.query.v; var v = req.query.v;
@ -118,11 +140,14 @@ app.get("/encryption", async function (req, res) {
}, },
}; };
res.json(re); res.json(re);
}); });
///////////// VIDEO PAGES ETC. ///////////// ///////////// VIDEO PAGES ETC. /////////////
////
initlog("Loading video pages ");
///
app.get("/watch", async function (req, res) { app.get("/watch", async function (req, res) {
/* /*
* QUERYS * QUERYS
@ -327,6 +352,11 @@ app.get("/music", async function (req, res) {
}); });
}); });
////
initlog("Loaded video pages ");
initlog("Loading Download and channel pages");
///
app.get("/download", async function (req, res) { app.get("/download", async function (req, res) {
var v = req.query.v; var v = req.query.v;
@ -465,8 +495,11 @@ app.get("/channel/", async (req, res) => {
desc: d, desc: d,
}); });
}); });
initlog("Loaded Download and channel pages");
///////////// STATIC ///////////// ///////////// STATIC /////////////
initlog("Loading static pages");
app.get("/privacy", function (req, res) { app.get("/privacy", function (req, res) {
renderTemplate(res, req, "priv.ejs"); renderTemplate(res, req, "priv.ejs");
}); });
@ -498,6 +531,8 @@ app.get("/js/:id", (req, res) => {
res.sendFile(__dirname + `/js/${req.params.id}`); res.sendFile(__dirname + `/js/${req.params.id}`);
}); });
initlog("Loaded static pages");
///////////// API ///////////// ///////////// API /////////////
app.get("/embed/:v", async function (req, res) { app.get("/embed/:v", async function (req, res) {
@ -672,24 +707,24 @@ app.get("/video/upload", (req, res) => {
///////////// 404 AND MAIN PAGES ETC ///////////// ///////////// 404 AND MAIN PAGES ETC /////////////
app.get("/:v*?", async function (req, res) { app.get("/:v*?", async function (req, res) {
let rendermainpage = () => {
if (req.useragent.isMobile) {
return res.redirect(`/discover`);
} else {
return renderTemplate(res, req, "landing.ejs");
}
};
if (req.params.v) { if (req.params.v) {
const isvld = await core.isvalidvideo(req.params.v); const isvld = await core.isvalidvideo(req.params.v);
if (isvld) { if (isvld) {
return res.redirect(`/watch?v=${req.params.v}`); return res.redirect(`/watch?v=${req.params.v}`);
} else { } else {
if (req.useragent.isMobile) { return rendermainpage();
return res.redirect(`/discover`);
} else {
return renderTemplate(res, req, "landing.ejs");
}
} }
} else { } else {
if (req.useragent.isMobile) { return rendermainpage();
return res.redirect(`/discover`);
} else {
return renderTemplate(res, req, "landing.ejs");
}
} }
}); });
@ -700,8 +735,9 @@ app.get("/*", function (req, res) {
}); });
}); });
initlog("Loaded pages - initing poketube finnished :3");
//////////////////////////////////////////////////// ////////////////////////////////////////////////////
// listen // listen
init(app);
app.listen("3000", () => {});