feat: 新增爱发电afdian.net (#2673)

This commit is contained in:
sanmmmm
2019-07-23 01:44:02 +08:00
committed by DIYgod
parent 78327f76e0
commit 8f3c2493a2
4 changed files with 120 additions and 0 deletions

View File

@@ -10,6 +10,29 @@ pageClass: routes
<Route author="xyqfer" example="/westore/new" path="/westore/new"/> <Route author="xyqfer" example="/westore/new" path="/westore/new"/>
## 爱发电
### 发现用户
<Route author="sanmmm" example="/afdian/explore/hot/所有" path="/afdian/explore/:type/:category?" :paramsDesc="['分类', '目录类型, 默认为 `所有`']">
分类
| 最新 | 推荐 | 最热 |
| ---- | ---- | ---- |
| new | rec | hot |
目录类型
| 所有 | 绘画 | 视频 | 写作 | 游戏 | 音乐 | 播客 | 摄影 | 技术 | Vtuber | 舞蹈 | 体育 | 旅游 | 美食 | 时尚 | 数码 | 动画 | 其他 |
| ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ------ | ---- | ---- | ---- | ---- | ---- | ---- | ---- | ---- |
| 所有 | 绘画 | 视频 | 写作 | 游戏 | 音乐 | 播客 | 摄影 | 技术 | Vtuber | 舞蹈 | 体育 | 旅游 | 美食 | 时尚 | 数码 | 动画 | 其他 |
</Route>
### 用户动态
<Route author="sanmmm" example="/afdian/dynamic/@afdian" path="/afdian/dynamic/:uid?" :paramsDesc="['用户id, 用户动态页面url里可找到']"/>
## 多抓鱼 ## 多抓鱼
### 搜索结果 ### 搜索结果

View File

@@ -1531,6 +1531,10 @@ router.get('/codeceo/:type/:category?', require('./routes/codeceo/category'));
// BOF // BOF
router.get('/bof/home', require('./routes/bof/home')); router.get('/bof/home', require('./routes/bof/home'));
// 爱发电
router.get('/afdian/explore/:type?/:category?', require('./routes/afdian/explore'));
router.get('/afdian/dynamic/:uid', require('./routes/afdian/dynamic'));
// 《明日方舟》游戏 // 《明日方舟》游戏
router.get('/arknights/news', require('./routes/arknights/news')); router.get('/arknights/news', require('./routes/arknights/news'));

View File

@@ -0,0 +1,35 @@
const got = require('@/utils/got');
module.exports = async (ctx) => {
const url_slug = ctx.params.uid.replace('@', '');
const baseUrl = 'https://afdian.net';
const userInfoRes = await got(`${baseUrl}/api/user/get-profile-by-slug`, {
query: {
url_slug,
},
});
const userInfo = userInfoRes.data.data.user;
const { user_id, name } = userInfo;
const dynamicRes = await got(`${baseUrl}/api/post/get-list`, {
query: {
type: 'old',
user_id,
},
});
const list = dynamicRes.data.data.list.map((item) => {
const { publish_time, title, content, pics = [], post_id } = item;
return {
title,
description: [content, pics.map((url) => `<img src="${url}"/>`).join('')].filter((str) => !!str).join('<br/>'),
link: `${baseUrl}/p/${post_id}`,
pubDate: new Date(Number(publish_time) * 1000).toUTCString(),
};
});
ctx.state.data = {
title: `${name}的爱发电动态`,
description: `${name}的爱发电动态`,
link: `${baseUrl}/@${url_slug}`,
item: list,
};
};

View File

@@ -0,0 +1,58 @@
const got = require('@/utils/got');
const categoryMap = {
所有: '',
绘画: '1d2c1ac230dd11e88a2052540025c377',
视频: '68cf9fc630dd11e8aca852540025c377',
写作: '9db3776230dd11e89c6c52540025c377',
游戏: 'ed45455e30dc11e89fd452540025c377',
音乐: 'f89c99b22e6f11e8940c52540025c377',
播客: '5378451a30dd11e8bd4f52540025c377',
摄影: 'ffa47c662e6f11e8b26952540025c377',
技术: 'f62d3e58c39211e88abd52540025c377',
Vtuber: 'e4f952e865cc11e98fb252540025c377',
舞蹈: '98a30fda836b11e9bbf152540025c377',
体育: 'f2212a3c836c11e9842d52540025c377',
旅游: '3935643c836e11e98cc552540025c377',
美食: 'c8d2eaae837011e9bfb652540025c377',
时尚: '05e960f6837311e9984952540025c377',
数码: 'd6163d8c837611e98ac352540025c377',
动画: '67498b10837711e99f0652540025c377',
其他: 'b1643af4328011e8b5b152540025c377',
};
const typeToLabel = {
rec: '推荐',
hot: '人气',
new: '新入驻',
};
module.exports = async (ctx) => {
const { type = 'rec', category = '所有' } = ctx.params;
const baseUrl = 'https://afdian.net';
const link = `${baseUrl}/api/creator/list`;
const res = await got(link, {
query: {
type,
category_id: categoryMap[category],
},
});
const list = res.data.data.list.map((item) => {
const { doing, monthly_fans, detail } = item.creator;
return {
title: item.name,
description: `正在创作 ${doing}<br/>
${monthly_fans}发电人次/月<br/>
详情:<br/>
${detail}<br/>
`,
link: `${baseUrl}/@${item.url_slug}`,
};
});
ctx.state.data = {
title: `爱发电-创作者 (按 ${category}/${typeToLabel[type]})`,
description: `爱发电-发现创作者 (按 ${category}/${typeToLabel[type]})`,
link: `${baseUrl}/explore`,
item: list,
};
};