Skip to content

Commit

Permalink
fix(route): 第一财经DT财经报告附件 (DIYgod#14176)
Browse files Browse the repository at this point in the history
  • Loading branch information
nczitzk authored Jan 4, 2024
1 parent b8f7b38 commit 9af1349
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions lib/v2/yicai/dt.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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;
})
Expand Down

0 comments on commit 9af1349

Please sign in to comment.