feat(route): Add Liyuan Forums Support (#7131)
Co-authored-by: NeverBehave <gayhub@never.pet>
This commit is contained in:
parent
53cb6f43fe
commit
e5ea410e7d
18
docs/bbs.md
18
docs/bbs.md
|
|
@ -360,6 +360,24 @@ pageClass: routes
|
|||
| 最新主题 | latest |
|
||||
| 精华主题 | digest |
|
||||
|
||||
## 梨园
|
||||
|
||||
### 主题帖(全站)
|
||||
|
||||
<Route author="WooMai" example="/liyuan-forums/threads" path="/liyuan-forums/threads" />
|
||||
|
||||
### 主题帖(板块)
|
||||
|
||||
<Route author="WooMai" example="/liyuan-forums/threads/forum/:forum_id" path="/liyuan-forums/threads/forum/1" :paramsDesc="['板块 ID']" />
|
||||
|
||||
### 主题帖(专题)
|
||||
|
||||
<Route author="WooMai" example="/liyuan-forums/threads/topic/:topic_id" path="/liyuan-forums/threads/topic/1" :paramsDesc="['专题 ID']" />
|
||||
|
||||
### 主题帖(用户)
|
||||
|
||||
<Route author="WooMai" example="/liyuan-forums/threads/user/:user_id" path="/liyuan-forums/threads/user/1" :paramsDesc="['用户 ID, 仅支持数字 ID']" />
|
||||
|
||||
## 龙空
|
||||
|
||||
### 分区
|
||||
|
|
|
|||
|
|
@ -4042,6 +4042,12 @@ router.get('/wainao-reads/all-articles', require('./routes/wainao/index'));
|
|||
// react
|
||||
router.get('/react/react-native-weekly', require('./routes/react/react-native-weekly'));
|
||||
|
||||
// 梨园
|
||||
router.get('/liyuan-forums/threads', require('./routes/liyuan-forums/threads'));
|
||||
router.get('/liyuan-forums/threads/forum/:forum_id', require('./routes/liyuan-forums/threads'));
|
||||
router.get('/liyuan-forums/threads/topic/:topic_id', require('./routes/liyuan-forums/threads'));
|
||||
router.get('/liyuan-forums/threads/user/:user_id', require('./routes/liyuan-forums/threads'));
|
||||
|
||||
// 集思录
|
||||
router.get('/jisilu/reply/:user', require('./routes/jisilu/reply'));
|
||||
router.get('/jisilu/topic/:user', require('./routes/jisilu/topic'));
|
||||
|
|
|
|||
|
|
@ -0,0 +1,61 @@
|
|||
const got = require('@/utils/got');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const forum_id = ctx.params.forum_id || null;
|
||||
const topic_id = ctx.params.topic_id || null;
|
||||
const user_id = ctx.params.user_id || null;
|
||||
|
||||
const query = ['initial_post=1'];
|
||||
|
||||
let link = 'https://forums.liyuans.com/recent';
|
||||
|
||||
if (forum_id) {
|
||||
query.push(`forum_id=${encodeURIComponent(forum_id)}`);
|
||||
link = `https://forums.liyuans.com/forum/${forum_id}`;
|
||||
}
|
||||
|
||||
if (topic_id) {
|
||||
query.push(`topic_id=${encodeURIComponent(topic_id)}`);
|
||||
link = `https://forums.liyuans.com/topic/${topic_id}`;
|
||||
}
|
||||
|
||||
if (user_id) {
|
||||
query.push(`user_id=${encodeURIComponent(user_id)}`);
|
||||
link = `https://forums.liyuans.com/user/${user_id}`;
|
||||
}
|
||||
|
||||
let qstr = '';
|
||||
if (query.length > 0) {
|
||||
qstr = '?' + query.join('&');
|
||||
}
|
||||
|
||||
const response = await got({
|
||||
method: 'get',
|
||||
url: `https://api.forums.liyuans.com/threads${qstr}`,
|
||||
});
|
||||
|
||||
const data = response.data.data.results;
|
||||
|
||||
ctx.state.data = {
|
||||
title: '梨园',
|
||||
link: link,
|
||||
description: '最新帖子 - 梨园',
|
||||
allowEmpty: true,
|
||||
item: data.map((item) => {
|
||||
let category = [item.forum.name];
|
||||
if (item.topic) {
|
||||
category = category.push(item.topic.name);
|
||||
}
|
||||
|
||||
return {
|
||||
title: item.title,
|
||||
author: item.user.nickname,
|
||||
category: category,
|
||||
description: `@${item.user.username}: ${item.initial_post.thumb}`,
|
||||
pubDate: new Date(item.create_time * 1000).toUTCString(),
|
||||
guid: `Thread_${item.id}`,
|
||||
link: `https://forums.liyuans.com/thread/${item.id}`,
|
||||
};
|
||||
}),
|
||||
};
|
||||
};
|
||||
Loading…
Reference in New Issue