mirror of
https://github.com/DIYgod/RSSHub.git
synced 2025-12-11 15:47:48 +08:00
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
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/posts',
|
|
categories: ['bbs'],
|
|
example: '/discourse/0/posts',
|
|
parameters: { configId: 'Environment variable configuration id, see above' },
|
|
features: {
|
|
requireConfig: ['DISCOURSE_CONFIG_*'],
|
|
requirePuppeteer: false,
|
|
antiCrawler: false,
|
|
supportBT: false,
|
|
supportPodcast: false,
|
|
supportScihub: false,
|
|
},
|
|
name: 'Latest posts',
|
|
maintainers: ['dzx-dzx'],
|
|
handler,
|
|
};
|
|
|
|
async function handler(ctx) {
|
|
const { link, key } = getConfig(ctx);
|
|
|
|
const feed = await RSSParser.parseString(
|
|
(
|
|
await got(`${link}/posts.rss`, {
|
|
headers: {
|
|
'User-Api-Key': key,
|
|
},
|
|
})
|
|
).data
|
|
);
|
|
|
|
feed.items = feed.items.map((e) => ({
|
|
description: e.content,
|
|
author: e.creator,
|
|
...e,
|
|
}));
|
|
|
|
return { item: feed.items, ...feed };
|
|
}
|