add did you mean? prompt

This commit is contained in:
Ashley 2022-11-18 09:42:25 +00:00
parent 64ff616867
commit 249a375aae

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 {
IsJsonString,
convert,
@ -41,17 +50,17 @@ module.exports = function (app, config, renderTemplate) {
.getColors(`https://i.ytimg.com/vi/${v}/maxresdefault.jpg`)
.then((colors) => colors[0].hex()),
});
});
});
app.get("/old/watch", async function (req, res) {
app.get("/old/watch", async function (req, res) {
var v = req.query.v;
var e = req.query.e;
if (!v) res.redirect("/");
res.redirect(`/watch?v=${v}`);
});
});
app.get("/search", async (req, res) => {
app.get("/search", async (req, res) => {
const query = req.query.query;
if (req.query.continuation) {
@ -72,19 +81,30 @@ app.get("/search", async (req, res) => {
return res.redirect("/");
}
h = " ";
if (j.Search.Results.DynamicItem) {
if (j.Search.Results.DynamicItem.id == "didYouMeanRenderer") {
var h = JSON.parse(j.Search.Results.DynamicItem.Title);
}
}
const summary = await wiki
.summary(query + " ")
.then((summary_) => (summary_.title !== "Not found." ? summary_ : "none"));
.then((summary_) =>
summary_.title !== "Not found." ? summary_ : "none"
);
renderTemplate(res, req, "search.ejs", {
j,
h,
continuation,
q: query,
summary,
});
});
});
app.get("/channel/", async (req, res) => {
app.get("/channel/", async (req, res) => {
const ID = req.query.id;
const tab = req.query.tab;
@ -104,7 +124,8 @@ app.get("/channel/", async (req, res) => {
//videos
const channel = await modules.fetch(
config.tubeApi + `channel?id=${ID}&tab=shorts&Continuation=${continuation}`
config.tubeApi +
`channel?id=${ID}&tab=shorts&Continuation=${continuation}`
);
const c = await channel.text();
const tj = JSON.parse(modules.toJson(c));
@ -149,5 +170,5 @@ app.get("/channel/", async (req, res) => {
: "Private",
desc: d,
});
});
}
});
};