feat: bbc cache

This commit is contained in:
DIYgod 2021-02-04 19:35:15 +08:00
parent 4803718318
commit c235f1e24a
No known key found for this signature in database
GPG Key ID: D159328F47A80DCA
1 changed files with 29 additions and 27 deletions

View File

@ -47,38 +47,40 @@ module.exports = async (ctx) => {
}
const items = await Promise.all(
feed.items.map(async (item) => {
const response = await got({
method: 'get',
url: item.link,
});
feed.items.map(
async (item) =>
await ctx.cache.tryGet(item.link, async () => {
const response = await got({
method: 'get',
url: item.link,
});
const $ = cheerio.load(response.data);
const $ = cheerio.load(response.data);
let description;
let description;
if (response.request.options.url.pathname.startsWith('/news/av')) {
description = item.content;
} else {
description = utils.ProcessFeed($);
}
if (response.request.options.url.pathname.startsWith('/news/av')) {
description = item.content;
} else {
description = utils.ProcessFeed($);
}
let section = 'sport';
const urlSplit = item.link.split('/');
const sectionSplit = urlSplit[urlSplit.length - 1].split('-');
if (sectionSplit.length > 1) {
section = sectionSplit[0];
}
section = section[0].toUpperCase() + section.slice(1);
let section = 'sport';
const urlSplit = item.link.split('/');
const sectionSplit = urlSplit[urlSplit.length - 1].split('-');
if (sectionSplit.length > 1) {
section = sectionSplit[0];
}
section = section[0].toUpperCase() + section.slice(1);
const single = {
title: `[${section}] ${item.title}`,
description,
pubDate: item.pubDate,
link: item.link,
};
return Promise.resolve(single);
})
return {
title: `[${section}] ${item.title}`,
description,
pubDate: item.pubDate,
link: item.link,
};
})
)
);
ctx.state.data = {