add cache for channels oowowowow :3

This commit is contained in:
Ashley 2023-04-28 20:39:55 +00:00
parent 56d01efe6d
commit 340c2a4ce0

View file

@ -55,7 +55,7 @@ module.exports = function (app, config, renderTemplate) {
.then((colors) => colors[0].hex()),
});
} catch {
res.redirect("/")
res.redirect("/");
}
});
@ -114,6 +114,7 @@ module.exports = function (app, config, renderTemplate) {
try {
const ID = req.query.id;
const tab = req.query.tab;
const cache = {};
try {
// about
@ -148,20 +149,34 @@ module.exports = function (app, config, renderTemplate) {
return null;
}
};
const tj = await getChannelData(
var tj = await getChannelData(
`https://invid-api.poketube.fun/api/v1/channels/videos/${ID}/?sort_by=${sort_by}${continuation}`
);
const shorts = await getChannelData(
var shorts = await getChannelData(
`https://invid-api.poketube.fun/api/v1/channels/${ID}/shorts?sort_by=${sort_by}${continuations}`
);
const stream = await getChannelData(
var stream = await getChannelData(
`https://invid-api.poketube.fun/api/v1/channels/${ID}/streams?sort_by=${sort_by}${continuationl}`
);
const c = await getChannelData(
var c = await getChannelData(
`https://invid-api.poketube.fun/api/v1/channels/community/${ID}/`
);
cache[ID] = {
result: {
tj,
shorts,
stream,
c,
boutJson,
},
timestamp: Date.now(),
};
if (cache[ID] && Date.now() - cache[ID].timestamp < 3600000) {
var { tj, shorts, stream, c, boutJson } = cache[ID].result;
}
const summary = await wiki.summary(boutJson.Channel.Metadata.Name);
const wikiSummary = summary.title !== "Not found." ? summary : "none";