forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): add Discourse official rss route (DIYgod#16681)
* add discourse official rss rule * fix issues with existing interfaces * optimize path parameters and add annotation ---------
- Loading branch information
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Route } from '@/types'; | ||
import { getConfig } from './utils'; | ||
import got from '@/utils/got'; | ||
import RSSParser from '@/utils/rss-parser'; | ||
|
||
export const route: Route = { | ||
path: '/:configId/official/:path{.+}', | ||
categories: ['bbs'], | ||
example: '/discourse/0/official/latest', | ||
parameters: { | ||
configId: 'Environment variable configuration id, see above', | ||
path: 'Discourse RSS path between `domain` and `.rss`. All supported Rss path can be found in [https://meta.discourse.org/t/finding-discourse-rss-feeds/264134](https://meta.discourse.org/t/finding-discourse-rss-feeds/264134). For example: the path of [https://meta.discourse.org/top/all.rss](https://meta.discourse.org/top/all.rss) is `top/all`.', | ||
}, | ||
features: { | ||
requireConfig: [ | ||
{ | ||
name: 'DISCOURSE_CONFIG_*', | ||
description: `Configure the Discourse environment variables referring to [https://docs.rsshub.app/deploy/config#discourse](https://docs.rsshub.app/deploy/config#discourse).`, | ||
}, | ||
], | ||
requirePuppeteer: false, | ||
antiCrawler: false, | ||
supportBT: false, | ||
supportPodcast: false, | ||
supportScihub: false, | ||
}, | ||
name: 'Official RSS', | ||
maintainers: ['Raikyou', 'dzx-dzx'], | ||
handler, | ||
}; | ||
|
||
async function handler(ctx) { | ||
const { link, key } = getConfig(ctx); | ||
const path = ctx.req.param('path'); | ||
|
||
const url = `${link}/${path}.rss`; | ||
|
||
const feed = await RSSParser.parseString( | ||
( | ||
await got(url, { | ||
headers: { | ||
'User-Api-Key': key, | ||
}, | ||
}) | ||
).data | ||
); | ||
|
||
feed.items = feed.items.map((e) => ({ | ||
description: e.content, | ||
author: e.creator, | ||
...e, | ||
})); | ||
|
||
return { item: feed.items, ...feed }; | ||
} |