Files
RSSHub/lib/v2/dongqiudi/special.js
T
Fatpandac 864016c598 fix(route): dongqiudi/top_news cannot convert undefined or null to ob… (#9558)
* fix(route): dongqiudi/top_news cannot convert undefined or null to object

* refactor: migrate to v2

* refactor: daily parseDate cache.tryGet

* fix: legacy url.parse, cache article

* refactor: result use parseDate

* refactor: `cache.get` to `cache.tryGet`

* fix: add radar

* fix: Incomplete URL substring sanitization
2022-04-19 01:19:10 +08:00

49 lines
1.3 KiB
JavaScript

const got = require('@/utils/got');
const cheerio = require('cheerio');
const utils = require('./utils');
module.exports = async (ctx) => {
const id = ctx.params.id;
const response = await got.get(`https://www.dongqiudi.com/special/${id}`);
const $ = cheerio.load(response.data);
const host = 'https://www.dongqiudi.com';
const list = $('.detail.special ul li h3').slice(0, 5).get();
const proList = [];
const out = await Promise.all(
list.map(async (item) => {
const $ = cheerio.load(item);
const title = $('a').text();
const itemUrl = host + $('a').attr('href');
const cache = await ctx.cache.get(itemUrl);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}
const single = {
title,
link: itemUrl,
};
const es = got.get(itemUrl);
proList.push(es);
return Promise.resolve(single);
})
);
const responses = await got.all(proList);
for (let i = 0; i < proList.length; i++) {
utils.ProcessFeedType2(out[i], responses[i].data);
}
ctx.state.data = {
title: `懂球帝专题-${id}`,
link: `https://www.dongqiudi.com/special/${id}`,
item: out.filter((e) => e !== undefined),
};
};