feat: 笔趣阁全文 (#2450)
This commit is contained in:
parent
88e11b1178
commit
fcd3b5c78f
|
|
@ -32,11 +32,39 @@ module.exports = async (ctx) => {
|
|||
link: e.attribs.href,
|
||||
}))
|
||||
.get();
|
||||
|
||||
const items = await Promise.all(
|
||||
chapter_item.map(async (item) => {
|
||||
const cache = await ctx.cache.get(item.link);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: item.link,
|
||||
responseType: 'buffer',
|
||||
});
|
||||
|
||||
const responseHtml = iconv.decode(response.data, 'GBK');
|
||||
const $ = cheerio.load(responseHtml);
|
||||
|
||||
const description = $('#content').html();
|
||||
|
||||
const single = {
|
||||
title: item.title,
|
||||
description,
|
||||
link: item.link,
|
||||
};
|
||||
ctx.cache.set(item.link, JSON.stringify(single));
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
ctx.state.data = {
|
||||
title: `笔趣阁 ${title}`,
|
||||
link: `${baseUrl}${id}/`,
|
||||
image: cover_url,
|
||||
description: description,
|
||||
item: chapter_item,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue