Files
aigen/server/api/studio-2/stills.post.ts
T
TowstyandCursor 1bab5152f6 Fix image edit disk upload so stills persist before Generate.
Reject only real handoff frames, return 400 with reason, keep the new still in the client library, and surface missing-still errors from Generate instead of 500s.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-12 12:21:20 -05:00

20 lines
1.2 KiB
TypeScript

import { imageDimensions } from '../../utils/resolution'
export default defineEventHandler(async event => {
const parts=await readMultipartFormData(event)
const image=parts?.find(p=>p.name==='image' && p.filename && p.data?.length)
const field=(name:string)=>parts?.find(p=>p.name===name)?.data.toString('utf8') || ''
if (!image) throw createError({statusCode:400,statusMessage:'Choose an image to upload.'})
const {owner}=assertLibraryOwner(event),folderId=field('folderId')
assertFolderAccess(event,folderId)
const size=imageDimensions(image.data)
if (!size) throw createError({statusCode:400,statusMessage:'Use a PNG, JPEG, or WebP'})
const filename=image.filename!.split(/[\\/]/).at(-1)!
const still=await saveStill({ownerKey:owner,folderId,filename,name:filename.replace(/\.[^.]+$/,''),data:image.data,...size,hideInput:field('hideInput')==='true',role:'input'})
if (!still?.id) throw createError({statusCode:400,statusMessage:'Could not save that image to the library.'})
const library=publicLibrary(event,{light:true})
const stills=library.stills.some(item=>item.id===still.id)
? library.stills
: [{...still,role:'input' as const},...library.stills]
return {still,...library,stills}
})