Saving the MP4 used to freeze Node, which made xAIGen unreachable and left the player empty even though the library already had the video. Co-authored-by: Cursor <cursoragent@cursor.com>
57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
const RECENT_CLIP_MS = 3 * 60 * 60 * 1000
|
|
|
|
function recentLibraryClip(event: Parameters<typeof assertLibraryOwner>[0]) {
|
|
const { catalog } = assertLibraryOwner(event)
|
|
const newest = catalog.clips[0]
|
|
if (!newest || Date.now() - newest.createdAt > RECENT_CLIP_MS) return null
|
|
return {
|
|
type: 'complete' as const,
|
|
status: 'complete' as const,
|
|
message: newest.hideThumbnail ? 'Video ready. Click the player to reveal it.' : 'Video ready',
|
|
progress: 100,
|
|
clipId: newest.id,
|
|
filename: newest.comfyFilename,
|
|
hideThumbnail: newest.hideThumbnail,
|
|
folderLocked: false
|
|
}
|
|
}
|
|
|
|
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 jobSnapshot(ensurePendingWatch(pending))
|
|
}
|
|
const saved = recentLibraryClip(event)
|
|
if (saved) return saved
|
|
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) {
|
|
return {
|
|
type: 'complete',
|
|
status: 'complete',
|
|
message: 'Recovered video from ComfyUI',
|
|
progress: 100,
|
|
clipId: newest.id,
|
|
filename: newest.comfyFilename,
|
|
hideThumbnail: newest.hideThumbnail
|
|
}
|
|
}
|
|
const saved = recentLibraryClip(event)
|
|
if (saved) return saved
|
|
throw createError({ statusCode: 404, statusMessage: 'No finished ComfyUI video to recover' })
|
|
})
|