diff --git a/lib/routes/hentai-cosplays/porn-images-xxx.js b/lib/routes/hentai-cosplays/porn-images-xxx.js index a2fc3880e9..b16829c20b 100644 --- a/lib/routes/hentai-cosplays/porn-images-xxx.js +++ b/lib/routes/hentai-cosplays/porn-images-xxx.js @@ -2,7 +2,7 @@ const { processFeed } = require('./utils'); module.exports = async (ctx) => { const url = ctx.params.type ? `https://ja.porn-images-xxx.com/search/${ctx.params.type}/${encodeURIComponent(ctx.params.name)}/` : 'https://ja.porn-images-xxx.com/search/'; - const items = await processFeed(url); + const items = await processFeed(ctx, url); ctx.state.data = { title: `${ctx.params.name || '新着画像一覧'} - エロ画像`, link: url, diff --git a/lib/routes/hentai-cosplays/utils.js b/lib/routes/hentai-cosplays/utils.js index 80770e3bc8..85be00b284 100644 --- a/lib/routes/hentai-cosplays/utils.js +++ b/lib/routes/hentai-cosplays/utils.js @@ -1,26 +1,46 @@ const cheerio = require('cheerio'); const got = require('@/utils/got'); -exports.processFeed = async function processFeed(link) { +const host = 'https://ja.porn-images-xxx.com/'; + +exports.processFeed = async function processFeed(ctx, link) { const response = await got.get(link); const $ = cheerio.load(response.body); - const list = $('ul#image-list li'); + const list = $('ul#image-list li') + .map(function (index, item) { + item = $(item); + return { + title: item.find('.image-list-item-title').text(), + link: item.find('.image-list-item-title > a').attr('href'), + date: item.find('.image-list-item-regist-date > span').text(), + }; + }) + .get(); + return await Promise.all( + list.map(async (info) => { + const title = info.title.trim(); + const date = info.date; + const itemUrl = host + info.link; - return ( - list && - list - .map((index, item) => { - item = $(item); - return { - title: item.find('.image-list-item-title').text(), - link: item.find('.image-list-item-title > a').attr('href'), - description: item - .find('.image-list-item-image') - .html() - .replace(/\/p=\d+x\d+/, ''), - pubDate: new Date(item.find('.image-list-item-regist-date').text()), - }; - }) - .get() + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const response = await got.get(itemUrl); + const $ = cheerio.load(response.data); + const images = $('.icon-overlay > a > img'); + const desc = cheerio.html(images); + const item = { + title: title, + link: itemUrl, + description: desc, + pubDate: new Date(date).toUTCString(), + }; + if (desc) { + ctx.cache.set(itemUrl, JSON.stringify(item)); + } + return Promise.resolve(item); + }) ); };