From f8400d4f5b96b6453bd6d2976032daaeda440c85 Mon Sep 17 00:00:00 2001 From: Jeason0228 <44083849+Jeason0228@users.noreply.github.com> Date: Fri, 27 Sep 2019 13:33:04 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=AF=B9=20=E9=B2=B8?= =?UTF-8?q?=E8=B7=83=E6=B1=BD=E8=BD=A6=E6=96=87=E7=AB=A0=20=E7=9A=84?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20(#3150)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 10 ++++++ lib/router.js | 1 + lib/routes/whalegogo/portal.js | 57 ++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+) create mode 100644 lib/routes/whalegogo/portal.js diff --git a/docs/new-media.md b/docs/new-media.md index 8a0a529df2..2494b6c343 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -375,6 +375,16 @@ pageClass: routes +### 其他栏目 + + + +| 快讯 | 文章 | 活动 | 评测 | 视频 | 访谈 | +| -------------------- | -------------------- | -------------------- | -------------------- | ------------------ | ------------------ | +| type_id=2,tagid 不填 | type_id=1,tagid 不填 | type_id=7,tagid 不填 | type_id=8,tagid 不填 | type_id=1,tagid=70 | type_id=1,tagid=73 | + + + ## 巨潮资讯 ### 公司公告 diff --git a/lib/router.js b/lib/router.js index aa0a86faec..ca0f7722f9 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1089,6 +1089,7 @@ router.get('/wenku8/chapter/:id', require('./routes/wenku8/chapter')); // 鲸跃汽车 router.get('/whalegogo/home', require('./routes/whalegogo/home')); +router.get('/whalegogo/portal/:type_id/:tagid?/', require('./routes/whalegogo/portal')); // 爱思想 router.get('/aisixiang/column/:id', require('./routes/aisixiang/column')); diff --git a/lib/routes/whalegogo/portal.js b/lib/routes/whalegogo/portal.js new file mode 100644 index 0000000000..c846da150a --- /dev/null +++ b/lib/routes/whalegogo/portal.js @@ -0,0 +1,57 @@ +const got = require('@/utils/got'); +module.exports = async (ctx) => { + const type_id = ctx.params.type_id || '2'; + const tagid = ctx.params.tagid || ''; + const sort = ctx.params.sort || '-push_at'; + const url = `https://www.whalegogo.com/list/portal-${type_id}?tag_id=all`; + // type_id = 2:快讯 / 1:文章 / 7:活动 / 8:评测 + // tagid = 70:视频 /73:访谈 + // sort = -push_at 最新 / hot最热 + const response = await got({ + method: 'get', + url: `https://api.whalegogo.com/v1/articles/search?tagid=${tagid}&type_id=${type_id}&sort=${sort}&page=1&per-page=12`, + headers: { + Referer: url, + }, + }); + const list = response.data.items; + const out = await Promise.all( + list.map(async (info) => { + const title = info.title; + const date = info.push_at; + const id = info.id; + // const cid = info.cid; + const author = info.author.username; + const itemUrl = `https://www.whalegogo.com/news?id=${id}`; + const cache = await ctx.cache.get(itemUrl); + // console.log(cid); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + const response = await got({ + method: 'get', + url: `https://api.whalegogo.com/v1/articles/${id}?expand=content`, + headers: { + Referer: url, + }, + }); + const description = response.data.content; + + const single = { + title: title, + author, + link: itemUrl, + description: description, + pubDate: new Date(date * 1000).toUTCString(), + }; + ctx.cache.set(itemUrl, JSON.stringify(single)); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: '鲸跃汽车', + link: url, + item: out, + }; +};