Files
aigen/server/api/generate/[id].get.ts
T

18 lines
506 B
TypeScript

export default defineEventHandler(async (event) => {
const id = getRouterParam(event, 'id')
const live = id ? getJob(id) : undefined
if (live) return jobSnapshot(live)
if (id) {
const pending = readPendingJob(id)
if (pending) {
const done = await resolvePendingJob(pending).catch(() => null)
if (done) return done
const job = ensurePendingWatch(pending)
return jobSnapshot(job)
}
}
throw createError({ statusCode: 404, statusMessage: 'Job not found' })
})