fix(route/apnews): Add throttle to topics.

(#18106)

* fix(route/apnews): Add throttle to topics.

* Update topics.ts
This commit is contained in:
Andvari
2025-01-14 00:40:34 +08:00
committed by GitHub
parent 989331871e
commit 4208e87e24
+11 -12
View File
@@ -1,7 +1,7 @@
import { Route, ViewType } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import { fetchArticle, removeDuplicateByKey } from './utils';
import { asyncPoolAll, fetchArticle, removeDuplicateByKey } from './utils';
const HOME_PAGE = 'https://apnews.com';
export const route: Route = {
@@ -41,17 +41,16 @@ async function handler(ctx) {
const response = await got(url);
const $ = load(response.data);
const items = await Promise.all(
$(':is(.PagePromo-content, .PageListStandardE-leadPromo-info) bsp-custom-headline')
.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) => (ctx.req.query('fulltext') === 'true' ? fetchArticle(item) : item))
);
const list = $(':is(.PagePromo-content, .PageListStandardE-leadPromo-info) bsp-custom-headline')
.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');
const items = ctx.req.query('fulltext') === 'true' ? await asyncPoolAll(10, list, (item) => fetchArticle(item)) : list;
return {
title: $('title').text(),