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

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

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;

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='`,
},