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:
@@ -1089,7 +1089,12 @@ function addNegative(){
|
|||||||
}
|
}
|
||||||
negativeDraft.value=''
|
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. */
|
/** Photos array is source of truth — never resurrect cards from leftover imageAId. */
|
||||||
function syncPhotosBindings(){
|
function syncPhotosBindings(){
|
||||||
const filled=(form.photos||[]).filter((p:any)=>p?.stillId)
|
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(!Number.isInteger(index)||!form.photos[index])return
|
||||||
if(!stillId){
|
if(!stillId){
|
||||||
form.photos.splice(index,1)
|
form.photos.splice(index,1)
|
||||||
}else if(!stillById(stillId)){
|
}else{
|
||||||
// Never fill the card with an id that is not in library.stills
|
// 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=''
|
form.photos[index].stillId=''
|
||||||
}else{
|
}else{
|
||||||
form.photos[index].stillId=stillId
|
form.photos[index].stillId=stillId
|
||||||
}
|
}
|
||||||
|
}
|
||||||
syncPhotosBindings()
|
syncPhotosBindings()
|
||||||
saveBenchDraft(true)
|
saveBenchDraft(true)
|
||||||
}
|
}
|
||||||
@@ -1533,8 +1542,13 @@ function pickAsset(asset:any){
|
|||||||
else if(key==='startClipId')chooseClip(asset?.id||'')
|
else if(key==='startClipId')chooseClip(asset?.id||'')
|
||||||
else if(key.startsWith('photo:')){
|
else if(key.startsWith('photo:')){
|
||||||
const index=Number(key.slice(6))
|
const index=Number(key.slice(6))
|
||||||
if(asset?.id)setPhotoStill(index,asset.id)
|
if(asset?.id){
|
||||||
else discardEmptyPhotoDraft(index)
|
// 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||''
|
}else if(key) form[key]=asset?.id||''
|
||||||
picker.value=''
|
picker.value=''
|
||||||
pickerRevealAll.value=false
|
pickerRevealAll.value=false
|
||||||
@@ -1913,12 +1927,21 @@ async function loadLibraryOnce(){
|
|||||||
if(form.folderId) qs.set('folderId',form.folderId)
|
if(form.folderId) qs.set('folderId',form.folderId)
|
||||||
const page=await $fetch<any>(`/api/library?${qs.toString()}`)
|
const page=await $fetch<any>(`/api/library?${qs.toString()}`)
|
||||||
const pageStills=page.stills||[]
|
const pageStills=page.stills||[]
|
||||||
const keepIds=new Set([
|
const keepIds=[
|
||||||
...(form.photos||[]).map((p:any)=>p?.stillId).filter(Boolean),
|
...(form.photos||[]).map((p:any)=>p?.stillId).filter(Boolean),
|
||||||
form.imageAId,form.imageBId,form.identityStillId,form.maskId,form.endStillId,
|
form.imageAId,form.imageBId,form.identityStillId,form.maskId,form.endStillId,
|
||||||
...(form.guides||[]).map((g:any)=>g?.stillId).filter(Boolean)
|
...(form.guides||[]).map((g:any)=>g?.stillId).filter(Boolean)
|
||||||
].filter(Boolean))
|
].filter(Boolean) as string[]
|
||||||
const kept=(library.value.stills||[]).filter((s:any)=>keepIds.has(s.id)&&!pageStills.some((p:any)=>p.id===s.id))
|
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={
|
library.value={
|
||||||
folders:page.folders||library.value.folders||[],
|
folders:page.folders||library.value.folders||[],
|
||||||
stills:[...pageStills,...kept],
|
stills:[...pageStills,...kept],
|
||||||
@@ -1929,11 +1952,13 @@ async function loadLibraryOnce(){
|
|||||||
loraTriggers:page.loraTriggers||library.value.loraTriggers||{},
|
loraTriggers:page.loraTriggers||library.value.loraTriggers||{},
|
||||||
keepPrompts:page.keepPrompts||library.value.keepPrompts
|
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){
|
for(let i=(form.photos||[]).length-1;i>=0;i-=1){
|
||||||
const id=form.photos[i]?.stillId
|
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(){
|
async function fetchHealth(){
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export default defineEventHandler(async (event) => {
|
|||||||
}
|
}
|
||||||
const size = imageDimensions(image.data)
|
const size = imageDimensions(image.data)
|
||||||
if (!size) {
|
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 { owner } = assertLibraryOwner(event)
|
||||||
const library = publicLibrary(event)
|
const library = publicLibrary(event)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ export default defineEventHandler(async event => {
|
|||||||
const {owner}=assertLibraryOwner(event),folderId=field('folderId')
|
const {owner}=assertLibraryOwner(event),folderId=field('folderId')
|
||||||
assertFolderAccess(event,folderId)
|
assertFolderAccess(event,folderId)
|
||||||
const size=imageDimensions(image.data)
|
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 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'})
|
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.'})
|
if (!still?.id) throw createError({statusCode:400,statusMessage:'Could not save that image to the library.'})
|
||||||
|
|||||||
@@ -32,18 +32,20 @@ export async function resolveRequestSize(owner: string, request: any) {
|
|||||||
const id = request.imageAId || request.identityStillId
|
const id = request.imageAId || request.identityStillId
|
||||||
if (id) {
|
if (id) {
|
||||||
const still = getStill(owner, 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)
|
const path = stillPath(owner, id)
|
||||||
if (!existsSync(path)) {
|
if (!existsSync(path)) {
|
||||||
throw createError({ statusCode: 404, statusMessage: 'That still is missing from the library' })
|
throw createError({ statusCode: 404, statusMessage: 'That still is missing from the library' })
|
||||||
}
|
}
|
||||||
if (still.width && still.height) {
|
try {
|
||||||
dimensions = { width: still.width, height: still.height }
|
|
||||||
} else {
|
|
||||||
// Header only — never read the full archive PNG into memory on Generate click
|
|
||||||
dimensions = imageDimensions(readImageHeader(path))
|
dimensions = imageDimensions(readImageHeader(path))
|
||||||
|
} catch {
|
||||||
|
dimensions = null
|
||||||
}
|
}
|
||||||
if (!dimensions) {
|
// Header probe failed — fall through to bench aspect via resolveSize.
|
||||||
throw createError({ statusCode: 400, statusMessage: 'Use a PNG, JPEG, or WebP' })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user