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:
Towsty
2026-10-12 12:21:20 -05:00
co-authored by Cursor
parent 7dcac5444c
commit 1bab5152f6
7 changed files with 169 additions and 46 deletions
+16 -3
View File
@@ -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 }
})