diff --git a/components/studio2/Bench.vue b/components/studio2/Bench.vue index f1044e3..d107ca6 100644 --- a/components/studio2/Bench.vue +++ b/components/studio2/Bench.vue @@ -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,11 +1137,15 @@ 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 + // 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(`/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('/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(){ diff --git a/server/api/library/stills.post.ts b/server/api/library/stills.post.ts index 2b4fdbc..b0c7c57 100644 --- a/server/api/library/stills.post.ts +++ b/server/api/library/stills.post.ts @@ -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) diff --git a/server/api/studio-2/stills.post.ts b/server/api/studio-2/stills.post.ts index 12317df..124e2d6 100644 --- a/server/api/studio-2/stills.post.ts +++ b/server/api/studio-2/stills.post.ts @@ -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.'}) diff --git a/server/utils/studio2/size.ts b/server/utils/studio2/size.ts index 739527d..21b0445 100644 --- a/server/utils/studio2/size.ts +++ b/server/utils/studio2/size.ts @@ -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) - 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 } + // 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 { - // Header only — never read the full archive PNG into memory on Generate click - dimensions = imageDimensions(readImageHeader(path)) - } - if (!dimensions) { - throw createError({ statusCode: 400, statusMessage: 'Use a PNG, JPEG, or WebP' }) + const path = stillPath(owner, id) + if (!existsSync(path)) { + throw createError({ statusCode: 404, statusMessage: 'That still is missing from the library' }) + } + try { + dimensions = imageDimensions(readImageHeader(path)) + } catch { + dimensions = null + } + // Header probe failed — fall through to bench aspect via resolveSize. } } }