feat(route): hub.baai (#11580)
* feat(route): hub.baai * docs: fix table
This commit is contained in:
@@ -781,6 +781,34 @@ GitHub 官方也提供了一些 RSS:
|
||||
|
||||
<Route author="kaiili" example="/secnews" path="/secnews" />
|
||||
|
||||
## 北京智源人工智能研究院
|
||||
|
||||
### 智源社区
|
||||
|
||||
<Route author="TonyRL" example="/baai/hub" path="/baai/hub/:tagId?/:sort?/:range?" :paramsDesc="['社群 ID,可在 [社群页](https://hub.baai.ac.cn/taglist) 或 URL 中找到', '分类,见下表,默认为 `new`', '时间跨度,仅在分类 `readCnt` 时有效']" radar="1">
|
||||
|
||||
分类
|
||||
|
||||
| 最热 | 最新 | 头条 |
|
||||
| --- | --- | ------- |
|
||||
| hot | new | readCnt |
|
||||
|
||||
时间跨度
|
||||
|
||||
| 3 天 | 7 天 | 30 天 |
|
||||
| --- | --- | ---- |
|
||||
| 3 | 7 | 30 |
|
||||
|
||||
</Route>
|
||||
|
||||
### 智源社区 - 活动
|
||||
|
||||
<Route author="TonyRL" example="/baai/hub/events" path="/baai/hub/events" radar="1"/>
|
||||
|
||||
### 智源社区 - 评论
|
||||
|
||||
<Route author="TonyRL" example="/baai/hub/comments" path="/baai/hub/comments" radar="1"/>
|
||||
|
||||
## 饿了么开放平台
|
||||
|
||||
### 商家开放平台公告
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
const { baseUrl, apiHost } = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const responses = await got.all(
|
||||
Array.from(
|
||||
{
|
||||
// first 2 pages
|
||||
length: (ctx.query.limit ? parseInt(ctx.query.limit, 10) : 12) / 6,
|
||||
},
|
||||
(_, v) => `${apiHost}/api/v1/commentsall?page=${v + 1}`
|
||||
).map((url) => got.post(url))
|
||||
);
|
||||
|
||||
const items = responses
|
||||
.map((response) => response.data.data.list)
|
||||
.flat()
|
||||
.map((item) => ({
|
||||
title: `${item.user_info.name} ${item.title_desc} ${item.title}`,
|
||||
description: item.desc,
|
||||
pubDate: timezone(parseDate(item.created_at), +8),
|
||||
author: item.user_info.name,
|
||||
link: `${baseUrl}/view/${item.source_id || item.story_id}`,
|
||||
guid: `baai:hub:comments:${item.id}`,
|
||||
}));
|
||||
|
||||
ctx.state.data = {
|
||||
title: '评论 - 智源社区',
|
||||
link: `${baseUrl}/comments`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,35 @@
|
||||
const got = require('@/utils/got');
|
||||
|
||||
const { baseUrl, apiHost, parseEventDetail, parseItem } = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const responses = await got.all(
|
||||
Array.from(
|
||||
{
|
||||
// first 2 pages
|
||||
length: (ctx.query.limit ? parseInt(ctx.query.limit, 10) : 16) / 8,
|
||||
},
|
||||
(_, v) => `${apiHost}/api/v1/events?page=${v + 1}`
|
||||
).map((url) => got.post(url))
|
||||
);
|
||||
|
||||
const list = responses
|
||||
.map((response) => response.data.data)
|
||||
.flat()
|
||||
.map((item) => parseItem(item));
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
item.description = await parseEventDetail(item);
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: '活动 - 智源社区',
|
||||
link: `${baseUrl}/events`,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,60 @@
|
||||
const got = require('@/utils/got');
|
||||
const cheerio = require('cheerio');
|
||||
|
||||
const { baseUrl, apiHost, parseEventDetail, parseItem } = require('./utils');
|
||||
|
||||
module.exports = async (ctx) => {
|
||||
const { tagId, sort = 'new', range } = ctx.params;
|
||||
|
||||
let title, description, brief, iconUrl;
|
||||
if (tagId) {
|
||||
const { data } = await got(`${apiHost}/api/v1/tags`, {
|
||||
searchParams: {
|
||||
id: tagId,
|
||||
},
|
||||
});
|
||||
title = data.data[0].title;
|
||||
description = data.data[0].description;
|
||||
brief = data.data[0].brief;
|
||||
iconUrl = data.data[0].icon_url;
|
||||
}
|
||||
|
||||
const responses = await got.all(
|
||||
Array.from(
|
||||
{
|
||||
// first 3 pages
|
||||
length: (ctx.query.limit ? parseInt(ctx.query.limit, 10) : 18) / 6,
|
||||
},
|
||||
(_, v) => `${apiHost}/api/v1/story/list?page=${v + 1}&sort=${sort}${tagId ? `&tag_id=${tagId}` : ''}${range ? `&time_range=${range}` : ''}`
|
||||
).map((url) => got.post(url))
|
||||
);
|
||||
|
||||
const list = responses
|
||||
.filter((response) => response.data.data)
|
||||
.map((response) => response.data.data)
|
||||
.flat()
|
||||
.map((item) => parseItem(item));
|
||||
|
||||
const items = await Promise.all(
|
||||
list.map((item) =>
|
||||
ctx.cache.tryGet(item.link, async () => {
|
||||
if (!item.eventId) {
|
||||
const { data: response } = await got(item.link);
|
||||
const $ = cheerio.load(response);
|
||||
item.description = item.is_event ? $('div.box2').html() : $('.post-content').html();
|
||||
} else {
|
||||
item.description = await parseEventDetail(item);
|
||||
}
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: `${title ? `${title} - ` : ''}${description ? `${description} - ` : ''}智源社区`,
|
||||
description: brief,
|
||||
link: `${baseUrl}/?${tagId ? `tag_id=${tagId}&` : ''}sort=${sort}${range ? `&time_range=${range}` : ''}`,
|
||||
image: iconUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
module.exports = {
|
||||
'/hub/comments': ['TonyRL'],
|
||||
'/hub/events': ['TonyRL'],
|
||||
'/hub/:tagId?/:sort?/:range?': ['TonyRL'],
|
||||
};
|
||||
@@ -0,0 +1,31 @@
|
||||
module.exports = {
|
||||
'baai.ac.cn': {
|
||||
_name: '北京智源人工智能研究院',
|
||||
hub: [
|
||||
{
|
||||
title: '智源社区',
|
||||
docs: 'https://docs.rsshub.app/programming.html#bei-jing-zhi-yuan-ren-gong-zhi-neng-yan-jiu-yuan',
|
||||
source: ['/'],
|
||||
target: (params, url) => {
|
||||
const searchParams = new URL(url).searchParams;
|
||||
const tagId = searchParams.get('tag_id');
|
||||
const sort = searchParams.get('sort');
|
||||
const range = searchParams.get('time_range');
|
||||
return `/baai/hub${tagId ? `/${tagId}` : ''}${sort ? `/${sort}` : ''}${range ? `/${range}` : ''}`;
|
||||
},
|
||||
},
|
||||
{
|
||||
title: '活动 - 智源社区',
|
||||
docs: 'https://docs.rsshub.app/programming.html#bei-jing-zhi-yuan-ren-gong-zhi-neng-yan-jiu-yuan',
|
||||
source: ['/events', '/'],
|
||||
target: '/baai/hub/events',
|
||||
},
|
||||
{
|
||||
title: '评论 - 智源社区',
|
||||
docs: 'https://docs.rsshub.app/programming.html#bei-jing-zhi-yuan-ren-gong-zhi-neng-yan-jiu-yuan',
|
||||
source: ['/comments', '/'],
|
||||
target: '/baai/hub/comments',
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,7 @@
|
||||
module.exports = (router) => {
|
||||
router.get('/hub/comments', require('./comments'));
|
||||
router.get('/hub/events', require('./events'));
|
||||
router.get('/hub/:tagId/:sort?/:range?', require('./hub'));
|
||||
router.get('/hub/:tagId/:sort?', require('./hub'));
|
||||
router.get('/hub/:sort?', require('./hub'));
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
const got = require('@/utils/got');
|
||||
const { parseDate } = require('@/utils/parse-date');
|
||||
const timezone = require('@/utils/timezone');
|
||||
|
||||
const baseUrl = 'https://hub.baai.ac.cn';
|
||||
const eventUrl = 'https://event.baai.ac.cn';
|
||||
const apiHost = 'https://hub-api.baai.ac.cn';
|
||||
|
||||
const parseItem = (item) => ({
|
||||
link: item.is_event ? `${eventUrl}/activities/${item.event_info.id}` : `${baseUrl}/view/${item.story_id}`,
|
||||
title: item.is_event ? item.event_info.name : item.story_info.title,
|
||||
pubDate: timezone(parseDate(item.is_event ? item.event_info.time_desc : item.story_info.created_at.replace('发布', '').replace('分享', '')), 8),
|
||||
author: item.is_event ? item.event_info.company : item.story_info.user_name,
|
||||
category: item.is_event ? null : item.story_info.tag_names.map((tag) => tag.title),
|
||||
eventId: item.is_event ? item.event_info.id : null,
|
||||
});
|
||||
|
||||
const parseEventDetail = async (item) => {
|
||||
const { data } = await got(`${eventUrl}/api/api/Activity/IntroductionTypes`, {
|
||||
searchParams: {
|
||||
activityId: item.eventId,
|
||||
},
|
||||
});
|
||||
return data.data.ac_desc + data.data.ac_desc_two;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
baseUrl,
|
||||
eventUrl,
|
||||
apiHost,
|
||||
parseItem,
|
||||
parseEventDetail,
|
||||
};
|
||||
Reference in New Issue
Block a user