diff --git a/lib/v2/dongqiudi/daily.js b/lib/v2/dongqiudi/daily.js deleted file mode 100644 index ebe7484af..000000000 --- a/lib/v2/dongqiudi/daily.js +++ /dev/null @@ -1,47 +0,0 @@ -const got = require('@/utils/got'); -const cheerio = require('cheerio'); -const utils = require('./utils'); - -module.exports = async (ctx) => { - const response = await got.get('https://www.dongqiudi.com/special/48'); - - const $ = cheerio.load(response.data); - - const host = 'https://www.dongqiudi.com'; - - const list = $('.detail.special ul li h3') - .slice(0, 5) - .get() - .filter((e) => cheerio.load(e).text().length > 3); - - const proList = []; - - const out = await Promise.all( - list.map((item) => { - const $ = cheerio.load(item); - const title = $('a').text(); - const itemUrl = host + $('a').attr('href'); - - return ctx.cache.tryGet(itemUrl, () => { - const single = { - title, - link: itemUrl, - }; - - const es = got.get(itemUrl); - proList.push(es); - return 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: '懂球帝早报', - link: 'http://www.dongqiudi.com/special/48', - item: out.filter((e) => e.description !== undefined), - }; -}; diff --git a/lib/v2/dongqiudi/player_news.js b/lib/v2/dongqiudi/player_news.js index c4e270021..b7285155c 100644 --- a/lib/v2/dongqiudi/player_news.js +++ b/lib/v2/dongqiudi/player_news.js @@ -1,8 +1,7 @@ const utils = require('./utils'); module.exports = async (ctx) => { - const id = ctx.params.id; - const link = `https://www.dongqiudi.com/player/${id}.html`; + const playerId = ctx.params.id; - await utils.ProcessFeed(ctx, link, 'player'); + await utils.ProcessFeed(ctx, 'player', playerId); }; diff --git a/lib/v2/dongqiudi/result.js b/lib/v2/dongqiudi/result.js index 38888f09d..5e9a2a29d 100644 --- a/lib/v2/dongqiudi/result.js +++ b/lib/v2/dongqiudi/result.js @@ -6,7 +6,7 @@ module.exports = async (ctx) => { const team = ctx.params.team; const link = `https://www.dongqiudi.com/team/${team}.html`; - const response = await got.get(link); + const response = await got(link); const dom = new JSDOM(response.data, { runScripts: 'dangerously', }); diff --git a/lib/v2/dongqiudi/router.js b/lib/v2/dongqiudi/router.js index a322f9d3e..11fb94e8c 100644 --- a/lib/v2/dongqiudi/router.js +++ b/lib/v2/dongqiudi/router.js @@ -1,5 +1,5 @@ module.exports = (router) => { - router.get('/daily', require('./daily')); + router.redirect('/daily', '/dongqiudi/special/48'); router.get('/player_news/:id', require('./player_news')); router.get('/result/:team', require('./result')); router.get('/special/:id', require('./special')); diff --git a/lib/v2/dongqiudi/special.js b/lib/v2/dongqiudi/special.js index c16369526..4e6506a6d 100644 --- a/lib/v2/dongqiudi/special.js +++ b/lib/v2/dongqiudi/special.js @@ -4,44 +4,38 @@ 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 response = await got(`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 list = $('.detail.special ul li h3') + .slice(0, ctx.query.limit ? Number(ctx.query.limit) : 5) + .toArray() + .map((item) => { + item = $(item); + return { + title: item.find('a').text(), + link: host + item.find('a').attr('href'), + }; + }); const out = await Promise.all( - list.map(async (item) => { - const $ = cheerio.load(item); - const title = $('a').text(); - const itemUrl = host + $('a').attr('href'); + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link); - const cache = await ctx.cache.get(itemUrl); - if (cache) { - return Promise.resolve(JSON.parse(cache)); - } + utils.ProcessFeedType2(item, response); - const single = { - title, - link: itemUrl, - }; - - const es = got.get(itemUrl); - proList.push(es); - return Promise.resolve(single); - }) + return item; + }) + ) ); - 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}`, + title: `懂球帝专题-${$('.detail.special h1').text()}`, + description: $('.detail.special h4').text(), link: `https://www.dongqiudi.com/special/${id}`, item: out.filter((e) => e !== undefined), }; diff --git a/lib/v2/dongqiudi/team_news.js b/lib/v2/dongqiudi/team_news.js index 4a6ddb8a5..9d2c1375e 100644 --- a/lib/v2/dongqiudi/team_news.js +++ b/lib/v2/dongqiudi/team_news.js @@ -1,8 +1,7 @@ const utils = require('./utils'); module.exports = async (ctx) => { - const team = ctx.params.team; - const link = `https://www.dongqiudi.com/team/${team}.html`; + const teamId = ctx.params.team; - await utils.ProcessFeed(ctx, link, 'team'); + await utils.ProcessFeed(ctx, 'team', teamId); }; diff --git a/lib/v2/dongqiudi/top_news.js b/lib/v2/dongqiudi/top_news.js index 838e62bd0..836278f83 100644 --- a/lib/v2/dongqiudi/top_news.js +++ b/lib/v2/dongqiudi/top_news.js @@ -1,39 +1,33 @@ const got = require('@/utils/got'); const utils = require('./utils'); +const { parseDate } = require('@/utils/parse-date'); module.exports = async (ctx) => { const id = ctx.params.id ?? 1; - const response = await got(`https://api.dongqiudi.com/app/tabs/iphone/${id}.json?mark=gif&version=576`); - const data = response.data.articles; - const label = response.data.label; + const { data } = await got(`https://api.dongqiudi.com/app/tabs/web/${id}.json`); + const articles = data.articles; + const label = data.label; - const proList = []; + const list = articles.map((item) => ({ + title: item.title, + link: `https://www.dongqiudi.com/articles/${item.id}.html`, + category: [item.category, ...(item.secondary_category ? item.secondary_category : [])], + pubDate: parseDate(item.show_time), + })); const out = await Promise.all( - data.map((item) => { - const title = item.title; - const itemUrl = `https://www.dongqiudi.com/news/${item.id}.html`; - - return ctx.cache.tryGet(itemUrl, () => { - const single = { - title, - link: itemUrl, - }; - - const es = got(itemUrl); - proList.push(es); - return single; - }); - }) + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link); + utils.ProcessFeedType2(item, response); + return item; + }) + ) ); - 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: `懂球帝 - ${label}`, - link: 'http://dongqiudi.com/news', + link: `https://www.dongqiudi.com/articlesList/${id}`, item: out.filter((e) => e !== undefined), }; }; diff --git a/lib/v2/dongqiudi/utils.js b/lib/v2/dongqiudi/utils.js index 4e2ae67a3..e18631b02 100644 --- a/lib/v2/dongqiudi/utils.js +++ b/lib/v2/dongqiudi/utils.js @@ -61,57 +61,57 @@ const ProcessImg = (content) => { }); }; -const ProcessFeed = async (ctx, link, type) => { - const got_ins = got.extend({ - headers: { - Referer: link, - }, - }); - - const response = await got_ins.get(link); +const ProcessFeed = async (ctx, type, id) => { + const link = `https://www.dongqiudi.com/${type}/${id}.html`; + const apiUrl = `https://api.dongqiudi.com/v3/archive/app/channel/feeds`; + const { data: response } = await got(link); let name; - const dom = new JSDOM(response.data, { + const { window } = new JSDOM(response, { runScripts: 'dangerously', }); - const data = dom.window.__NUXT__.data[0]; - const list = data.relatedNewsList; - + const typeInfo = window.__NUXT__.data[0][`${type}Detail`].base_info; if (type === 'team') { - name = data.teamDetail.base_info.team_name; + name = typeInfo.team_name; } else if (type === 'player') { - name = data.playerDetail.base_info.person_name; + name = typeInfo.person_name; } - const proList = []; + + const { data } = await got(apiUrl, { + searchParams: { + id, + type, + size: 20, + platform: 'web', + version: '', + }, + }); + + const list = data.data.articles.map((article) => ({ + title: article.title, + link: `https://www.dongqiudi.com/articles/${article.id}.html`, + category: [article.category, ...(article.secondary_category ? article.secondary_category : [])], + pubDate: parseDate(article.show_time), + })); const out = await Promise.all( - list.map((item) => { - const title = item.title; - const link = `https://www.dongqiudi.com/news/${item.id}.html`; + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const { data: response } = await got(item.link); - return ctx.cache.tryGet(link, () => { - const single = { - title, - link, - }; + ProcessFeedType2(item, response); - const es = got(link); - proList.push(es); - return single; - }); - }) + return item; + }) + ) ); - const responses = await got.all(proList); - for (let i = 0; i < proList.length; i++) { - ProcessFeedType2(out[i], responses[i].data); - } - ctx.state.data = { title: `${name} - 相关新闻`, link, + image: type === 'team' ? typeInfo.team_logo : typeInfo.person_logo, item: out, }; }; @@ -134,7 +134,7 @@ const ProcessFeedType2 = (item, response) => { ProcessImg(body('img')); item.description = body.html(); item.author = data.writer; - item.pubDate = parseDate(data.show_time * 1000); + item.pubDate = parseDate(data.show_time, 'X'); } };