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>
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { imageDimensions } from '../../utils/resolution'
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const form = await readMultipartFormData(event)
|
||||
if (!form?.length) {
|
||||
@@ -15,6 +17,10 @@ export default defineEventHandler(async (event) => {
|
||||
if (!image) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'An image is required' })
|
||||
}
|
||||
const size = imageDimensions(image.data)
|
||||
if (!size) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Use a PNG, JPEG, or WebP' })
|
||||
}
|
||||
const { owner } = assertLibraryOwner(event)
|
||||
const library = publicLibrary(event)
|
||||
const folderId = library.folders.some(folder => folder.id === fields.folderId)
|
||||
@@ -29,10 +35,17 @@ export default defineEventHandler(async (event) => {
|
||||
folderId,
|
||||
filename: image.filename,
|
||||
data: image.data,
|
||||
width: Number(fields.width || 0),
|
||||
height: Number(fields.height || 0),
|
||||
width: size.width,
|
||||
height: size.height,
|
||||
hideInput: fields.hideInput === 'true',
|
||||
role: 'input'
|
||||
})
|
||||
return { still: still || undefined, ...publicLibrary(event) }
|
||||
if (!still?.id) {
|
||||
throw createError({ statusCode: 400, statusMessage: 'Could not save that image to the library.' })
|
||||
}
|
||||
const next = publicLibrary(event)
|
||||
const stills = next.stills.some(item => item.id === still.id)
|
||||
? next.stills
|
||||
: [{ ...still, role: 'input' as const }, ...next.stills]
|
||||
return { still, ...next, stills }
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user