Let saved library stills queue Edit without a format rejection.

Use catalog width/height or aspect fallback in resolveRequestSize, restore GIF/BMP upload messaging, and keep Photo to change still ids across reload so Klein/Qwen Edit can bind imageAId.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-10-12 12:45:50 -05:00
co-authored by Cursor
parent 1bab5152f6
commit 97c7547da9
4 changed files with 52 additions and 25 deletions
+35 -10
View File
@@ -1089,7 +1089,12 @@ function addNegative(){
}
negativeDraft.value=''
}
function stillById(id:string){return id?stills.value.find((s:any)=>s.id===id)||null:null}
function stillById(id:string){
if(!id)return null
return stills.value.find((s:any)=>s.id===id)
|| (library.value.stills||[]).find((s:any)=>s.id===id)
|| null
}
/** Photos array is source of truth — never resurrect cards from leftover imageAId. */
function syncPhotosBindings(){
const filled=(form.photos||[]).filter((p:any)=>p?.stillId)
@@ -1132,12 +1137,16 @@ 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
}else{
// Prefer a library row; if the picker passed a still object already in library.value, stillById works.
// Keep the id when the still is in library.stills (any folder match via merge) so Edit can bind imageAId.
const inLibrary=(library.value.stills||[]).some((s:any)=>s.id===stillId)
if(!inLibrary && !stillById(stillId)){
form.photos[index].stillId=''
}else{
form.photos[index].stillId=stillId
}
}
syncPhotosBindings()
saveBenchDraft(true)
}
@@ -1533,8 +1542,13 @@ function pickAsset(asset:any){
else if(key==='startClipId')chooseClip(asset?.id||'')
else if(key.startsWith('photo:')){
const index=Number(key.slice(6))
if(asset?.id)setPhotoStill(index,asset.id)
else discardEmptyPhotoDraft(index)
if(asset?.id){
// Ensure the chosen library still stays in library.stills so the card + imageAId bind
if(!(library.value.stills||[]).some((s:any)=>s.id===asset.id)){
library.value={...library.value,stills:[{...asset,role:asset.role||'input'},...(library.value.stills||[])]}
}
setPhotoStill(index,asset.id)
}else discardEmptyPhotoDraft(index)
}else if(key) form[key]=asset?.id||''
picker.value=''
pickerRevealAll.value=false
@@ -1913,12 +1927,21 @@ async function loadLibraryOnce(){
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([
const keepIds=[
...(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))
].filter(Boolean) as string[]
let kept=(library.value.stills||[]).filter((s:any)=>keepIds.includes(s.id)&&!pageStills.some((p:any)=>p.id===s.id))
const stillMissing=keepIds.filter(id=>!pageStills.some((s:any)=>s.id===id)&&!kept.some((s:any)=>s.id===id))
// Draft / upload stills must survive reload even when they fall outside the first page
if(stillMissing.length){
try{
const full=await $fetch<any>('/api/library?light=1')
const recovered=(full.stills||[]).filter((s:any)=>stillMissing.includes(s.id))
kept=[...kept,...recovered.filter((s:any)=>!kept.some((k:any)=>k.id===s.id))]
}catch{/* keep page + in-memory stills */}
}
library.value={
folders:page.folders||library.value.folders||[],
stills:[...pageStills,...kept],
@@ -1929,11 +1952,13 @@ async function loadLibraryOnce(){
loraTriggers:page.loraTriggers||library.value.loraTriggers||{},
keepPrompts:page.keepPrompts||library.value.keepPrompts
}
// Drop filled photo cards whose still left the library
const allStills=[...pageStills,...kept]
// Drop filled photo cards only when the still is truly gone from the catalog
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=''
if(id && !allStills.some((s:any)=>s.id===id)) form.photos[i].stillId=''
}
syncPhotosBindings()
}
async function fetchHealth(){
+1 -1
View File
@@ -19,7 +19,7 @@ export default defineEventHandler(async (event) => {
}
const size = imageDimensions(image.data)
if (!size) {
throw createError({ statusCode: 400, statusMessage: 'Use a PNG, JPEG, or WebP' })
throw createError({ statusCode: 400, statusMessage: 'Use a PNG, JPEG, WebP, GIF, or BMP image.' })
}
const { owner } = assertLibraryOwner(event)
const library = publicLibrary(event)
+1 -1
View File
@@ -7,7 +7,7 @@ export default defineEventHandler(async event => {
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'})
if (!size) throw createError({statusCode:400,statusMessage:'Use a PNG, JPEG, WebP, GIF, or BMP image.'})
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.'})
+8 -6
View File
@@ -32,18 +32,20 @@ export async function resolveRequestSize(owner: string, request: any) {
const id = request.imageAId || request.identityStillId
if (id) {
const still = getStill(owner, id)
// Catalog size wins — never re-probe a saved still as an upload format check.
if (Number(still.width) > 0 && Number(still.height) > 0) {
dimensions = { width: Number(still.width), height: Number(still.height) }
} else {
const path = stillPath(owner, id)
if (!existsSync(path)) {
throw createError({ statusCode: 404, statusMessage: 'That still is missing from the library' })
}
if (still.width && still.height) {
dimensions = { width: still.width, height: still.height }
} else {
// Header only — never read the full archive PNG into memory on Generate click
try {
dimensions = imageDimensions(readImageHeader(path))
} catch {
dimensions = null
}
if (!dimensions) {
throw createError({ statusCode: 400, statusMessage: 'Use a PNG, JPEG, or WebP' })
// Header probe failed — fall through to bench aspect via resolveSize.
}
}
}