Skip to content

Commit

Permalink
dispatch256
Browse files Browse the repository at this point in the history
  • Loading branch information
simon300000 committed Sep 7, 2023
1 parent a03e3df commit c0838f4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { albums, AvailableLocales, availableLocales } from './albumParser.js'
import { search as searchF } from './common.js'

import { joinJob } from './spider.js'
import { dispatch, receipt } from './dispatcher.js'
import { dispatch, dispatch256, receipt } from './dispatcher.js'

const __dirname = dirname(fileURLToPath(import.meta.url))

Expand Down Expand Up @@ -202,6 +202,10 @@ router.post('/dispatch', ctx => {
ctx.body = { url: dispatch() }
})

router.post('/dispatch256', ctx => {
ctx.body = { urls: dispatch256() }
})

router.post('/receipt', koaBody(), ctx => {
const { url, data } = ctx.request.body
ctx.body = { result: receipt(url, JSON.parse(data)) }
Expand Down
1 change: 1 addition & 0 deletions api/dispatcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +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 receipt = (url: string, data: any) => {
if (data.code === 0) {
Expand Down

0 comments on commit c0838f4

Please sign in to comment.