From 774a4feb52d6eb010c1ae340340c8c637d608103 Mon Sep 17 00:00:00 2001 From: Ethan Shen <42264778+nczitzk@users.noreply.github.com> Date: Tue, 18 Apr 2023 04:37:09 +0800 Subject: [PATCH] feat(route): add Aqara Community (#12338) * feat(route): add Aqara Community * style: crlf to lf * docs: add keyword parameter * fix: merge conflict --------- --- docs/other.md | 4 ++++ lib/v2/aqara/community.js | 32 ++++++++++++++++++++++++++++++++ lib/v2/aqara/maintainer.js | 1 + lib/v2/aqara/radar.js | 8 ++++++++ lib/v2/aqara/router.js | 1 + 5 files changed, 46 insertions(+) create mode 100644 lib/v2/aqara/community.js diff --git a/docs/other.md b/docs/other.md index 9cdf7a12e..591cf226b 100644 --- a/docs/other.md +++ b/docs/other.md @@ -78,6 +78,10 @@ pageClass: routes ## Aqara +### Community + + + ### News diff --git a/lib/v2/aqara/community.js b/lib/v2/aqara/community.js new file mode 100644 index 000000000..3c20d6ad7 --- /dev/null +++ b/lib/v2/aqara/community.js @@ -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, + }; +}; diff --git a/lib/v2/aqara/maintainer.js b/lib/v2/aqara/maintainer.js index 169cca9bc..4dc84e45e 100644 --- a/lib/v2/aqara/maintainer.js +++ b/lib/v2/aqara/maintainer.js @@ -1,3 +1,4 @@ module.exports = { + '/community/:id?/:keyword?': ['nczitzk'], '/news': ['nczitzk'], }; diff --git a/lib/v2/aqara/radar.js b/lib/v2/aqara/radar.js index c588ece8e..63b1073c4 100644 --- a/lib/v2/aqara/radar.js +++ b/lib/v2/aqara/radar.js @@ -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')}`, + }, + ], }, }; diff --git a/lib/v2/aqara/router.js b/lib/v2/aqara/router.js index 69a5972f6..f5ce9fdab 100644 --- a/lib/v2/aqara/router.js +++ b/lib/v2/aqara/router.js @@ -1,3 +1,4 @@ module.exports = function (router) { + router.get('/community/:id?/:keyword?', require('./community')); router.get('/news', require('./news')); };