18 lines
729 B
TypeScript
18 lines
729 B
TypeScript
import { startQueueBurst } from '~/server/utils/videoChain'
|
|
|
|
function parseCount(raw: unknown): number | 'all' {
|
|
if (raw === 'all' || raw === 'remaining') return 'all'
|
|
const n = typeof raw === 'number' ? raw : Number(raw)
|
|
if (!Number.isFinite(n)) return 1
|
|
return Math.max(1, Math.min(50, Math.floor(n)))
|
|
}
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const { owner } = assertLibraryOwner(event)
|
|
const id = String(getRouterParam(event, 'id') || '')
|
|
const body = await readBody<{ count?: number | 'all' | 'remaining' }>(event).catch(() => ({} as { count?: number | 'all' }))
|
|
const query = getQuery(event)
|
|
const count = parseCount(body?.count ?? query.count)
|
|
return startQueueBurst(owner, id, count)
|
|
})
|