feat: AI研习社添加参数 (#2416)

* enhance: AI研习社添加参数

* 支持查看不同领域
* 排序方式

* fix warning

* enhance: 添加更多类别
This commit is contained in:
Chenyang Shi
2019-06-16 20:31:52 +08:00
committed by DIYgod
parent 7e0ca8aaee
commit 59b2196b28
3 changed files with 22 additions and 4 deletions
+2 -2
View File
@@ -6,9 +6,9 @@ pageClass: routes
## AI 研习社
### 最新
### 首页
<Route author="kt286" example="/aiyanxishe" path="/aiyanxishe"/>
<Route author="kt286" example="/aiyanxishe/109/hot" path="/aiyanxishe/:id/:sort?" :paramsDesc="['领域 id,全部领域为 all,单独领域 id 抓包可得','排序方式,默认为 new(最新),也可选择 hot(最热)或 recommend(推荐)']"/>
## AlgoCasts
+1 -1
View File
@@ -1419,6 +1419,6 @@ router.get('/outagereport/:name/:count?', require('./routes/outagereport/service
router.get('/sixthtone/news', require('./routes/sixthtone/news'));
// AI研习社
router.get('/aiyanxishe/', require('./routes/aiyanxishe/home'));
router.get('/aiyanxishe/:id/:sort?', require('./routes/aiyanxishe/home'));
module.exports = router;
+19 -1
View File
@@ -1,9 +1,27 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const id = ctx.params.id;
const sort = ctx.params.sort || 'new';
let url = 'https://www.leiphone.com/club/api?page=1&size=30&parent_tag=';
if (id === 'all') {
url += '&tag=';
} else {
url += `&tag=${id}`;
}
if (sort === 'hot') {
url += '&is_hot=1&is_recommend=0';
} else if (sort === 'recommend') {
url += '&is_hot=0&is_recommend=1';
} else {
url += '&is_hot=0&is_recommend=0';
}
const response = await got({
method: 'GET',
url: 'https://www.leiphone.com/club/api?page=1&size=30&is_hot=0&is_recommend=0&tag=&parent_tag=',
url: url,
headers: {
Referer: `https://www.leiphone.com/club/api?page=1&size=30&is_hot=0&is_recommend=0&tag=&parent_tag='`,
},