Add asset-pack Image v2 API for Family Board stickers.
POST /api/assets/generate wraps Flux/Krea generate with sticker/panel/icon presets; GET /api/assets/{id} returns status and PNG URLs using the existing poll path.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* 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<string, unknown>) => {
|
||||
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<string, unknown>)
|
||||
|
||||
const pending = readPendingJob(id)
|
||||
if (pending) {
|
||||
const done = await resolvePendingJob(pending).catch(() => null)
|
||||
if (done) return withUrls(done as Record<string, unknown>)
|
||||
const job = ensurePendingWatch(pending)
|
||||
return withUrls(jobSnapshot(job) as Record<string, unknown>)
|
||||
}
|
||||
|
||||
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<string, unknown>),
|
||||
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' })
|
||||
})
|
||||
Reference in New Issue
Block a user