Files
aigen/server/api/queues/[id].patch.ts
T

25 lines
1.0 KiB
TypeScript

import { getShotQueue, patchShotQueueSegments, updateShotQueue, summarizeQueue } from '~/server/utils/shotQueue'
export default defineEventHandler(async (event) => {
const { owner } = assertLibraryOwner(event)
const id = String(getRouterParam(event, 'id') || '')
const body = await readBody<{
name?: string
autoRun?: boolean
segments?: Array<{ index: number; prompt?: string; duration?: number }>
}>().catch(() => ({}))
if (Array.isArray(body?.segments) && body.segments.length) {
await patchShotQueueSegments(owner, id, body.segments)
}
if (typeof body?.name === 'string' || typeof body?.autoRun === 'boolean') {
await updateShotQueue(owner, id, (queue) => {
if (typeof body.name === 'string') queue.name = body.name.trim().slice(0, 80) || queue.name
if (typeof body.autoRun === 'boolean' && queue.status !== 'running') queue.autoRun = body.autoRun
})
}
const queue = getShotQueue(owner, id)
if (!queue) throw createError({ statusCode: 404, statusMessage: 'Queue not found' })
return summarizeQueue(queue)
})