From 3df0c95b93abb14314d13d7d747d79634b4f6d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=95=AC=E8=81=AA?= Date: Fri, 27 Sep 2024 14:05:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9eslint?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/routes/53ai/news.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/routes/53ai/news.ts b/lib/routes/53ai/news.ts index de7394c1ea0ad6..c9ccc2f01ab089 100644 --- a/lib/routes/53ai/news.ts +++ b/lib/routes/53ai/news.ts @@ -38,15 +38,12 @@ export const route: Route = { }; }); }; + const fetchAllPages = async (page: number, accumulatedItems: NewsItem[] = []): Promise => { + const pageItems: NewsItem[] = await fetchPage(page); + const newItems: NewsItem[] = [...accumulatedItems, ...pageItems]; + const lastItem: NewsItem | undefined = pageItems.at(-1); - const fetchAllPages = async (page: number, accumulatedItems: any[] = []): Promise => { - const pageItems = await fetchPage(page); - const newItems = [...accumulatedItems, ...pageItems]; - const lastItem = pageItems.at(-1); - - return pageItems.length === 0 || (lastItem && lastItem.pubDate < threeDaysAgo) - ? newItems - : fetchAllPages(page + 1, newItems); + return pageItems.length === 0 || (lastItem && lastItem.pubDate < threeDaysAgo) ? newItems : fetchAllPages(page + 1, newItems); }; const items = await fetchAllPages(1); @@ -61,3 +58,9 @@ export const route: Route = { }; }, }; + +interface NewsItem { + pubDate: Date; + title?: string; + content?: string; +}