mirror of
https://github.com/DIYgod/RSSHub.git
synced 2026-10-16 07:44:44 +08:00
fix(route/apnews): Add throttle to topics.
(#18106) * fix(route/apnews): Add throttle to topics. * Update topics.ts
This commit is contained in:
+11
-12
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user