Nest shot scripts under Queue jobs, keep the studio from overflowing on phones, and lighten library thumbs and polling so the UI stays responsive.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,12 +1,40 @@
|
||||
import { listShotQueues, summarizeQueue } from '~/server/utils/shotQueue'
|
||||
import { listStudioJobs, summarizeStudioJob } from '~/server/utils/studioQueue'
|
||||
|
||||
export default defineEventHandler((event) => {
|
||||
const { owner } = assertLibraryOwner(event)
|
||||
const jobs = listStudioJobs(owner)
|
||||
const full = String(getQuery(event).full || '') === '1'
|
||||
const active = listStudioJobs(owner)
|
||||
.filter(job => job.status === 'waiting' || job.status === 'running' || job.status === 'held')
|
||||
.map(summarizeStudioJob)
|
||||
const claimed = new Set(active.map(job => job.shotQueueId).filter(Boolean) as string[])
|
||||
const queues = listShotQueues(owner)
|
||||
const byId = new Map(queues.map(queue => [queue.id, queue]))
|
||||
const jobs = active.map((job) => {
|
||||
const shots = job.shotQueueId ? byId.get(job.shotQueueId) || null : null
|
||||
const shotSummary = shots ? summarizeQueue(shots) : null
|
||||
const plannedShots = shotSummary
|
||||
? undefined
|
||||
: [
|
||||
{ prompt: job.payload.prompt, duration: job.payload.duration },
|
||||
...(job.payload.extensions || [])
|
||||
]
|
||||
return {
|
||||
...summarizeStudioJob(job),
|
||||
...(full ? {
|
||||
shots: shotSummary,
|
||||
plannedShots: plannedShots && plannedShots.length > 1 ? plannedShots : undefined
|
||||
} : {}),
|
||||
completedCount: shotSummary?.completedCount || 0,
|
||||
pendingCount: shotSummary?.pendingCount ?? job.shotCount
|
||||
}
|
||||
})
|
||||
return {
|
||||
jobs,
|
||||
orphans: full
|
||||
? queues
|
||||
.filter(queue => !claimed.has(queue.id) && queue.status !== 'complete')
|
||||
.map(summarizeQueue)
|
||||
: [],
|
||||
waitingCount: jobs.filter(job => job.status === 'waiting').length
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user