From aea69c83d98343ca6aa94fd1d43bcadcc8d45953 Mon Sep 17 00:00:00 2001 From: Andvari <31068367+dzx-dzx@users.noreply.github.com> Date: Sat, 21 Sep 2024 16:04:48 +0800 Subject: [PATCH] feat(route/bjp): Support throttling option. (#16847) --- lib/routes/bjp/apod.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/routes/bjp/apod.ts b/lib/routes/bjp/apod.ts index b883fabc6..9f909c12a 100644 --- a/lib/routes/bjp/apod.ts +++ b/lib/routes/bjp/apod.ts @@ -29,7 +29,7 @@ export const route: Route = { url: 'bjp.org.cn/APOD/today.shtml', }; -async function handler() { +async function handler(ctx) { const baseUrl = 'https://www.bjp.org.cn'; const listUrl = `${baseUrl}/APOD/list.shtml`; @@ -46,7 +46,9 @@ async function handler() { link: `${baseUrl}${e.find('a').attr('href')}`, pubDate: timezone(parseDate(e.find('span').text().replace(':', ''), 'YYYY-MM-DD'), 8), }; - }); + }) + .sort((a, b) => b.pubDate - a.pubDate) + .slice(0, ctx.req.query('limit') ? Number.parseInt(ctx.req.query('limit'), 10) : 10); const items = await Promise.all( list.map((e) =>