add 鲸跃汽车 (#1558)

closes #1555
This commit is contained in:
Chenyang Shi 2019-02-19 14:26:28 +08:00 committed by DIYgod
parent 7c0d60478f
commit f7a31fd758
3 changed files with 50 additions and 0 deletions

View File

@ -2958,3 +2958,7 @@ board 和 build 可在[这里](http://api.ineal.me/tss/status)查看
<route name="用户收藏" author="LogicJake" example="/woshipm/bookmarks/324696" path="/woshipm/bookmarks/:id" :paramsDesc="['用户id']"/>
<route name="用户文章" author="LogicJake" example="/woshipm/user_article/324696" path="/woshipm/user_article/:id" :paramsDesc="['用户id']"/>
### 鲸跃汽车
<route name="首页" author="LogicJake" example="/whalegogo/home" path="/whalegogo/home"/>

View File

@ -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'));

View File

@ -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,
};
};