Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/routes/dongqiudi/daily.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ export const route: Route = {
};

function handler(ctx) {
ctx.set('redirect', '/dongqiudi/special/48');
return ctx.set('redirect', '/dongqiudi/special/48');
}
2 changes: 1 addition & 1 deletion lib/routes/dongqiudi/player-news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ export const route: Route = {
async function handler(ctx) {
const playerId = ctx.req.param('id');

await utils.ProcessFeed(ctx, 'player', playerId);
return await utils.ProcessFeed(ctx, 'player', playerId);
}
25 changes: 15 additions & 10 deletions lib/routes/dongqiudi/result.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { JSDOM } from 'jsdom';

import type { Route } from '@/types';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
Expand All @@ -24,20 +22,27 @@ async function handler(ctx) {
const team = ctx.req.param('team');
const link = `https://www.dongqiudi.com/team/${team}.html`;

const response = await got(link);
const dom = new JSDOM(response.data, {
runScripts: 'dangerously',
});
const data = dom.window.__NUXT__.data[0];
const resultData = data.teamScheduleData.filter((data) => data.fs_A && data.fs_B);
const { data: scheduleData } = await got(`https://api.dongqiudi.com/data/v1/team/schedule/${team}`);
const lastSeason = scheduleData.season_list.find((s) => !s.current);

if (!lastSeason) {
return {
title: `${team} 比赛结果`,
link,
item: [],
};
}

const { data: seasonResp } = await got(lastSeason.url);
const resultData = seasonResp.data.filter((match) => match.fs_A && match.fs_B);

const teamName = data.teamDetail.base_info.team_name;
const teamName = resultData.length ? (resultData[0].team_A_id === team ? resultData[0].team_A_name : resultData[0].team_B_name) : team;

const out = resultData.map((result) => ({
title: `${result.match_title} ${result.team_A_name} ${result.fs_A}-${result.fs_B} ${result.team_B_name}`,
guid: result.match_id,
link: result.scheme.replace('dongqiudi:///game/', 'https://www.dongqiudi.com/liveDetail/'),
pubDate: parseDate(result.start_time),
pubDate: parseDate(result.start_play),
}));

return {
Expand Down
18 changes: 12 additions & 6 deletions lib/routes/dongqiudi/special.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export const route: Route = {
path: '/special/:id',
categories: ['sport'],
example: '/dongqiudi/special/41',
parameters: { id: '专题 id, 可自行通过 https://www.dongqiudi.com/special/+数字匹配' },
parameters: {
id: '专题 id, 可自行通过 https://www.dongqiudi.com/special/+数字匹配',
},
radar: [
{
source: ['www.dongqiudi.com/special/:id'],
Expand All @@ -30,17 +32,21 @@ async function handler(ctx) {
const list = response.data.map((item) => ({
title: item.title,
link: `https://www.dongqiudi.com/articles/${item.aid}.html`,
mobileLink: `https://m.dongqiudi.com/article/${item.aid}.html`,
pubDate: parseDate(item.show_time, 'X'),
}));

const out = await Promise.all(
list.map((item) =>
cache.tryGet(item.link, async () => {
const { data: response } = await got(item.mobileLink);

utils.ProcessFeedType3(item, response);

try {
const { data: response } = await got(item.link);
utils.ProcessFeedType2(item, response);
} catch (error) {
if (!(error instanceof Error) || !['HTTPError', 'RequestError', 'FetchError'].includes(error.name)) {
throw error;
}
// Keep the list item when the article page is gone or temporarily unavailable.
}
return item;
})
)
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/dongqiudi/top-news.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function handler(ctx) {
title: item.title,
link: `https://www.dongqiudi.com/articles/${item.id}.html`,
category: [item.category, ...(item.secondary_category ?? [])],
pubDate: parseDate(item.show_time),
pubDate: parseDate(item.show_time, 'X'),
}));

const out = await Promise.all(
Expand Down
58 changes: 17 additions & 41 deletions lib/routes/dongqiudi/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,19 @@ const ProcessFeed = async (ctx, type, id) => {
const apiUrl = 'https://api.dongqiudi.com/v3/archive/app/channel/feeds';
const { data: response } = await got(link);

let name;

const { window } = new JSDOM(response, {
runScripts: 'dangerously',
});

const typeInfo = window.__NUXT__.data[0][`${type}Detail`].base_info;
const nuxtData = window.__NUXT__.data[0];
let name;
let image;
if (type === 'team') {
name = typeInfo.team_name;
} else if (type === 'player') {
name = typeInfo.person_name;
name = nuxtData.teamInfo.name;
image = nuxtData.teamInfo.logo;
} else {
name = nuxtData.detail.base_info.person_name;
image = nuxtData.detail.base_info.person_logo;
}

const { data } = await got(apiUrl, {
Expand All @@ -95,7 +97,7 @@ const ProcessFeed = async (ctx, type, id) => {
title: article.title,
link: `https://www.dongqiudi.com/articles/${article.id}.html`,
category: [article.category, ...(article.secondary_category ?? [])],
pubDate: parseDate(article.show_time),
pubDate: parseDate(article.show_time, 'X'),
}));

const out = await Promise.all(
Expand All @@ -113,7 +115,7 @@ const ProcessFeed = async (ctx, type, id) => {
return {
title: `${name} - 相关新闻`,
link,
image: type === 'team' ? typeInfo.team_logo : typeInfo.person_logo,
image,
item: out,
};
};
Expand All @@ -123,44 +125,18 @@ const ProcessFeedType2 = (item, response) => {
runScripts: 'dangerously',
});

const data = dom.window.__NUXT__.data[0].newData;
const data = dom.window.__NUXT__?.data?.[0]?.article;

// filter out undefined item
if (!data) {
return;
}

if (Object.keys(data).length > 0) {
const body = ProcessVideo(load(data.body, null, false));
ProcessHref(body('a'));
ProcessImg(body('img'));
item.description = body.html();
item.author = data.writer;
item.pubDate = parseDate(data.show_time, 'X');
}
};

const ProcessFeedType3 = (item, response) => {
const $ = load(response);
const initialState = JSON.parse(
$('script:contains("window.__INITIAL_STATE__")')
.text()
.match(/window\.__INITIAL_STATE__\s*=\s*((?:\S.*?)??);\(/)[1]
);

// filter out undefined item
if (!initialState) {
return;
}

if (Object.keys(initialState.articleContent).length) {
const data = Object.values(initialState.articleContent)[0];
const body = ProcessVideo(load(data.body, null, false));
ProcessHref(body('a'));
ProcessImg(body('img'));
item.description = body.html();
item.author = data.writer;
}
const body = ProcessVideo(load(data.rawBody, null, false));
ProcessHref(body('a'));
ProcessImg(body('img'));
item.description = body.html();
item.author = data.author;
};

export default { ProcessVideo, ProcessFeed, ProcessFeedType2, ProcessFeedType3, ProcessHref, ProcessImg };
export default { ProcessVideo, ProcessFeed, ProcessFeedType2, ProcessHref, ProcessImg };