diff --git a/lib/routes/novel/biquge.js b/lib/routes/novel/biquge.js index f732d6d6c..85ce877b0 100644 --- a/lib/routes/novel/biquge.js +++ b/lib/routes/novel/biquge.js @@ -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, }; };