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
+18 -6
View File
@@ -336,19 +336,31 @@ async function unlock() {
}
async function ingest(file: File) {
if (/last[\s._-]*frame/i.test(file.name || '')) return
if (/last[\s._-]*frame/i.test(file.name || '')) {
emit('error', 'Rejected as video handoff: filename matches last-frame. Choose a regular source image.')
return
}
const body = new FormData()
body.append('image', file)
body.append('folderId', current.value?.id || activeFolderId.value)
body.append('hideInput', String(props.hideInputPreview === true))
try {
const result = await $fetch<{ still?: { id: string; filename: string; hideInput?: boolean } }>('/api/library/stills', { method: 'POST', body })
emit('updated', result)
if (props.stillOnly) {
if (result.still?.id) emit('pick', result.still)
const result = await $fetch<{ still?: { id: string; filename: string; hideInput?: boolean }; stills?: PickerStill[] }>('/api/library/stills', { method: 'POST', body })
if (!result.still?.id) {
emit('error', 'Could not save that image to the library.')
return
}
emit('select', file, props.hideInputPreview === true, result.still?.id)
// Keep the new still in the payload the parent merges into library.stills
const stills = Array.isArray(result.stills) ? result.stills : []
if (!stills.some(item => item.id === result.still!.id)) {
stills.unshift(result.still as PickerStill)
}
emit('updated', { ...result, still: result.still, stills })
if (props.stillOnly) {
emit('pick', result.still)
return
}
emit('select', file, props.hideInputPreview === true, result.still.id)
} catch (error: any) {
emit('error', error?.data?.statusMessage || 'Could not save image')
}
+67 -17
View File
@@ -1132,12 +1132,32 @@ function setPhotoStill(index:number,stillId:string){
if(!Number.isInteger(index)||!form.photos[index])return
if(!stillId){
form.photos.splice(index,1)
}else if(!stillById(stillId)){
// Never fill the card with an id that is not in library.stills
form.photos[index].stillId=''
}else{
form.photos[index].stillId=stillId
}
syncPhotosBindings()
saveBenchDraft(true)
}
function mergeUploadedStill(response:any,still:any){
const prev=library.value||{}
const fromServer=Array.isArray(response?.stills)?response.stills:[]
const others=fromServer.filter((s:any)=>s?.id&&s.id!==still.id)
const kept=(prev.stills||[]).filter((s:any)=>s?.id&&s.id!==still.id&&!others.some((x:any)=>x.id===s.id))
library.value={
...prev,
folders:response?.folders||prev.folders||[],
clips:response?.clips||prev.clips||[],
tracks:response?.tracks||prev.tracks||[],
drafts:response?.drafts||prev.drafts||[],
loraAliases:response?.loraAliases||prev.loraAliases||{},
loraTriggers:response?.loraTriggers||prev.loraTriggers||{},
keepPrompts:response?.keepPrompts||prev.keepPrompts,
stills:[{...still,role:still.role||'input'},...others,...kept]
}
}
function discardEmptyPhotoDraft(index:number){
if(!Number.isInteger(index)||!form.photos[index])return
if(!form.photos[index].stillId)form.photos.splice(index,1)
@@ -1524,21 +1544,33 @@ async function uploadPickerFile(event:Event){
const file=input.files?.[0]
if(!file)return
const key=picker.value
const photoIndex=key.startsWith('photo:')?Number(key.slice(6)):-1
uploading.value=true;uploadMessage.value='';error.value=''
const body=new FormData();body.append('image',file);body.append('folderId',form.folderId);body.append('hideInput',String(xaigen))
try{
const response=await $fetch<any>('/api/studio-2/stills',{method:'POST',body})
library.value=response
measured[response.still.id]={width:response.still.width,height:response.still.height}
if(key.startsWith('photo:')){
setPhotoStill(Number(key.slice(6)),response.still.id)
picker.value=''
pickerRevealAll.value=false
const still=response?.still
if(!still?.id) throw new Error('Could not save that image to the library.')
mergeUploadedStill(response,still)
measured[still.id]={width:still.width,height:still.height}
if(photoIndex>=0){
if(!stillById(still.id)){
discardEmptyPhotoDraft(photoIndex)
error.value='Could not keep that photo in the library.'
}else{
setPhotoStill(photoIndex,still.id)
picker.value=''
pickerRevealAll.value=false
uploadMessage.value=`Loaded ${still.name || file.name}.`
}
}else{
Object.assign(form,applyUploadedStill(form,response,'source'))
Object.assign(form,applyUploadedStill(form,{...response,still},'source'))
uploadMessage.value=`Loaded ${still.name || file.name}.`
}
uploadMessage.value=`Loaded ${response.still.name || file.name}.`
}catch(e:any){error.value=e.data?.statusMessage||e.message}
}catch(e:any){
if(photoIndex>=0) discardEmptyPhotoDraft(photoIndex)
error.value=e.data?.statusMessage||e.message||'Could not save image'
}
finally{uploading.value=false;input.value=''}
}
async function upload(event:Event,target:'source'|'hero'){
@@ -1547,22 +1579,28 @@ async function upload(event:Event,target:'source'|'hero'){
const body=new FormData();body.append('image',file);body.append('folderId',form.folderId);body.append('hideInput',String(xaigen))
try{
const response=await $fetch<any>('/api/studio-2/stills',{method:'POST',body})
library.value=response
measured[response.still.id]={width:response.still.width,height:response.still.height}
const still=response?.still
if(!still?.id) throw new Error('Could not save that image to the library.')
mergeUploadedStill(response,still)
measured[still.id]={width:still.width,height:still.height}
const plan=photosPlanState.value
if(plan.show && !plan.handoffReadonly){
if(!stillById(still.id)){
error.value='Could not keep that photo in the library.'
return
}
const role=target==='hero'
?(plan.roles.includes('person')?'person':plan.defaultRole)
:plan.defaultRole
if(form.photos.length>=plan.max)form.photos[form.photos.length-1]={stillId:response.still.id,role}
else form.photos.push({stillId:response.still.id,role:role||'change'})
if(form.photos.length>=plan.max)form.photos[form.photos.length-1]={stillId:still.id,role}
else form.photos.push({stillId:still.id,role:role||'change'})
syncPhotosBindings()
}else{
Object.assign(form,applyUploadedStill(form,response,target))
Object.assign(form,applyUploadedStill(form,{...response,still},target))
}
uploadMessage.value=`Loaded ${response.still.name || file.name}.`
uploadMessage.value=`Loaded ${still.name || file.name}.`
}
catch(e:any){error.value=e.data?.statusMessage||e.message}
catch(e:any){error.value=e.data?.statusMessage||e.message||'Could not save image'}
finally{uploading.value=false;input.value=''}
}
function loadRevealed(folderId:string){
@@ -1874,9 +1912,16 @@ async function loadLibraryOnce(){
const qs=new URLSearchParams({limit:'50'})
if(form.folderId) qs.set('folderId',form.folderId)
const page=await $fetch<any>(`/api/library?${qs.toString()}`)
const pageStills=page.stills||[]
const keepIds=new Set([
...(form.photos||[]).map((p:any)=>p?.stillId).filter(Boolean),
form.imageAId,form.imageBId,form.identityStillId,form.maskId,form.endStillId,
...(form.guides||[]).map((g:any)=>g?.stillId).filter(Boolean)
].filter(Boolean))
const kept=(library.value.stills||[]).filter((s:any)=>keepIds.has(s.id)&&!pageStills.some((p:any)=>p.id===s.id))
library.value={
folders:page.folders||library.value.folders||[],
stills:page.stills||[],
stills:[...pageStills,...kept],
clips:page.clips||[],
tracks:page.tracks||[],
drafts:page.drafts||library.value.drafts||[],
@@ -1884,6 +1929,11 @@ async function loadLibraryOnce(){
loraTriggers:page.loraTriggers||library.value.loraTriggers||{},
keepPrompts:page.keepPrompts||library.value.keepPrompts
}
// Drop filled photo cards whose still left the library
for(let i=(form.photos||[]).length-1;i>=0;i-=1){
const id=form.photos[i]?.stillId
if(id && !stillById(id)) form.photos[i].stillId=''
}
}
async function fetchHealth(){