import { getShotQueue, patchShotQueueSegments, updateShotQueue, summarizeQueue } from '~/server/utils/shotQueue' import { listStudioLoras } from '~/server/utils/loras' 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; loraName?: string; loraStack?: unknown }> }>().catch(() => ({})) if (Array.isArray(body?.segments) && body.segments.length) { await listStudioLoras() 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) })