Files
aigen/server/api/generate/recover.post.ts
T
TowstyandCursor a7a810a7b3 Let clips move between folders, save busy jobs, and fail dropped Comfy runs.
Held jobs restore the form after a 3-minute wait, hidden stills stay blurred in the picker, and reloading Comfy no longer leaves xaigen spinning.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-25 21:46:24 -05:00

45 lines
1.5 KiB
TypeScript

export default defineEventHandler(async (event) => {
const body = await readBody<{ jobId?: string }>(event).catch(() => ({} as { jobId?: string }))
const jobId = String(body?.jobId || '')
const live = jobId ? getJob(jobId) : undefined
if (live) return jobSnapshot(live)
if (jobId) {
const pending = readPendingJob(jobId)
if (pending) {
const done = await resolvePendingJob(pending)
if (done) return done
return {
type: 'snapshot',
status: 'running',
jobId,
message: 'Reconnecting to ComfyUI...',
progress: 90,
promptId: pending.promptId,
elapsedMs: Date.now() - pending.startedAt,
hideThumbnail: pending.hideThumbnail,
folderLocked: pending.folderLocked
}
}
throw createError({ statusCode: 404, statusMessage: 'Job not found' })
}
const { owner } = assertLibraryOwner(event)
const library = publicLibrary(event)
const folderId = library.folders.find(folder => folder.unlocked)?.id
const imported = folderId ? await importMissingComfyVideos(owner, folderId) : []
const newest = imported[imported.length - 1]
if (!newest) {
throw createError({ statusCode: 404, statusMessage: 'No finished ComfyUI video to recover' })
}
return {
type: 'complete',
status: 'complete',
message: 'Recovered video from ComfyUI',
progress: 100,
clipId: newest.id,
filename: newest.comfyFilename,
hideThumbnail: newest.hideThumbnail
}
})