fix(dongqiudi): adapt routes to new __NUXT__ data structure (#22720)

* route: fix dongqiudi routes for new __NUXT__ data structure

* fix(dongqiudi): remove unused mobile fallback

* fix(dongqiudi): tolerate unavailable special articles

* fix(dongqiudi): remove unnecessary bool return from ProcessFeedType2
This commit is contained in:
whatever
2026-07-25 05:06:28 +08:00
committed by GitHub
parent 4e41ec6670
commit 0294ce99db
6 changed files with 47 additions and 60 deletions
+1 -1
View File
@@ -19,5 +19,5 @@ export const route: Route = {
};
function handler(ctx) {
ctx.set('redirect', '/dongqiudi/special/48');
return ctx.set('redirect', '/dongqiudi/special/48');
}
+1 -1
View File
@@ -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);
}
+15 -10
View File
@@ -1,5 +1,3 @@
import { JSDOM } from 'jsdom';
import type { Route } from '@/types';
import got from '@/utils/got';
import { parseDate } from '@/utils/parse-date';
@@ -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);
const teamName = data.teamDetail.base_info.team_name;
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 = 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 {
+12 -6
View File
@@ -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'],
@@ -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;
})
)
+1 -1
View File
@@ -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(
+17 -41
View File
@@ -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, {
@@ -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(
@@ -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,
};
};
@@ -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 body = ProcessVideo(load(data.rawBody, null, false));
ProcessHref(body('a'));
ProcessImg(body('img'));
item.description = body.html();
item.author = data.author;
};
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;
}
};
export default { ProcessVideo, ProcessFeed, ProcessFeedType2, ProcessFeedType3, ProcessHref, ProcessImg };
export default { ProcessVideo, ProcessFeed, ProcessFeedType2, ProcessHref, ProcessImg };