Keep library deletes when a still file is locked, and match LoRAs by engine folder.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -362,6 +362,8 @@
|
||||
:folder-id="form.folderId"
|
||||
:preview-hidden="!eyeOpen"
|
||||
:is-hidden="isHidden"
|
||||
:refresh-key="libraryRefreshKey"
|
||||
:hidden-ids="[...forgottenStillIds]"
|
||||
@close="libraryOpen=false"
|
||||
@select="selectOutput"
|
||||
@use-image="onLibraryUseImage"
|
||||
@@ -962,8 +964,14 @@ const gpuChipLabel=computed(()=>{
|
||||
return gpu.value.label || 'GPU ?'
|
||||
})
|
||||
const sourceSlot=computed(()=>{const clip=clips.value.find((a:any)=>a.id===form.startClipId);return form.mode==='extend'?(clip?{...clip,kind:'clip'}:null):inputStill.value})
|
||||
const pickerAssets=computed(()=>picker.value==='startClipId'?clips.value.map((a:any)=>({...a,kind:'clip'})):stills.value.map((a:any)=>({...a,kind:'still'})))
|
||||
const inputStill=computed(()=>stills.value.find((s:any)=>s.id===form.imageAId))
|
||||
const forgottenStillIds=ref(new Set<string>())
|
||||
const libraryRefreshKey=ref(0)
|
||||
const pickerAssets=computed(()=>{
|
||||
const forget=forgottenStillIds.value
|
||||
if(picker.value==='startClipId')return clips.value.filter((a:any)=>!forget.has(a.id)).map((a:any)=>({...a,kind:'clip'}))
|
||||
return stills.value.filter((a:any)=>!forget.has(a.id)).map((a:any)=>({...a,kind:'still'}))
|
||||
})
|
||||
const inputStill=computed(()=>stills.value.find((s:any)=>s.id===form.imageAId&&!forgottenStillIds.value.has(s.id)))
|
||||
const family=computed(()=>folderAssets(library.value,jobs.value,form.folderId))
|
||||
const familyStillCount=computed(()=>{
|
||||
const folder=(library.value.folders||[]).find((f:any)=>f.id===form.folderId)
|
||||
@@ -1094,11 +1102,29 @@ function addNegative(){
|
||||
negativeDraft.value=''
|
||||
}
|
||||
function stillById(id:string){
|
||||
if(!id)return null
|
||||
if(!id||forgottenStillIds.value.has(id))return null
|
||||
return stills.value.find((s:any)=>s.id===id)
|
||||
|| (library.value.stills||[]).find((s:any)=>s.id===id)
|
||||
|| null
|
||||
}
|
||||
function clearFormSlots(ids:string[]){
|
||||
const gone=new Set(ids.filter(Boolean))
|
||||
if(!gone.size)return
|
||||
const touched=gone.has(form.imageAId)||gone.has(form.imageBId)||gone.has(form.identityStillId)||(form.photos||[]).some((p:any)=>gone.has(p?.stillId))
|
||||
if(gone.has(form.imageAId))form.imageAId=''
|
||||
if(gone.has(form.imageBId))form.imageBId=''
|
||||
if(gone.has(form.identityStillId))form.identityStillId=''
|
||||
if(gone.has(form.maskId))form.maskId=''
|
||||
if(gone.has(form.endStillId))form.endStillId=''
|
||||
if(gone.has(form.startClipId))form.startClipId=''
|
||||
form.photos=(form.photos||[]).filter((p:any)=>!gone.has(p?.stillId))
|
||||
form.guides=(form.guides||[]).map((g:any)=>gone.has(g?.stillId)?{...g,stillId:''}:g)
|
||||
if(touched)syncPhotosBindings()
|
||||
if(selected.value&&gone.has(selected.value.id)){
|
||||
selected.value=null
|
||||
selectionPinned.value=false
|
||||
}
|
||||
}
|
||||
/** Photos array is source of truth — never resurrect cards from leftover imageAId. */
|
||||
function syncPhotosBindings(){
|
||||
const filled=(form.photos||[]).filter((p:any)=>p?.stillId)
|
||||
@@ -1445,23 +1471,34 @@ function slotHidden(_id:string){
|
||||
function toggleReveal(_id?:string){
|
||||
eyeOpen.value=!eyeOpen.value
|
||||
}
|
||||
async function deleteOutput(){
|
||||
if(!selected.value)return
|
||||
const label=assetLabel(selected.value)
|
||||
async function deleteOutput(explicit?:any){
|
||||
const target=explicit||selected.value
|
||||
if(!target?.id)return
|
||||
const label=assetLabel(target)
|
||||
if(import.meta.client && !window.confirm(`Delete ${label}?`))return
|
||||
const id=String(target.id)
|
||||
const kind=target.kind==='clip'?'clips/':target.kind==='track'?'tracks/':'stills/'
|
||||
try{
|
||||
const kind=selected.value.kind==='clip'?'clips/':selected.value.kind==='track'?'tracks/':'stills/'
|
||||
const id=selected.value.id
|
||||
await $fetch('/api/library/'+kind+id,{method:'DELETE'})
|
||||
library.value={
|
||||
...library.value,
|
||||
stills:(library.value.stills||[]).filter((s:any)=>s.id!==id),
|
||||
clips:(library.value.clips||[]).filter((c:any)=>c.id!==id),
|
||||
tracks:(library.value.tracks||[]).filter((t:any)=>t.id!==id)
|
||||
}catch(e:any){
|
||||
const status=Number(e?.statusCode||e?.status||e?.response?.status||0)
|
||||
if(status!==404){
|
||||
error.value=e?.data?.statusMessage||e?.message
|
||||
return
|
||||
}
|
||||
selected.value=null
|
||||
await refreshJobs()
|
||||
}catch(e:any){error.value=e.data?.statusMessage||e.message}
|
||||
}
|
||||
forgottenStillIds.value=new Set([...forgottenStillIds.value,id])
|
||||
clearFormSlots([id])
|
||||
library.value={
|
||||
...library.value,
|
||||
stills:(library.value.stills||[]).filter((s:any)=>s.id!==id),
|
||||
clips:(library.value.clips||[]).filter((c:any)=>c.id!==id),
|
||||
tracks:(library.value.tracks||[]).filter((t:any)=>t.id!==id)
|
||||
}
|
||||
if(selected.value?.id===id)selected.value=null
|
||||
libraryRefreshKey.value+=1
|
||||
try{await loadLibraryOnce()}catch{/* catalog write already landed */}
|
||||
await refreshJobs()
|
||||
}
|
||||
function stepFamily(delta:number){
|
||||
const list=family.value
|
||||
@@ -1500,8 +1537,7 @@ function onLibraryLoadInputRaw(item:any){
|
||||
loadInputRaw(item)
|
||||
}
|
||||
function onLibraryDelete(item:any){
|
||||
if(item)selectOutput(item)
|
||||
void deleteOutput()
|
||||
void deleteOutput(item)
|
||||
}
|
||||
function onStageHotkey(e:KeyboardEvent){
|
||||
if(e.metaKey||e.ctrlKey||e.altKey)return
|
||||
@@ -1929,28 +1965,30 @@ async function loadLibraryOnce(){
|
||||
// Current folder page only — never the yearly Inbox JSON on /
|
||||
const qs=new URLSearchParams({limit:'50'})
|
||||
if(form.folderId) qs.set('folderId',form.folderId)
|
||||
qs.set('_',String(Date.now()))
|
||||
const page=await $fetch<any>(`/api/library?${qs.toString()}`)
|
||||
const pageStills=page.stills||[]
|
||||
const forget=forgottenStillIds.value
|
||||
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) 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))
|
||||
].filter((id:string)=>id&&!forget.has(id)) as string[]
|
||||
let kept=(library.value.stills||[]).filter((s:any)=>keepIds.includes(s.id)&&!pageStills.some((p:any)=>p.id===s.id)&&!forget.has(s.id))
|
||||
const stillMissing=keepIds.filter(id=>!forget.has(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))
|
||||
const full=await $fetch<any>(`/api/library?light=1&_=${Date.now()}`)
|
||||
const recovered=(full.stills||[]).filter((s:any)=>stillMissing.includes(s.id)&&!forget.has(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],
|
||||
clips:page.clips||[],
|
||||
tracks:page.tracks||[],
|
||||
stills:[...pageStills,...kept].filter((s:any)=>!forget.has(s.id)),
|
||||
clips:(page.clips||[]).filter((c:any)=>!forget.has(c.id)),
|
||||
tracks:(page.tracks||[]).filter((t:any)=>!forget.has(t.id)),
|
||||
drafts:page.drafts||library.value.drafts||[],
|
||||
loraAliases:page.loraAliases||library.value.loraAliases||{},
|
||||
loraTriggers:page.loraTriggers||library.value.loraTriggers||{},
|
||||
@@ -2061,6 +2099,8 @@ const mobileCtx=computed(()=>({
|
||||
focusedJobId:focusedJobId.value,
|
||||
canClearFinished:canClearFinished.value,
|
||||
selected:selected.value,
|
||||
forgottenStillIds:[...forgottenStillIds.value],
|
||||
libraryRefreshKey:libraryRefreshKey.value,
|
||||
family:family.value,
|
||||
familyStillCount:familyStillCount.value,
|
||||
libraryOpen:libraryOpen.value,
|
||||
|
||||
@@ -163,6 +163,8 @@ const props = defineProps<{
|
||||
folderId?: string
|
||||
previewHidden?: boolean
|
||||
isHidden?: (asset: any) => boolean
|
||||
refreshKey?: number
|
||||
hiddenIds?: string[]
|
||||
}>()
|
||||
|
||||
const emit = defineEmits<{
|
||||
@@ -286,26 +288,18 @@ function useAndClose() {
|
||||
close()
|
||||
}
|
||||
|
||||
function removeLocalAsset(asset: any) {
|
||||
if (!asset?.id) return
|
||||
const next = new Set(suppressedDeletedIds.value)
|
||||
next.add(asset.id)
|
||||
suppressedDeletedIds.value = next
|
||||
stills.value = stills.value.filter(s => s.id !== asset.id)
|
||||
clips.value = clips.value.filter(c => c.id !== asset.id)
|
||||
tracks.value = tracks.value.filter(t => t.id !== asset.id)
|
||||
function dropIds() {
|
||||
return new Set([...(props.hiddenIds || []), ...suppressedDeletedIds.value])
|
||||
}
|
||||
|
||||
function onDeleteClick() {
|
||||
const asset = detailAsset.value
|
||||
if (!asset) return
|
||||
if (!asset?.id) return
|
||||
emit('delete', asset)
|
||||
removeLocalAsset(asset)
|
||||
window.setTimeout(() => { void fetchLibrary(true) }, 500)
|
||||
}
|
||||
|
||||
function mergeIds(prev: { id: string }[], next: { id: string }[]) {
|
||||
const drop = suppressedDeletedIds.value
|
||||
const drop = dropIds()
|
||||
const map = new Map<string, { id: string }>()
|
||||
for (const item of prev) {
|
||||
if (!drop.has(item.id)) map.set(item.id, item)
|
||||
@@ -318,7 +312,7 @@ function mergeIds(prev: { id: string }[], next: { id: string }[]) {
|
||||
|
||||
function applyLibraryPage(data: any, replace: boolean) {
|
||||
folders.value = data?.folders || folders.value
|
||||
const drop = suppressedDeletedIds.value
|
||||
const drop = dropIds()
|
||||
const keep = <T extends { id: string }>(list: T[]) => list.filter(item => !drop.has(item.id))
|
||||
if (replace) {
|
||||
clips.value = keep(data?.clips || []) as LibraryClip[]
|
||||
@@ -375,7 +369,7 @@ async function confirmWipeFolder() {
|
||||
async function fetchLibraryPage(cursor: string | null) {
|
||||
const folder = activeFolderId.value && activeFolderId.value !== 'all' ? activeFolderId.value : ''
|
||||
const type = filter.value === 'all' ? 'all' : filter.value === 'images' ? 'images' : filter.value === 'videos' ? 'videos' : 'music'
|
||||
const qs = new URLSearchParams({ limit: '50' })
|
||||
const qs = new URLSearchParams({ limit: '50', _: String(Date.now()) })
|
||||
if (folder) qs.set('folderId', folder)
|
||||
if (type !== 'all') qs.set('type', type)
|
||||
if (cursor) qs.set('cursor', cursor)
|
||||
@@ -384,6 +378,14 @@ async function fetchLibraryPage(cursor: string | null) {
|
||||
|
||||
let fetchGen = 0
|
||||
|
||||
function pageIds(data: { stills?: { id: string }[]; clips?: { id: string }[]; tracks?: { id: string }[] }) {
|
||||
return [
|
||||
...(data?.stills || []).map(item => item.id),
|
||||
...(data?.clips || []).map(item => item.id),
|
||||
...(data?.tracks || []).map(item => item.id)
|
||||
]
|
||||
}
|
||||
|
||||
async function fetchLibrary(force = false) {
|
||||
const stale = !fetchedAt.value || Date.now() - fetchedAt.value > 15_000
|
||||
const empty = !stills.value.length && !clips.value.length && !tracks.value.length
|
||||
@@ -392,9 +394,11 @@ async function fetchLibrary(force = false) {
|
||||
loading.value = true
|
||||
loadError.value = ''
|
||||
liveThumbs.value = new Set()
|
||||
const serverIds = new Set<string>()
|
||||
try {
|
||||
const first = await fetchLibraryPage(null)
|
||||
if (gen !== fetchGen) return
|
||||
for (const id of pageIds(first)) serverIds.add(id)
|
||||
applyLibraryPage(first, true)
|
||||
loading.value = false
|
||||
nextTick(() => observeThumbs())
|
||||
@@ -403,10 +407,14 @@ async function fetchLibrary(force = false) {
|
||||
while (cursor && gen === fetchGen) {
|
||||
const more = await fetchLibraryPage(cursor)
|
||||
if (gen !== fetchGen) return
|
||||
for (const id of pageIds(more)) serverIds.add(id)
|
||||
applyLibraryPage(more, false)
|
||||
cursor = more?.nextCursor || null
|
||||
nextTick(() => observeThumbs())
|
||||
}
|
||||
if (gen === fetchGen) {
|
||||
suppressedDeletedIds.value = new Set([...suppressedDeletedIds.value].filter(id => serverIds.has(id)))
|
||||
}
|
||||
} catch (e: any) {
|
||||
if (gen !== fetchGen) return
|
||||
loadError.value = e?.data?.statusMessage || e?.message || 'Could not load library'
|
||||
@@ -497,11 +505,15 @@ watch(entries, () => nextTick(() => observeThumbs()))
|
||||
|
||||
watch([filter, activeFolderId], () => {
|
||||
if (!props.open) return
|
||||
suppressedDeletedIds.value = new Set()
|
||||
pendingWipe.value = null
|
||||
void fetchLibrary(true)
|
||||
})
|
||||
|
||||
watch(() => props.refreshKey, () => {
|
||||
if (!props.open) return
|
||||
void fetchLibrary(true)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (import.meta.client) {
|
||||
document.body.style.overflow = ''
|
||||
|
||||
@@ -144,6 +144,8 @@
|
||||
:folder-id="ctx.form?.folderId"
|
||||
:preview-hidden="!ctx.eyeOpen"
|
||||
:is-hidden="ctx.isHidden"
|
||||
:refresh-key="ctx.libraryRefreshKey"
|
||||
:hidden-ids="ctx.forgottenStillIds"
|
||||
@close="ctx.closeLibrary()"
|
||||
@select="ctx.selectOutput"
|
||||
@use-image="ctx.onLibraryUseImage"
|
||||
|
||||
Reference in New Issue
Block a user