feat(route): add Aqara Community (#12338)

* feat(route): add Aqara Community

* style: crlf to lf

* docs: add keyword parameter

* fix: merge conflict

---------
This commit is contained in:
Ethan Shen 2023-04-18 04:37:09 +08:00 committed by GitHub
parent b921c04bfb
commit 774a4feb52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 46 additions and 0 deletions

View File

@ -78,6 +78,10 @@ pageClass: routes
## Aqara
### Community
<Route author="nczitzk" example="/aqara/community" path="/aqara/community/:id?/:keyword?" :paramsDesc="['分类 id可在对应分类页 URL 中找到,默认为全部', '关键字,默认为空']"/>
### News
<Route author="nczitzk" example="/aqara/news" path="/aqara/news"/>

32
lib/v2/aqara/community.js Normal file
View File

@ -0,0 +1,32 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
module.exports = async (ctx) => {
const id = ctx.params.id ?? '';
const keyword = ctx.params.keyword ?? '';
const limit = ctx.query.limit ? parseInt(ctx.query.limit) : 100;
const rootUrl = 'https://community.aqara.com';
const apiUrl = `${rootUrl}/api/v2/feeds?limit=${limit}&platedetail_id=${id}&keyword=${keyword}&all=1`;
const currentUrl = `${rootUrl}/pc/#/post${id ? `?id=${id}` : ''}`;
const response = await got({
method: 'get',
url: apiUrl,
});
const items = response.data.map((item) => ({
title: item.feed_title,
link: `${rootUrl}/pc/#/post/postDetail/${item.id}`,
description: item.feed_content,
pubDate: parseDate(item.created_at),
author: item.user.nickname,
}));
ctx.state.data = {
title: 'Aqara社区',
link: currentUrl,
item: items,
allowEmpty: true,
};
};

View File

@ -1,3 +1,4 @@
module.exports = {
'/community/:id?/:keyword?': ['nczitzk'],
'/news': ['nczitzk'],
};

View File

@ -9,5 +9,13 @@ module.exports = {
target: '/aqara/news',
},
],
community: [
{
title: 'Community',
docs: 'https://docs.rsshub.app/other.html#aqara-community',
source: ['/pc', '/'],
target: (params, url) => `/aqara/community/${new URL(url).searchParams.get('id')}`,
},
],
},
};

View File

@ -1,3 +1,4 @@
module.exports = function (router) {
router.get('/community/:id?/:keyword?', require('./community'));
router.get('/news', require('./news'));
};