Skip to content

Commit

Permalink
fix(route/apnews): Prevent fetching fulltext by default to alleviate …
Browse files Browse the repository at this point in the history
…403 error. (#16706)

* fix(route/apnews): Prevent fetching fulltext by default to alleviate 403 error.

* .

* .
  • Loading branch information
dzx-dzx committed Sep 14, 2024
1 parent cba88e1 commit 2783eed
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/routes/apnews/rss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/routes/apnews/sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`,
Expand Down
4 changes: 2 additions & 2 deletions lib/routes/apnews/topics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 2783eed

Please sign in to comment.