From f7a31fd758d73bf465a186688e856e31a4a5aa78 Mon Sep 17 00:00:00 2001 From: Chenyang Shi Date: Tue, 19 Feb 2019 14:26:28 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E9=B2=B8=E8=B7=83=E6=B1=BD=E8=BD=A6=20(#?= =?UTF-8?q?1558)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #1555 --- docs/README.md | 4 ++++ lib/router.js | 3 +++ lib/routes/whalegogo/home.js | 43 ++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 lib/routes/whalegogo/home.js diff --git a/docs/README.md b/docs/README.md index 523e446f0..7d241a88e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2958,3 +2958,7 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看 + +### 鲸跃汽车 + + diff --git a/lib/router.js b/lib/router.js index ff3b1f939..dca04af4a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1045,6 +1045,9 @@ router.get('/gaoqing/latest', require('./routes/gaoqing/latest')); // 轻小说文库 router.get('/wenku8/chapter/:id', require('./routes/wenku8/chapter')); +// 鲸跃汽车 +router.get('/whalegogo/home', require('./routes/whalegogo/home')); + // 爱思想 router.get('/aisixiang/column/:id', require('./routes/aisixiang/column')); router.get('/aisixiang/ranking/:type?/:range?', require('./routes/aisixiang/ranking')); diff --git a/lib/routes/whalegogo/home.js b/lib/routes/whalegogo/home.js new file mode 100644 index 000000000..1cc44bf0f --- /dev/null +++ b/lib/routes/whalegogo/home.js @@ -0,0 +1,43 @@ +const axios = require('../../utils/axios'); + +module.exports = async (ctx) => { + const url = 'https://m.whalegogo.com/index'; + const response = await axios.get('https://api.whalegogo.com/v1/app/index'); + + 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://m.whalegogo.com/article?id=${id}&cid=${cid}`; + + const cache = await ctx.cache.get(itemUrl); + if (cache) { + return Promise.resolve(JSON.parse(cache)); + } + + const response = await axios.get(`https://api.whalegogo.com/v1/articles/${id}?expand=content`); + 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), 24 * 60 * 60); + return Promise.resolve(single); + }) + ); + + ctx.state.data = { + title: '鲸跃汽车', + link: url, + item: out, + }; +};