Split video/edit job state so the sidecar can edit concurrently, and hide v2 identity-ref thumbnails when the input still is hidden. Co-authored-by: Cursor <cursoragent@cursor.com>
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
function livePayload(job: ReturnType<typeof getJob> & {}) {
|
|
if (!job) return null
|
|
return {
|
|
jobId: job.id,
|
|
kind: job.kind || 'video',
|
|
hideThumbnail: job.hideThumbnail === true,
|
|
folderLocked: job.library?.folderLocked === true,
|
|
...jobSnapshot(job)
|
|
}
|
|
}
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const owner = libraryOwnerKey(event)
|
|
const live = listJobs()
|
|
.filter(job => job.library?.ownerKey === owner && (job.status === 'queued' || job.status === 'uploading' || job.status === 'running'))
|
|
.sort((a, b) => b.startedAt - a.startedAt)
|
|
const videoLive = live.find(job => job.kind !== 'edit')
|
|
const editLive = live.find(job => job.kind === 'edit')
|
|
|
|
let video = videoLive ? livePayload(videoLive) : null
|
|
const edit = editLive ? livePayload(editLive) : null
|
|
|
|
if (!video) {
|
|
const pending = listPendingJobs()
|
|
.filter(job => job.ownerKey === owner)
|
|
.sort((a, b) => b.startedAt - a.startedAt)[0]
|
|
if (pending) {
|
|
const resolved = await resolvePendingJob(pending).catch(() => null)
|
|
if (resolved) {
|
|
video = {
|
|
jobId: pending.jobId,
|
|
kind: 'video' as const,
|
|
hideThumbnail: pending.hideThumbnail === true,
|
|
folderLocked: pending.folderLocked === true,
|
|
...resolved
|
|
}
|
|
} else {
|
|
video = {
|
|
jobId: pending.jobId,
|
|
kind: 'video',
|
|
type: 'snapshot',
|
|
status: 'running',
|
|
message: 'Reconnecting to ComfyUI...',
|
|
progress: Math.max(8, Math.min(90, Math.round((Date.now() - pending.startedAt) / 1000))),
|
|
promptId: pending.promptId,
|
|
elapsedMs: Date.now() - pending.startedAt,
|
|
hideThumbnail: pending.hideThumbnail === true,
|
|
folderLocked: pending.folderLocked === true
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return {
|
|
jobId: video?.jobId || edit?.jobId || null,
|
|
video,
|
|
edit
|
|
}
|
|
})
|