feat: 添加对 鲸跃汽车文章 的支持 (#3150)

This commit is contained in:
Jeason0228
2019-09-27 13:33:04 +08:00
committed by DIYgod
parent 84ded422f1
commit f8400d4f5b
3 changed files with 68 additions and 0 deletions
+10
View File
@@ -375,6 +375,16 @@ pageClass: routes
<Route author="LogicJake" example="/whalegogo/home" path="/whalegogo/home"/>
### 其他栏目
<Route author="Jeason0228" example="/whalegogo/portal" path="/whalegogo/portal/:type_id/:tagid?/" :paramsDesc="['type_id,栏目id','tagid,标签id']">
| 快讯 | 文章 | 活动 | 评测 | 视频 | 访谈 |
| -------------------- | -------------------- | -------------------- | -------------------- | ------------------ | ------------------ |
| 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 |
</Route>
## 巨潮资讯
### 公司公告
+1
View File
@@ -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'));
+57
View File
@@ -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,
};
};