parent
03e2e1ea85
commit
6793202023
|
|
@ -392,6 +392,12 @@ type 为 all 时,category 参数不支持 cost 和 free
|
|||
|
||||
<Route author="WenryXu" example="/duozhi" path="/duozhi"/>
|
||||
|
||||
## 飞地
|
||||
|
||||
### 分类
|
||||
|
||||
<Route author="LogicJake" example="/enclavebooks/category/1" path="/enclavebooks/category/:id" :paramsDesc="['类别 id,可在[分类api](https://app.enclavebooks.cn/v2/discovery)返回数据中的category查看']"/>
|
||||
|
||||
## 福利资源-met.red
|
||||
|
||||
### 福利资源-met.red
|
||||
|
|
|
|||
|
|
@ -1299,4 +1299,7 @@ router.get('/curseforge/:gameid/:catagoryid/:projectid/files', require('./routes
|
|||
// 西南财经大学
|
||||
router.get('/swufe/seie/:type?', require('./routes/universities/swufe/seie'));
|
||||
|
||||
// 飞地
|
||||
router.get('/enclavebooks/category/:id?', require('./routes/enclavebooks/category'));
|
||||
|
||||
module.exports = router;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,73 @@
|
|||
const axios = require('@/utils/axios');
|
||||
const host = 'https://www.enclavebooks.cn';
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const id = ctx.params.id;
|
||||
|
||||
const categorys = (await axios({
|
||||
method: 'get',
|
||||
url: 'https://app.enclavebooks.cn/v2/discovery',
|
||||
headers: {
|
||||
Referer: host,
|
||||
},
|
||||
})).data.result.category;
|
||||
|
||||
let category_name, description;
|
||||
for (let i = 0; i < categorys.length; i++) {
|
||||
const item = categorys[i];
|
||||
if (item.cateId === parseInt(id)) {
|
||||
category_name = item.cateName;
|
||||
description = item.cateDescription;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const list = (await axios({
|
||||
method: 'get',
|
||||
url: `https://app.enclavebooks.cn/v1_9/getCategoryList?cateId=${id}&page=1`,
|
||||
headers: {
|
||||
Referer: host,
|
||||
},
|
||||
})).data.result.data;
|
||||
|
||||
const out = await Promise.all(
|
||||
list.map(async (item) => {
|
||||
const title = item.artTitle;
|
||||
const date = item.artTime;
|
||||
const author = item.artEditor;
|
||||
const itemUrl = `https://app.enclavebooks.cn/v2/article?id=${item.artId}`;
|
||||
|
||||
const cache = await ctx.cache.get(itemUrl);
|
||||
if (cache) {
|
||||
return Promise.resolve(JSON.parse(cache));
|
||||
}
|
||||
|
||||
const response = await axios({
|
||||
method: 'get',
|
||||
url: itemUrl,
|
||||
headers: {
|
||||
Referer: host,
|
||||
},
|
||||
});
|
||||
|
||||
const description = response.data.result.artContent;
|
||||
|
||||
const single = {
|
||||
title,
|
||||
link: `http://www.enclavebooks.cn/article.html?art_id=${item.artId}`,
|
||||
description,
|
||||
author,
|
||||
pubDate: new Date(date * 1000).toUTCString(),
|
||||
};
|
||||
ctx.cache.set(itemUrl, JSON.stringify(single));
|
||||
return Promise.resolve(single);
|
||||
})
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${category_name}-飞地`,
|
||||
link: host,
|
||||
description,
|
||||
item: out,
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue