Merge pull request #797 from ajnart/rss-multiple-feeds

Rss multiple feeds
This commit is contained in:
Thomas Camlong
2023-04-11 01:07:49 +09:00
committed by GitHub
6 changed files with 164 additions and 163 deletions

View File

@@ -1,17 +1,13 @@
import Consola from 'consola';
import { getCookie } from 'cookies-next';
import { decode } from 'html-entities';
import { NextApiRequest, NextApiResponse } from 'next';
import Consola from 'consola';
import { getCookie } from 'cookies-next';
import { decode } from 'html-entities';
import Parser from 'rss-parser';
import { z } from 'zod';
import { getConfig } from '../../../../tools/config/getConfig';
import { IRssWidget } from '../../../../widgets/rss/RssWidgetTile';
import { Stopwatch } from '../../../../tools/shared/time/stopwatch.tool';
import { IRssWidget } from '../../../../widgets/rss/RssWidgetTile';
type CustomItem = {
'media:content': string;
@@ -28,6 +24,7 @@ const parser: Parser<any, CustomItem> = new Parser({
const getQuerySchema = z.object({
widgetId: z.string().uuid(),
feedUrl: z.string(),
});
export const Get = async (request: NextApiRequest, response: NextApiResponse) => {
@@ -44,7 +41,6 @@ export const Get = async (request: NextApiRequest, response: NextApiResponse) =>
const rssWidget = config.widgets.find(
(x) => x.type === 'rss' && x.id === parseResult.data.widgetId
) as IRssWidget | undefined;
if (
!rssWidget ||
!rssWidget.properties.rssFeedUrl ||
@@ -54,9 +50,9 @@ export const Get = async (request: NextApiRequest, response: NextApiResponse) =>
return;
}
Consola.info('Requesting RSS feed...');
Consola.info(`Requesting RSS feed at url ${parseResult.data.feedUrl}`);
const stopWatch = new Stopwatch();
const feed = await parser.parseURL(rssWidget.properties.rssFeedUrl);
const feed = await parser.parseURL(parseResult.data.feedUrl);
Consola.info(`Retrieved RSS feed after ${stopWatch.getEllapsedMilliseconds()} milliseconds`);
const orderedFeed = {