fix(router/u9a9): return cache if need (#14537)

This commit is contained in:
storytellerF
2024-02-23 19:03:24 +08:00
committed by GitHub
parent 79d391baf7
commit 65ba168e87
+13 -13
View File
@@ -21,7 +21,7 @@ module.exports = async (ctx) => {
const { data: response } = await got(link);
const $ = cheerio.load(response);
const items = $('table tr')
const list = $('table tr')
.slice(1) // skip thead
.toArray()
.map((item) => {
@@ -43,20 +43,20 @@ module.exports = async (ctx) => {
};
});
if (preview) {
await Promise.all(
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);
const items = preview
? await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);
item.description = $('.panel-body').eq(1).html();
item.description = $('.panel-body').eq(1).html();
return item;
})
)
);
}
return item;
})
)
)
: list;
ctx.state.data = {
title,