fix(route): 虎扑社区比赛信息 (#10742)

This commit is contained in:
Ethan Shen 2022-09-08 18:32:01 +08:00 committed by GitHub
parent c6dd4e2495
commit 58156eaa50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 1 deletions

View File

@ -2,12 +2,15 @@ const got = require('@/utils/got');
const cheerio = require('cheerio');
const timezone = require('@/utils/timezone');
const { parseDate } = require('@/utils/parse-date');
const { art } = require('@/utils/render');
const path = require('path');
module.exports = async (ctx) => {
const id = ctx.params.id ?? '34';
const order = ctx.params.order ?? '1';
const rootUrl = 'https://bbs.hupu.com';
const apiRootUrl = 'https://games.mobileapi.hupu.com';
const currentUrl = `${rootUrl}/${id}${order === '1' ? `-postdate` : ''}`;
const response = await got({
@ -35,7 +38,7 @@ module.exports = async (ctx) => {
items.map((item) =>
ctx.cache.tryGet(item.link, async () => {
try {
const detailResponse = await got({
let detailResponse = await got({
method: 'get',
url: item.link,
});
@ -46,6 +49,24 @@ module.exports = async (ctx) => {
item.author = content('.post-user-comp-info-top-name').first().text();
item.description = content('.main-thread').first().html();
const matches = detailResponse.data.match(/matchId=(\d+)-BATTLE_REPORT/);
if (matches) {
detailResponse = await got({
method: 'get',
url: `${apiRootUrl}/1/7.5.36/basketballapi/news/battleReport?relationId=${matches[1]}&relationType=BATTLE_REPORT`,
});
const result = detailResponse.data.result;
item.description = art(path.join(__dirname, 'templates/description.art'), {
image: result.img,
description: result.beginContent,
keyEvent: result.keyEvent,
playerImage: result.playerScoreImg,
});
}
} catch (e) {
// no-empty
}

View File

@ -0,0 +1,22 @@
{{ if image }}
<img src="{{ image }}">
{{ /if }}
{{ if description }}
<p>{{ description }}</p>
{{ /if }}
{{ if keyEvent }}
<h1>关键事件</h1>
{{ each keyEvent event }}
<p>{{ event.title }}</p>
{{ each event.gifImgs gif }}
<img src="{{ gif }}">
{{ /each }}
{{ /each }}
{{ /if }}
{{ if playerImage }}
<h1>球员评分</h1>
<img src="{{ playerImage }}">
{{ /if }}