fix(route/gnn): remove empty div, limit concurrency (#19912)

This commit is contained in:
Stephen Zhou 2025-08-27 18:49:52 +08:00 committed by GitHub
parent 8139a648e3
commit 54dae2a0e4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 3 deletions

View File

@ -4,6 +4,7 @@ import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
import timezone from '@/utils/timezone';
import pMap from 'p-map';
export const route: Route = {
path: '/gnn/:category?',
@ -94,6 +95,8 @@ async function handler(ctx) {
const list = $('div.BH-lbox.GN-lbox2')
.children()
.not('p,a,img,span')
// <div data-news-id="291265" id="291265"></div>
.not('[data-news-id]')
.slice(0, limit)
.toArray()
.map((item) => {
@ -116,8 +119,9 @@ async function handler(ctx) {
};
});
const items = await Promise.all(
list.map(async (item) => {
const items = await pMap(
list,
async (item) => {
item.description = await cache.tryGet(item.link, async () => {
const response = await got.get(item.link);
let component = '';
@ -163,7 +167,8 @@ async function handler(ctx) {
return component;
});
return item;
})
},
{ concurrency: 5 }
);
return {