fix a silly issue :3

This commit is contained in:
Ashley 2022-11-10 14:27:26 +01:00
parent 605c0b1079
commit 9636794ac2

View file

@ -1,4 +1,13 @@
const { fetcher,core, wiki,musicInfo, modules, version, initlog, init,} = require("../libpoketube-initsys.js"); const {
fetcher,
core,
wiki,
musicInfo,
modules,
version,
initlog,
init,
} = require("../libpoketube-initsys.js");
const { const {
IsJsonString, IsJsonString,
convert, convert,
@ -12,34 +21,13 @@ const {
const sha384 = modules.hash; const sha384 = modules.hash;
module.exports = function (app, config, renderTemplate) { module.exports = function (app, config, renderTemplate) {
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) {
const isvld = await core.isvalidvideo(req.params.v);
if (isvld) {
return res.redirect(`/watch?v=${req.params.v}`);
} else {
return rendermainpage();
}
} else {
return rendermainpage();
}
});
app.get("/discover", async function (req, res) { app.get("/discover", async function (req, res) {
const trends = await modules.fetch(config.tubeApi + `trending`); const trends = await modules.fetch(config.tubeApi + `trending`);
const h = await trends.text(); const h = await trends.text();
const k = JSON.parse(modules.toJson(h)); const k = JSON.parse(modules.toJson(h));
if (req.query.tab) var tab = `/?type=${capitalizeFirstLetter(req.query.tab)}`; if (req.query.tab)
var tab = `/?type=${capitalizeFirstLetter(req.query.tab)}`;
if (!req.query.tab) var tab = ""; if (!req.query.tab) var tab = "";
@ -79,4 +67,25 @@ app.get("/discover", 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) {
const isvld = await core.isvalidvideo(req.params.v);
if (isvld) {
return res.redirect(`/watch?v=${req.params.v}`);
} else {
return rendermainpage();
}
} else {
return rendermainpage();
}
});
};