From 6d9ab1fe9d6791f883b44ab330f845b54bbf4925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B7=AF=E8=BF=87=E5=90=9B?= <65474016+luguoj@users.noreply.github.com> Date: Tue, 7 Jan 2025 00:33:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20Fixed=20the=20issue=20of=20being=20block?= =?UTF-8?q?ed=20by=20the=20website=20due=20to=20excessive=E2=80=A6=20(#180?= =?UTF-8?q?49)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Fixed the issue of being blocked by the website due to excessive concurrent requests, which resulted in failure to retrieve information. * fix: Added the missing semicolons. * fix: use tiny-async-pool instead of resolving one by one. --- lib/routes/agefans/update.ts | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/lib/routes/agefans/update.ts b/lib/routes/agefans/update.ts index 94423cc52..9f303a899 100644 --- a/lib/routes/agefans/update.ts +++ b/lib/routes/agefans/update.ts @@ -3,6 +3,7 @@ import cache from '@/utils/cache'; import got from '@/utils/got'; import { load } from 'cheerio'; import { rootUrl } from './utils'; +import asyncPool from 'tiny-async-pool'; export const route: Route = { path: '/update', @@ -46,26 +47,27 @@ async function handler() { }; }); - const items = await Promise.all( - list.map((item) => - cache.tryGet(item.link, async () => { - const detailResponse = await got(item.link); - const content = load(detailResponse.data); + const items:any[] = []; + for await (const item of asyncPool(3, list, (item) => + cache.tryGet(item.link, async () => { + const detailResponse = await got(item.link); + const content = load(detailResponse.data); - content('img').each((_, ele) => { - if (ele.attribs['data-original']) { - ele.attribs.src = ele.attribs['data-original']; - delete ele.attribs['data-original']; - } - }); - content('.video_detail_collect').remove(); + content('img').each((_, ele) => { + if (ele.attribs['data-original']) { + ele.attribs.src = ele.attribs['data-original']; + delete ele.attribs['data-original']; + } + }); + content('.video_detail_collect').remove(); - item.description = content('.video_detail_left').html(); + item.description = content('.video_detail_left').html(); - return item; - }) - ) - ); + return item; + }) + )) { + items.push(item); + } return { title: $('title').text(),