From 2783eed12c900ec2eea39cbf16cdbc03b6df6a2b Mon Sep 17 00:00:00 2001 From: Andvari <31068367+dzx-dzx@users.noreply.github.com> Date: Sun, 15 Sep 2024 01:31:02 +0800 Subject: [PATCH] fix(route/apnews): Prevent fetching fulltext by default to alleviate 403 error. (#16706) * fix(route/apnews): Prevent fetching fulltext by default to alleviate 403 error. * . * . --- lib/routes/apnews/rss.ts | 2 +- lib/routes/apnews/sitemap.ts | 2 +- lib/routes/apnews/topics.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/routes/apnews/rss.ts b/lib/routes/apnews/rss.ts index a6a6270d911cc..a34dc17b0aeef 100644 --- a/lib/routes/apnews/rss.ts +++ b/lib/routes/apnews/rss.ts @@ -38,7 +38,7 @@ async function handler(ctx) { const url = `${HOME_PAGE}/${rss}.rss`; const res = await parser.parseURL(url); - const items = await Promise.all(res.items.map((item) => fetchArticle(item))); + const items = ctx.req.query('mode') === 'fulltext' ? await Promise.all(res.items.map((item) => fetchArticle(item))) : res; return { ...res, diff --git a/lib/routes/apnews/sitemap.ts b/lib/routes/apnews/sitemap.ts index 07d89f9fda28b..495fa4f2f2b94 100644 --- a/lib/routes/apnews/sitemap.ts +++ b/lib/routes/apnews/sitemap.ts @@ -82,7 +82,7 @@ async function handler(ctx) { .sort((a, b) => (a.pubDate && b.pubDate ? b.pubDate - a.pubDate : b.lastmod - a.lastmod)) .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 20); - const items = await asyncPoolAll(20, list, (item) => fetchArticle(item)); + const items = ctx.req.query('mode') === 'fulltext' ? await asyncPoolAll(20, list, (item) => fetchArticle(item)) : list; return { title: `AP News sitemap:${route}`, diff --git a/lib/routes/apnews/topics.ts b/lib/routes/apnews/topics.ts index ddb8b9deeeb08..5c693c7124019 100644 --- a/lib/routes/apnews/topics.ts +++ b/lib/routes/apnews/topics.ts @@ -42,14 +42,14 @@ async function handler(ctx) { const items = await Promise.all( $(':is(.PagePromo-content, .PageListStandardE-leadPromo-info) bsp-custom-headline') - .get() + .toArray() .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit')) : Infinity) .map((e) => ({ title: $(e).find('span.PagePromoContentIcons-text').text(), link: $(e).find('a').attr('href'), })) .filter((e) => typeof e.link === 'string') - .map((item) => fetchArticle(item)) + .map((item) => (ctx.req.query('mode') === 'fulltext' ? fetchArticle(item) : item)) ); return {