mirror of
https://codeberg.org/ashley/poke.git
synced 2024-11-23 03:57:48 +01:00
fix issues :3
This commit is contained in:
parent
03755a8e3b
commit
6e79f2f285
1 changed files with 93 additions and 109 deletions
|
@ -66,58 +66,42 @@ module.exports = function (app, config, renderTemplate) {
|
||||||
app.get("/search", async (req, res) => {
|
app.get("/search", async (req, res) => {
|
||||||
const query = req.query.query;
|
const query = req.query.query;
|
||||||
|
|
||||||
if (req.query.continuation) {
|
|
||||||
var continuation = req.query.continuation;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!req.query.continuation) {
|
|
||||||
var continuation = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!query) {
|
if (!query) {
|
||||||
return res.redirect("/");
|
return res.redirect("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (query) {
|
let continuation = req.query.continuation || "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const search = await modules.fetch(
|
const searchUrl = `https://tube-srv.ashley143.gay/api/search?query=${encodeURIComponent(
|
||||||
`https://tube-srv.ashley143.gay/api/search?query=${query.replace(
|
query
|
||||||
"&",
|
)}&continuation=${encodeURIComponent(continuation)}`;
|
||||||
"and"
|
const searchResponse = await modules.fetch(searchUrl);
|
||||||
)}&continuation=${continuation}`
|
const searchText = await searchResponse.text();
|
||||||
);
|
const searchJson = JSON.parse(modules.toJson(searchText));
|
||||||
|
|
||||||
const text = await search.text();
|
let didYouMean;
|
||||||
const j = JSON.parse(modules.toJson(text));
|
if (
|
||||||
|
searchJson.Search?.Results?.DynamicItem?.id === "didYouMeanRenderer"
|
||||||
h = " ";
|
) {
|
||||||
|
didYouMean = JSON.parse(searchJson.Search.Results.DynamicItem.Title);
|
||||||
// YOUTUBE WHY do you WANT me to do this oh ma gosh
|
|
||||||
if (j.Search) {
|
|
||||||
if ("Results.DynamicItem" in j.Search) {
|
|
||||||
if (j.Search.Results.DynamicItem.id == "didYouMeanRenderer") {
|
|
||||||
var h = JSON.parse(j.Search.Results.DynamicItem.Title);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const summary = await wiki
|
const summary = await wiki.summary(query + " ").then((summary_) =>
|
||||||
.summary(query + " ")
|
|
||||||
.then((summary_) =>
|
|
||||||
summary_.title !== "Not found." ? summary_ : "none"
|
summary_.title !== "Not found." ? summary_ : "none"
|
||||||
);
|
);
|
||||||
|
|
||||||
renderTemplate(res, req, "search.ejs", {
|
renderTemplate(res, req, "search.ejs", {
|
||||||
j,
|
j: searchJson,
|
||||||
h,
|
h: didYouMean,
|
||||||
continuation,
|
continuation,
|
||||||
q: query,
|
q: query,
|
||||||
summary,
|
summary,
|
||||||
});
|
});
|
||||||
} catch {
|
} catch (error) {
|
||||||
|
console.error(`Error while searching for '${query}':`, error);
|
||||||
res.redirect("/");
|
res.redirect("/");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get("/channel/", async (req, res) => {
|
app.get("/channel/", async (req, res) => {
|
||||||
|
@ -149,14 +133,12 @@ app.get("/channel/", async (req, res) => {
|
||||||
console.error("Failed to fetch channel data from API:", error);
|
console.error("Failed to fetch channel data from API:", error);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const [tj, shorts, stream, c] = await Promise.all([
|
const tj = await modules.fetch(`https://inv.zzls.xyz/api/v1/channels/videos/${ID}/?sort_by=${req.query.sort_by || "newest"}` + continuation).then((res) => res.text()).then((txt) => getJson(txt)).catch(" ")
|
||||||
getChannelData(`https://inv.zzls.xyz/api/v1/channels/videos/${ID}/?sort_by=${sort_by}&continuation=${continuation}`),
|
const shorts = await modules.fetch(`https://inv.zzls.xyz/api/v1/channels/${ID}/shorts?sort_by=${req.query.sort_by || "newest"}` + continuations).then((res) => res.text()).then((txt) => getJson(txt)).catch(" ")
|
||||||
getChannelData(`https://inv.zzls.xyz/api/v1/channels/${ID}/shorts?sort_by=${sort_by}&continuation=${continuations}`),
|
const stream = await modules.fetch(`https://inv.zzls.xyz/api/v1/channels/${ID}/streams?sort_by=${req.query.sort_by || "newest"}` + continuationl).then((res) => res.text()).then((txt) => getJson(txt)).catch(" ")
|
||||||
getChannelData(`https://inv.zzls.xyz/api/v1/channels/${ID}/streams?sort_by=${sort_by}&continuation=${continuationl}`),
|
const c = await modules.fetch(`https://inv.zzls.xyz/api/v1/channels/community/${ID}/`).then((res) => res.text()) .then((txt) => getJson(txt));
|
||||||
getChannelData(`https://inv.zzls.xyz/api/v1/channels/community/${ID}/`),
|
|
||||||
]);
|
|
||||||
|
|
||||||
const summary = await wiki.summary(boutJson.Channel.Metadata.Name);
|
const summary = await wiki.summary(boutJson.Channel.Metadata.Name);
|
||||||
const wikiSummary = summary.title !== "Not found." ? summary : "none";
|
const wikiSummary = summary.title !== "Not found." ? summary : "none";
|
||||||
|
@ -183,7 +165,10 @@ app.get("/channel/", async (req, res) => {
|
||||||
getFirstLine,
|
getFirstLine,
|
||||||
isMobile: req.useragent.isMobile,
|
isMobile: req.useragent.isMobile,
|
||||||
about,
|
about,
|
||||||
subs: typeof subscribers === "string" ? subscribers.replace("subscribers", "") : "None",
|
subs:
|
||||||
|
typeof subscribers === "string"
|
||||||
|
? subscribers.replace("subscribers", "")
|
||||||
|
: "None",
|
||||||
desc: dnoreplace === "[object Object]" ? "" : description,
|
desc: dnoreplace === "[object Object]" ? "" : description,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -191,5 +176,4 @@ app.get("/channel/", async (req, res) => {
|
||||||
res.redirect("/");
|
res.redirect("/");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue