/** * Asset-pack status. Same job ids as Image v2. * Poll: GET /api/assets/{id} (or GET /api/generate/{id}). * On complete, includes downloadable still URL(s) under /api/library/stills/{stillId}. */ export default defineEventHandler(async (event) => { const id = String(getRouterParam(event, 'id') || '').trim() if (!id) throw createError({ statusCode: 400, statusMessage: 'Missing job id' }) const withUrls = (snap: Record) => { const stillId = typeof snap.stillId === 'string' ? snap.stillId : '' const url = stillId ? `/api/library/stills/${stillId}` : null return { ...snap, url, urls: url ? [url] : [], pngUrl: url, thumbUrl: url ? `${url}?thumb=1` : null, complete: snap.status === 'complete' } } const live = getJob(id) if (live) return withUrls(jobSnapshot(live) as Record) const pending = readPendingJob(id) if (pending) { const done = await resolvePendingJob(pending).catch(() => null) if (done) return withUrls(done as Record) const job = ensurePendingWatch(pending) return withUrls(jobSnapshot(job) as Record) } try { const owner = libraryOwnerKey(event) const studio = listStudioJobs(owner).find(item => item.id === id || item.liveJobId === id) if (studio) { const liveId = studio.liveJobId || '' const liveJob = liveId ? getJob(liveId) : undefined if (liveJob) { return { ...withUrls(jobSnapshot(liveJob) as Record), studioJobId: studio.id } } return { jobId: studio.id, studioJobId: studio.id, status: studio.status || 'queued', message: studio.error || 'Waiting in the studio queue', progress: 0, url: null, urls: [], pngUrl: null, thumbUrl: null, complete: studio.status === 'complete', error: studio.error || undefined } } } catch { // fall through } throw createError({ statusCode: 404, statusMessage: 'Job not found' }) })