From 3e3657cdd00ed11396184e272bccca8ac03a7720 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Sun, 27 Jun 2021 08:23:40 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E5=8A=A0=E7=BE=8E?= =?UTF-8?q?=E8=B4=A2=E7=BB=8F=20(#7773)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 10 +++++ lib/router.js | 3 ++ lib/routes/caus/index.js | 88 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 lib/routes/caus/index.js diff --git a/docs/new-media.md b/docs/new-media.md index b07c3fb13..8be1cb4c8 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1291,6 +1291,16 @@ others = 热点新闻 + 滚动新闻 +## 加美财经 + + + +| 全部 | 要闻 | 商业 | 快讯 | 投资理财 | 生活 | +| ---- | ---- | ---- | ---- | -------- | ---- | +| 0 | 1 | 2 | 3 | 4 | 6 | + + + ## 贾真的电商 108 将 ### 「108 将」实战分享 diff --git a/lib/router.js b/lib/router.js index f24a22fa5..4fbf65b22 100644 --- a/lib/router.js +++ b/lib/router.js @@ -4115,4 +4115,7 @@ router.get('/bibgame/:category?/:type?', require('./routes/bibgame/category')); // 澳門特別行政區政府各公共部門獎助貸學金服務平台 router.get('/macau-bolsas/:lang?', require('./routes/macau-bolsas/index')); +// 加美财经 +router.get('/caus/:category?', require('./routes/caus')); + module.exports = router; diff --git a/lib/routes/caus/index.js b/lib/routes/caus/index.js new file mode 100644 index 000000000..424e468e4 --- /dev/null +++ b/lib/routes/caus/index.js @@ -0,0 +1,88 @@ +const got = require('@/utils/got'); + +const categories = { + 0: { + title: '全部', + link: 'home?id=0', + }, + 1: { + title: '要闻', + link: 'focus_news?id=1', + }, + 2: { + title: '商业', + link: 'business?id=2', + }, + 3: { + title: '快讯', + link: 'hours?id=3', + }, + 4: { + title: '投资理财', + link: 'CFT?id=4', + }, + 6: { + title: '生活', + link: 'life?id=6', + }, +}; + +module.exports = async (ctx) => { + const category = ctx.params.category || '0'; + + const isHome = category === '0'; + + const rootUrl = 'https://www.caus.com'; + const apiRootUrl = 'https://api.caus.money'; + + const currentUrl = `${rootUrl}/${categories[category].link}`; + const searchUrl = `${apiRootUrl}/toronto/display/searchList`; + const listUrl = `${apiRootUrl}/toronto/display/lanmuArticlelistNew`; + + const response = await got({ + method: 'post', + url: isHome ? searchUrl : listUrl, + json: isHome + ? { + pageQ: { + pageSize: 10, + sortFiled: 'id', + sortType: 'DESC', + }, + types: ['ARTICLE', 'VIDEO'], + } + : { + filterIds: [], + lanmuId: parseInt(category), + }, + }); + + const list = (isHome ? response.data.data : response.data.data.articleList).map((item) => ({ + title: item.title, + link: item.contentId, + pubDate: new Date(item.createTime), + })); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: `${apiRootUrl}/toronto/display/contentWithRelate?contentId=${item.link}`, + }); + + item.link = `${rootUrl}/detail/${item.link}`; + item.description = detailResponse.data.data.content.content; + + return item; + }) + ) + ); + + ctx.state.data = { + title: `${categories[category].title} - 加美财经`, + link: currentUrl, + item: items, + }; +};