From 7b422cbf90b91a8748eddb9b28f39e2ced130a9c Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sun, 23 Jan 2022 02:23:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(route):=20=E5=8D=8E=E5=B0=94=E8=A1=97?= =?UTF-8?q?=E8=A7=81=E9=97=BB=20(#8729)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/router.js | 4 +- lib/routes/wallstreetcn/live.js | 44 ---------------------- lib/routes/wallstreetcn/news.js | 33 ----------------- lib/v2/wallstreetcn/live.js | 40 ++++++++++++++++++++ lib/v2/wallstreetcn/maintainer.js | 5 +++ lib/v2/wallstreetcn/news.js | 61 +++++++++++++++++++++++++++++++ lib/v2/wallstreetcn/radar.js | 19 ++++++++++ lib/v2/wallstreetcn/router.js | 5 +++ 8 files changed, 132 insertions(+), 79 deletions(-) delete mode 100644 lib/routes/wallstreetcn/live.js delete mode 100644 lib/routes/wallstreetcn/news.js create mode 100644 lib/v2/wallstreetcn/live.js create mode 100644 lib/v2/wallstreetcn/maintainer.js create mode 100644 lib/v2/wallstreetcn/news.js create mode 100644 lib/v2/wallstreetcn/radar.js create mode 100644 lib/v2/wallstreetcn/router.js diff --git a/lib/router.js b/lib/router.js index c7e46a9663..00e9611400 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1286,8 +1286,8 @@ router.get('/taobao/zhongchou/:type?', lazyloadRouteHandler('./routes/taobao/zho router.get('/allpoetry/:order?', lazyloadRouteHandler('./routes/allpoetry/order')); // 华尔街见闻 -router.get('/wallstreetcn/news/global', lazyloadRouteHandler('./routes/wallstreetcn/news')); -router.get('/wallstreetcn/live/:channel?', lazyloadRouteHandler('./routes/wallstreetcn/live')); +// router.get('/wallstreetcn/news/global', lazyloadRouteHandler('./routes/wallstreetcn/news')); +// router.get('/wallstreetcn/live/:channel?', lazyloadRouteHandler('./routes/wallstreetcn/live')); // 多抓鱼搜索 router.get('/duozhuayu/search/:wd', lazyloadRouteHandler('./routes/duozhuayu/search')); diff --git a/lib/routes/wallstreetcn/live.js b/lib/routes/wallstreetcn/live.js deleted file mode 100644 index 6455fea5d8..0000000000 --- a/lib/routes/wallstreetcn/live.js +++ /dev/null @@ -1,44 +0,0 @@ -const got = require('@/utils/got'); - -const config = { - global: '要闻', - 'a-stock': 'A股', - 'us-stock': '美股', - 'hk-stock': '港股', - forex: '外汇', - commodity: '商品', - financing: '理财', -}; - -module.exports = async (ctx) => { - ctx.params.channel = ctx.params.channel || 'global'; - - const currentUrl = `https://wallstreetcn.com/live/${ctx.params.channel}`; - const rootUrl = `https://api.wallstcn.com/apiv1/content/lives?channel=${ctx.params.channel}-channel`; - const response = await got({ - method: 'get', - url: rootUrl, - }); - - const items = response.data.data.items.map((item) => { - let title; - const match = item.content_text.match(/【(.*)】/); - if (match !== null) { - title = match[1]; - } else { - title = item.content_text; - } - return { - title, - link: `https://wallstreetcn.com/livenews/${item.id}`, - pubDate: new Date(item.display_time * 1000).toUTCString(), - description: item.content, - }; - }); - - ctx.state.data = { - title: `${config[ctx.params.channel]} - 实时快讯 - 华尔街见闻`, - link: currentUrl, - item: items, - }; -}; diff --git a/lib/routes/wallstreetcn/news.js b/lib/routes/wallstreetcn/news.js deleted file mode 100644 index f520be4409..0000000000 --- a/lib/routes/wallstreetcn/news.js +++ /dev/null @@ -1,33 +0,0 @@ -const got = require('@/utils/got'); - -module.exports = async (ctx) => { - const response = await got({ - method: 'get', - url: 'https://api-prod.wallstreetcn.com/apiv1/content/fabricate-articles?limit=30&channel=global', - }); - - const data = response.data; - const stateData = { - title: '华尔街见闻', - link: 'https://wallstreetcn.com/news/global', - description: '华尔街见闻-中国领先的商业和金融信息提供商,首创商业和金融信息“实时”模式,重要信息秒级推送。7*24小时全年不间断为用户提供资讯、数据、行情、研究和社区等服务。', - item: [], - }; - - if (data.data && Array.isArray(data.data.items)) { - data.data.items.forEach((item) => { - if (item.resource_type !== 'article') { - return; - } - stateData.item.push({ - title: item.resource.title, - description: item.resource.content_short, - pubDate: new Date(item.resource.display_time * 1000).toUTCString(), - guid: item.resource.id, - link: decodeURI(item.resource.uri), - author: item.resource.author && item.resource.author.display_name, - }); - }); - } - ctx.state.data = stateData; -}; diff --git a/lib/v2/wallstreetcn/live.js b/lib/v2/wallstreetcn/live.js new file mode 100644 index 0000000000..ef0b237708 --- /dev/null +++ b/lib/v2/wallstreetcn/live.js @@ -0,0 +1,40 @@ +const got = require('@/utils/got'); +const { parseDate } = require('@/utils/parse-date'); + +const titles = { + global: '要闻', + 'a-stock': 'A股', + 'us-stock': '美股', + 'hk-stock': '港股', + forex: '外汇', + commodity: '商品', + financing: '理财', +}; + +module.exports = async (ctx) => { + const category = ctx.params.category ?? 'global'; + + const rootUrl = 'https://wallstreetcn.com'; + const apiRootUrl = 'https://api-one.wallstcn.com'; + const currentUrl = `${rootUrl}/live/${category}`; + const apiUrl = `${apiRootUrl}/apiv1/content/lives?channel=${category}-channel&limit=${ctx.query.limit ?? 50}`; + + const response = await got({ + method: 'get', + url: apiUrl, + }); + + const items = response.data.data.items.map((item) => ({ + link: item.uri, + title: item.title || item.content_text, + description: item.content, + pubDate: parseDate(item.display_time * 1000), + author: item.author.display_name, + })); + + ctx.state.data = { + title: `${titles[category]} - 实时快讯 - 华尔街见闻`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/wallstreetcn/maintainer.js b/lib/v2/wallstreetcn/maintainer.js new file mode 100644 index 0000000000..9c3b0b14be --- /dev/null +++ b/lib/v2/wallstreetcn/maintainer.js @@ -0,0 +1,5 @@ +module.exports = { + '/live/:category?': ['nczitzk'], + '/news/:category?': ['nczitzk'], + '/:category?': ['nczitzk'], +}; diff --git a/lib/v2/wallstreetcn/news.js b/lib/v2/wallstreetcn/news.js new file mode 100644 index 0000000000..9d9990239e --- /dev/null +++ b/lib/v2/wallstreetcn/news.js @@ -0,0 +1,61 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseDate } = require('@/utils/parse-date'); + +const titles = { + global: '最新', + shares: '股市', + bonds: '债市', + commodities: '商品', + forex: '外汇', + enterprise: '公司', + 'asset-manage': '资管', + tmt: '科技', + estate: '地产', + car: '汽车', + medicine: '医药', +}; + +module.exports = async (ctx) => { + const category = ctx.params.category ?? 'global'; + + const rootUrl = 'https://wallstreetcn.com'; + const apiRootUrl = 'https://api-one.wallstcn.com'; + const currentUrl = `${rootUrl}/live/${category}`; + const apiUrl = `${apiRootUrl}/apiv1/content/information-flow?channel=${category}-channel&accept=article&limit=25`; + + const response = await got({ + method: 'get', + url: apiUrl, + }); + + let items = response.data.data.items.map((item) => ({ + link: item.resource.uri, + title: item.resource?.title, + author: item.resource.author?.display_name, + pubDate: parseDate(item.resource.display_time * 1000), + })); + + items = await Promise.all( + items.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + }); + + const content = cheerio.load(detailResponse.data); + + item.description = content('.rich-text, .live-detail-html').html(); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${titles[category]} - 资讯 - 华尔街见闻`, + link: currentUrl, + item: items, + }; +}; diff --git a/lib/v2/wallstreetcn/radar.js b/lib/v2/wallstreetcn/radar.js new file mode 100644 index 0000000000..2c2b4d1dd3 --- /dev/null +++ b/lib/v2/wallstreetcn/radar.js @@ -0,0 +1,19 @@ +module.exports = { + 'wallstreetcn.com': { + _name: '华尔街见闻', + '.': [ + { + title: '资讯', + docs: 'https://docs.rsshub.app/traditional-media.html#hua-er-jie-jian-wen-zi-xun', + source: ['/news/:category', '/'], + target: '/wallstreetcn/news/:category?', + }, + { + title: '实时快讯', + docs: 'https://docs.rsshub.app/traditional-media.html#hua-er-jie-jian-wen-shi-shi-kuai-xun', + source: ['/live/:category', '/'], + target: '/wallstreetcn/live/:category?', + }, + ], + }, +}; diff --git a/lib/v2/wallstreetcn/router.js b/lib/v2/wallstreetcn/router.js new file mode 100644 index 0000000000..2ccacc3e42 --- /dev/null +++ b/lib/v2/wallstreetcn/router.js @@ -0,0 +1,5 @@ +module.exports = function (router) { + router.get('/live/:category?', require('./live')); + router.get('/news/:category?', require('./news')); + router.get('/:category?', require('./news')); +};