From 9af13494c3438fece2fc1ac7f1ea189893c524da Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Thu, 4 Jan 2024 12:06:17 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20=E7=AC=AC=E4=B8=80=E8=B4=A2?= =?UTF-8?q?=E7=BB=8FDT=E8=B4=A2=E7=BB=8F=E6=8A=A5=E5=91=8A=E9=99=84?= =?UTF-8?q?=E4=BB=B6=20(#14176)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/v2/yicai/dt.js | 53 ++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/lib/v2/yicai/dt.js b/lib/v2/yicai/dt.js index e7f84400bfd0a4..30cd8b43ec5978 100644 --- a/lib/v2/yicai/dt.js +++ b/lib/v2/yicai/dt.js @@ -4,48 +4,53 @@ const { parseDate } = require('@/utils/parse-date'); const { art } = require('@/utils/render'); const path = require('path'); -const types = { +const columns = { article: 2, report: 3, visualization: 4, }; module.exports = async (ctx) => { - const { type = 'article', category = '0' } = ctx.params; + const { column = 'article', category = '0' } = ctx.params; const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 30; const rootUrl = 'https://dt.yicai.com'; const apiUrl = new URL('api/getNewsList', rootUrl).href; - const currentUrl = new URL(type, rootUrl).href; + const currentUrl = new URL(column, rootUrl).href; const { data: response } = await got(apiUrl, { searchParams: { page: 1, - rid: types[type], + rid: columns[column], cid: category, pageSize: limit, }, }); - let items = response.data.data.slice(0, limit).map((item) => ({ - title: item.newstitle, - link: new URL(item.url, rootUrl).href, - description: art(path.join(__dirname, 'templates/description.art'), { - image: { - src: item.originPic, - alt: item.newstitle, - }, - intro: item.newsnotes, - }), - author: item.creatername, - category: [item.channelrootname, item.channelname, item.NewsTypeName].filter((c) => c), - guid: `yicai-dt-${item.newsid}`, - pubDate: parseDate(item.utc_createdate), - updated: parseDate(item.utc_lastdate), - enclosure_url: item.originVideo, - enclosure_type: item.originVideo ? `video/${item.originVideo.split(/\./).pop()}` : undefined, - upvotes: item.newsscore ?? 0, - })); + let items = response.data.data.slice(0, limit).map((item) => { + const enclosureUrl = item.originVideo; + const enclosureExt = enclosureUrl.split(/\./).pop(); + + return { + title: item.newstitle, + link: new URL(item.url, rootUrl).href, + description: art(path.join(__dirname, 'templates/description.art'), { + image: { + src: item.originPic, + alt: item.newstitle, + }, + intro: item.newsnotes, + }), + author: item.creatername, + category: [item.channelrootname, item.channelname, item.NewsTypeName].filter((c) => c), + guid: `yicai-dt-${item.newsid}`, + pubDate: parseDate(item.utc_createdate), + updated: parseDate(item.utc_lastdate), + enclosure_url: enclosureUrl, + enclosure_type: enclosureUrl ? `${enclosureExt === 'mp4' ? 'video' : 'application'}/${enclosureExt}` : undefined, + upvotes: item.newsscore ?? 0, + }; + }); items = await Promise.all( items.map((item) => @@ -75,8 +80,6 @@ module.exports = async (ctx) => { description: content('div.txt').html(), }); item.author = content('div.authortime h3').text(); - item.enclosure_url = ''; - item.enclosure_type = 'video/mp4'; return item; })