From ac82a14d7483c9481c23d91cbfbf103584abe8d3 Mon Sep 17 00:00:00 2001 From: simon3000 Date: Thu, 7 Sep 2023 14:58:31 +0200 Subject: [PATCH] dispatch256 with index --- api/api.ts | 5 +++-- api/dispatcher.ts | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/api/api.ts b/api/api.ts index 78c738db..531d61b3 100644 --- a/api/api.ts +++ b/api/api.ts @@ -202,8 +202,9 @@ router.post('/dispatch', ctx => { ctx.body = { url: dispatch() } }) -router.post('/dispatch256', ctx => { - ctx.body = { urls: dispatch256() } +router.post('/dispatch256', koaBody(), ctx => { + const { i } = ctx.request.body + ctx.body = { urls: dispatch256(i) } }) router.post('/receipt', koaBody(), ctx => { diff --git a/api/dispatcher.ts b/api/dispatcher.ts index 4b15681c..f5b647a6 100644 --- a/api/dispatcher.ts +++ b/api/dispatcher.ts @@ -20,7 +20,7 @@ export const fetch = async (url: string) => { } export const dispatch = () => jobs[Math.floor(Math.random() * jobs.length)]?.url -export const dispatch256 = () => jobs.filter((_, i) => i < 256).map(job => job.url) +export const dispatch256 = (i = 0) => jobs.filter((_, i) => i >= i * 256).filter((_, i) => i < 256).map(job => job.url) export const receipt = (url: string, data: any) => { if (data.code === 0) {