refactor code :3

This commit is contained in:
Ashley 2023-09-07 13:13:40 +00:00
parent 7a28bf1e48
commit 35a739d8df

View file

@ -80,10 +80,9 @@ module.exports = function (app, config, renderTemplate) {
} }
} }
if (query && query.startsWith('!')) { if (query && query.startsWith("!")) {
res.redirect("https://duckduckgo.com/?q=" + query) res.redirect("https://duckduckgo.com/?q=" + query);
} }
if (!query) { if (!query) {
return res.redirect("/"); return res.redirect("/");
@ -92,7 +91,7 @@ module.exports = function (app, config, renderTemplate) {
let continuation = req.query.continuation || ""; let continuation = req.query.continuation || "";
try { try {
const headers = {}; const headers = {};
const searchUrl = `https://inner-api.poketube.fun/api/search?query=${encodeURIComponent( const searchUrl = `https://inner-api.poketube.fun/api/search?query=${encodeURIComponent(
query query
@ -116,7 +115,7 @@ module.exports = function (app, config, renderTemplate) {
h: didYouMean, h: didYouMean,
continuation, continuation,
q: query, q: query,
summary:"", summary: "",
}); });
} catch (error) { } catch (error) {
console.error(`Error while searching for '${query}':`, error); console.error(`Error while searching for '${query}':`, error);
@ -133,9 +132,7 @@ module.exports = function (app, config, renderTemplate) {
try { try {
// about // about
const bout = await fetch( const bout = await fetch(config.tubeApi + `channel?id=${ID}&tab=about`);
config.tubeApi + `channel?id=${ID}&tab=about`
);
const h = await bout.text(); const h = await bout.text();
var boutJson = JSON.parse(modules.toJson(h)); var boutJson = JSON.parse(modules.toJson(h));
} catch { } catch {
@ -163,26 +160,20 @@ module.exports = function (app, config, renderTemplate) {
} }
}; };
var tjPromise = getChannelData( const apiUrl = "https://invid-api.poketube.fun/api/v1/channels/";
`https://invid-api.poketube.fun/api/v1/channels/videos/${ID}/?sort_by=${sort_by}${continuation}` const channelUrl = `${apiUrl}videos/${ID}/?sort_by=${sort_by}${continuation}`;
); const shortsUrl = `${apiUrl}${ID}/shorts?sort_by=${sort_by}${continuations}`;
var shortsPromise = getChannelData( const streamUrl = `${apiUrl}${ID}/streams?sort_by=${sort_by}${continuationl}`;
`https://invid-api.poketube.fun/api/v1/channels/${ID}/shorts?sort_by=${sort_by}${continuations}` const channelINVUrl = `${apiUrl}${ID}/`;
); const communityUrl = `${apiUrl}community/${ID}/?hl=en-US`;
var streamPromise = getChannelData(
`https://invid-api.poketube.fun/api/v1/channels/${ID}/streams?sort_by=${sort_by}${continuationl}` var [tj, shorts, stream, c, cinv] = await Promise.all([
); getChannelData(channelUrl),
var ChannelINVPromise = getChannelData( getChannelData(shortsUrl),
`https://invid-api.poketube.fun/api/v1/channels/${ID}/` getChannelData(streamUrl),
); getChannelData(communityUrl),
var cPromise = getChannelData( getChannelData(channelINVUrl),
`https://invid-api.poketube.fun/api/v1/channels/community/${ID}/?hl=en-US` ]);
);
var tj = await tjPromise;
var shorts = await shortsPromise;
var stream = await streamPromise;
var c = await cPromise;
var cinv = await ChannelINVPromise;
cache[ID] = { cache[ID] = {
result: { result: {