mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-11-22 13:27:21 +08:00
Add REQUEST_MAX_RESPONSE_SIZE (default 16 MiB), applied to every fetch, ofetch and got response and to rss-parser's parseURL. A request can raise it with the maxResponseSize option. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import Parser from 'rss-parser';
|
|
|
|
import { config } from '@/config';
|
|
import type { DataItem, Language } from '@/types';
|
|
|
|
interface ParsedFeed {
|
|
author?: string;
|
|
copyright?: string;
|
|
creator?: string;
|
|
generator?: string;
|
|
language?: Language;
|
|
lastBuildDate?: string;
|
|
managingEditor?: string;
|
|
pubDate?: string;
|
|
publisher?: string;
|
|
webMaster?: string;
|
|
}
|
|
|
|
type ParsedItem = Pick<DataItem, 'author' | 'category' | 'description' | 'enclosure_type' | 'enclosure_url' | 'id'> & {
|
|
magnet?: string;
|
|
};
|
|
|
|
// A Parser reuses a single xml2js parser, whose state can outlive a malformed document and leak into the next one, so every document gets its own
|
|
const createParser = () =>
|
|
new Parser<ParsedFeed, ParsedItem>({
|
|
customFields: {
|
|
item: ['magnet'],
|
|
},
|
|
headers: {
|
|
'User-Agent': config.ua,
|
|
},
|
|
maxResponseSize: config.requestMaxResponseSize,
|
|
});
|
|
|
|
export default {
|
|
parseString: (xml: string) => createParser().parseString(xml),
|
|
parseURL: (feedUrl: string) => createParser().parseURL(feedUrl),
|
|
};
|