mirror of
https://github.com/sim1222/misskey.git
synced 2025-08-04 07:26:29 +09:00
feat(server): add fetch-rss api to reduce dependency of external apis
This commit is contained in:
@ -312,6 +312,7 @@ import * as ep___users_searchByUsernameAndHost from './endpoints/users/search-by
|
||||
import * as ep___users_search from './endpoints/users/search.js';
|
||||
import * as ep___users_show from './endpoints/users/show.js';
|
||||
import * as ep___users_stats from './endpoints/users/stats.js';
|
||||
import * as ep___fetchRss from './endpoints/fetch-rss.js';
|
||||
|
||||
const eps = [
|
||||
['admin/meta', ep___admin_meta],
|
||||
@ -626,6 +627,7 @@ const eps = [
|
||||
['users/search', ep___users_search],
|
||||
['users/show', ep___users_show],
|
||||
['users/stats', ep___users_stats],
|
||||
['fetch-rss', ep___fetchRss],
|
||||
];
|
||||
|
||||
export interface IEndpointMeta {
|
||||
|
39
packages/backend/src/server/api/endpoints/fetch-rss.ts
Normal file
39
packages/backend/src/server/api/endpoints/fetch-rss.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import Parser from 'rss-parser';
|
||||
import { getResponse } from '@/misc/fetch.js';
|
||||
import config from '@/config/index.js';
|
||||
import define from '../define.js';
|
||||
|
||||
const rssParser = new Parser();
|
||||
|
||||
export const meta = {
|
||||
tags: ['meta'],
|
||||
|
||||
requireCredential: false,
|
||||
allowGet: true,
|
||||
cacheSec: 60 * 3,
|
||||
} as const;
|
||||
|
||||
export const paramDef = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
url: { type: 'string' },
|
||||
},
|
||||
required: ['url'],
|
||||
} as const;
|
||||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps) => {
|
||||
const res = await getResponse({
|
||||
url: ps.url,
|
||||
method: 'GET',
|
||||
headers: Object.assign({
|
||||
'User-Agent': config.userAgent,
|
||||
Accept: 'application/rss+xml, */*',
|
||||
}),
|
||||
timeout: 5000,
|
||||
});
|
||||
|
||||
const text = await res.text();
|
||||
|
||||
return rssParser.parseString(text);
|
||||
});
|
Reference in New Issue
Block a user