Stop a folder wipe from restoring the pre-wipe library catalog.
The in-memory catalog could outlive the write, so delete-all came back as thousands of empty tiles and a stale badge. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -237,7 +237,7 @@
|
||||
@click="libraryOpen=true"
|
||||
>Library<span v-if="familyStillCount" class="stage-library-count">{{ familyStillCount }}</span></button>
|
||||
<div
|
||||
v-if="selected && selected.kind!=='track'"
|
||||
v-if="selected && selected.kind!=='track' && (selected.kind==='clip' || showSelectedStill)"
|
||||
class="stage-actions"
|
||||
aria-label="Selected still actions"
|
||||
>
|
||||
@@ -282,7 +282,7 @@
|
||||
<button type="button" class="stage-action-danger" @click="deleteOutput">Delete</button>
|
||||
</div>
|
||||
<button
|
||||
v-if="selected"
|
||||
v-if="selected && (selected.kind==='clip' || selected.kind==='track' || showSelectedStill)"
|
||||
type="button"
|
||||
class="eye-viewer"
|
||||
:aria-pressed="eyeOpen"
|
||||
@@ -322,7 +322,7 @@
|
||||
@loadedmetadata="onVideoTime"
|
||||
/>
|
||||
</template>
|
||||
<template v-else-if="selected">
|
||||
<template v-else-if="selected && showSelectedStill">
|
||||
<img
|
||||
v-show="!isHidden(selected)"
|
||||
:key="selected.id+'-'+stagePreviewNonce"
|
||||
@@ -373,6 +373,7 @@
|
||||
@load-input="onLibraryLoadInput"
|
||||
@load-input-raw="onLibraryLoadInputRaw"
|
||||
@delete="onLibraryDelete"
|
||||
@wiped="onLibraryWiped"
|
||||
@toggle-preview="toggleReveal()"
|
||||
/>
|
||||
</section>
|
||||
@@ -490,7 +491,7 @@ import {createLoraMemory,loraUse} from '~/shared/studio2/lora-memory.mjs'
|
||||
import {filterLorasForStudio,filterLorasForUse} from '~/utils/loras'
|
||||
import {sectionsFrom} from '~/shared/studio2/contracts.mjs'
|
||||
import {aspectOptions,resolveSize,bindClip,restoreAll,useAsSource,hydrateStudio2Job} from '~/shared/studio2/input.mjs'
|
||||
import {folderAssets,newestOutput,assetLabel,reconcileSelection,previewHidden} from '~/shared/studio2/viewer.mjs'
|
||||
import {folderAssets,newestOutput,assetLabel,reconcileSelection,previewHidden,folderImageCount,libraryAfterWipe} from '~/shared/studio2/viewer.mjs'
|
||||
import {queueJobs,queueEngineLabel,jobStageLabel,jobProgressView,elapsedSeconds} from '~/shared/studio2/queue-view.mjs'
|
||||
import {gpuStatus} from '~/shared/studio2/status.mjs'
|
||||
import {CAPTION_STYLES} from '~/shared/caption.mjs'
|
||||
@@ -973,11 +974,18 @@ const pickerAssets=computed(()=>{
|
||||
})
|
||||
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)
|
||||
const fromFolder=Number(folder?.imageCount||0)
|
||||
if(fromFolder>0) return fromFolder
|
||||
return family.value.filter((a:any)=>a.kind==='still').length
|
||||
const familyStillCount=computed(()=>folderImageCount(
|
||||
(library.value.folders||[]).find((f:any)=>f.id===form.folderId),
|
||||
family.value.filter((a:any)=>a.kind==='still').length
|
||||
))
|
||||
const showSelectedStill=computed(()=>{
|
||||
const item=selected.value
|
||||
if(!item?.id || item.kind==='clip' || item.kind==='track') return false
|
||||
if(forgottenStillIds.value.has(item.id)) return false
|
||||
if((library.value.stills||[]).some((s:any)=>s.id===item.id)) return true
|
||||
const folder=(library.value.folders||[]).find((f:any)=>f.id===(item.folderId||form.folderId))
|
||||
if(folder && typeof folder.imageCount==='number' && folder.imageCount===0) return false
|
||||
return true
|
||||
})
|
||||
const sourceAsset=computed(()=>form.startClipId?clips.value.find((c:any)=>c.id===form.startClipId):stills.value.find((s:any)=>s.id===(form.imageAId||form.identityStillId||form.photos?.[0]?.stillId)))
|
||||
const sourceSize=computed(()=>measured[sourceAsset.value?.id] || sourceAsset.value)
|
||||
@@ -1539,6 +1547,35 @@ function onLibraryLoadInputRaw(item:any){
|
||||
function onLibraryDelete(item:any){
|
||||
void deleteOutput(item)
|
||||
}
|
||||
function onLibraryWiped(result:any){
|
||||
const folderId=String(result?.folderId||form.folderId||'')
|
||||
const next=libraryAfterWipe({
|
||||
folders:library.value.folders,
|
||||
stills:library.value.stills,
|
||||
clips:library.value.clips,
|
||||
tracks:library.value.tracks,
|
||||
suppressedIds:[...forgottenStillIds.value]
|
||||
}, result, folderId)
|
||||
forgottenStillIds.value=new Set(next.suppressedIds)
|
||||
clearFormSlots(next.suppressedIds)
|
||||
if(selected.value && (forgottenStillIds.value.has(selected.value.id) || String(selected.value.folderId||'')===folderId)){
|
||||
selected.value=null
|
||||
selectionPinned.value=false
|
||||
}
|
||||
library.value={
|
||||
...library.value,
|
||||
folders:next.folders,
|
||||
stills:next.stills,
|
||||
clips:next.clips,
|
||||
tracks:next.tracks,
|
||||
drafts:result?.drafts||[],
|
||||
loraAliases:result?.loraAliases||library.value.loraAliases||{},
|
||||
loraTriggers:result?.loraTriggers||library.value.loraTriggers||{},
|
||||
keepPrompts:result?.keepPrompts||library.value.keepPrompts
|
||||
}
|
||||
libraryRefreshKey.value+=1
|
||||
void loadLibraryOnce()
|
||||
}
|
||||
function onStageHotkey(e:KeyboardEvent){
|
||||
if(e.metaKey||e.ctrlKey||e.altKey)return
|
||||
const t=e.target as HTMLElement|null
|
||||
@@ -1707,6 +1744,13 @@ function onTaskSelect(event:Event){chooseTask((event.target as HTMLSelectElement
|
||||
function chooseClip(id:string){if(!id){form.startClipId='';return}const clip=clips.value.find((c:any)=>c.id===id);if(clip){try{Object.assign(form,bindClip(form,clip,xaigen,loraMemory))}catch(e:any){error.value=e?.message||'Could not copy clip settings.';form.startClipId=clip.id;form.mode='extend';form.engine=xaigen && form.engine==='ltx'?'ltx':'minimax'}}}
|
||||
function selectOutput(item:any){
|
||||
stageMenu.value=''
|
||||
if(item?.id && !forgottenStillIds.value.has(item.id)){
|
||||
const kind=item.kind==='clip'?'clips':item.kind==='track'?'tracks':'stills'
|
||||
const list=library.value[kind]||[]
|
||||
if(!list.some((row:any)=>row.id===item.id)){
|
||||
library.value={...library.value,[kind]:[...list,{...item,folderId:item.folderId||form.folderId}]}
|
||||
}
|
||||
}
|
||||
selected.value=item
|
||||
selectionPinned.value=!!item
|
||||
if(form.mode==='extend' && item?.kind==='clip')chooseClip(item.id)
|
||||
@@ -1754,7 +1798,10 @@ function ingestNewOutputs(nextJobs:any[]){
|
||||
const fresh=newestOutput(nextJobs,seenOutputs,form.folderId)
|
||||
for(const job of nextJobs){
|
||||
for(const output of job.outputs||[]){
|
||||
if(seenOutputs.has(output.id)) continue
|
||||
if(seenOutputs.has(output.id) || forgottenStillIds.value.has(output.id)){
|
||||
seenOutputs.add(output.id)
|
||||
continue
|
||||
}
|
||||
seenOutputs.add(output.id)
|
||||
const meta=output.studio2||{}
|
||||
const folderId=job.request?.folderId||form.folderId
|
||||
@@ -1778,7 +1825,7 @@ function ingestNewOutputs(nextJobs:any[]){
|
||||
}
|
||||
}
|
||||
}
|
||||
if(fresh){
|
||||
if(fresh && !forgottenStillIds.value.has(fresh.id)){
|
||||
// Merge into catalog above; only auto-select when the user has not pinned a pick.
|
||||
if(!selectionPinned.value){
|
||||
const existingFresh=family.value.find(a=>a.id===fresh.id)
|
||||
@@ -1788,6 +1835,9 @@ function ingestNewOutputs(nextJobs:any[]){
|
||||
selected.value={...fresh,kind,folderId:form.folderId,studio2:fresh.studio2}
|
||||
}
|
||||
}
|
||||
}else if(selected.value && forgottenStillIds.value.has(selected.value.id)){
|
||||
selected.value=null
|
||||
selectionPinned.value=false
|
||||
}else if(selected.value){
|
||||
const next=reconcileSelection(selected.value,family.value)
|
||||
if(form.mode!=='music' && next?.kind==='track'){
|
||||
@@ -1795,8 +1845,9 @@ function ingestNewOutputs(nextJobs:any[]){
|
||||
if(nonTrack && !selectionPinned.value) selected.value=nonTrack
|
||||
else if(next?.id===selected.value.id) selected.value=next
|
||||
}else if(next) selected.value=next
|
||||
else { selected.value=null; selectionPinned.value=false }
|
||||
}else{
|
||||
selected.value=reconcileSelection(null,family.value)
|
||||
selected.value=reconcileSelection(null,family.value.filter((a:any)=>!forgottenStillIds.value.has(a.id)))
|
||||
}
|
||||
const newestTrack=(library.value.tracks||[]).filter((t:any)=>t.folderId===form.folderId).sort((a:any,b:any)=>(b.createdAt||0)-(a.createdAt||0))[0]
|
||||
if(form.mode==='music' && newestTrack && !seenOutputs.has(newestTrack.id)){
|
||||
@@ -1961,12 +2012,15 @@ async function cancel(job:any){
|
||||
await refreshJobs()
|
||||
}
|
||||
|
||||
let libraryLoadGen=0
|
||||
async function loadLibraryOnce(){
|
||||
// Current folder page only — never the yearly Inbox JSON on /
|
||||
const gen=++libraryLoadGen
|
||||
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()}`)
|
||||
if(gen!==libraryLoadGen) return
|
||||
const pageStills=page.stills||[]
|
||||
const forget=forgottenStillIds.value
|
||||
const keepIds=[
|
||||
@@ -1980,10 +2034,12 @@ async function loadLibraryOnce(){
|
||||
if(stillMissing.length){
|
||||
try{
|
||||
const full=await $fetch<any>(`/api/library?light=1&_=${Date.now()}`)
|
||||
if(gen!==libraryLoadGen) return
|
||||
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 */}
|
||||
}
|
||||
if(gen!==libraryLoadGen) return
|
||||
library.value={
|
||||
folders:page.folders||library.value.folders||[],
|
||||
stills:[...pageStills,...kept].filter((s:any)=>!forget.has(s.id)),
|
||||
@@ -2103,6 +2159,7 @@ const mobileCtx=computed(()=>({
|
||||
libraryRefreshKey:libraryRefreshKey.value,
|
||||
family:family.value,
|
||||
familyStillCount:familyStillCount.value,
|
||||
showSelectedStill:showSelectedStill.value,
|
||||
libraryOpen:libraryOpen.value,
|
||||
eyeOpen:eyeOpen.value,
|
||||
hideInputs:hideInputs.value,
|
||||
@@ -2144,6 +2201,7 @@ const mobileCtx=computed(()=>({
|
||||
selectOutput,
|
||||
stepFamily,
|
||||
deleteOutput,
|
||||
onLibraryWiped,
|
||||
queue,
|
||||
upload,
|
||||
cancel,
|
||||
|
||||
@@ -154,7 +154,7 @@ import {
|
||||
type LibraryTrack
|
||||
} from '~/utils/libraryBrowse'
|
||||
import { clipSettingsRows, stillSettingsRows, trackSettingsRows } from '~/utils/libraryGeneration'
|
||||
import { assetLabel } from '~/shared/studio2/viewer.mjs'
|
||||
import { assetLabel, libraryAfterWipe, mergeLibraryRows, replaceLibraryRows } from '~/shared/studio2/viewer.mjs'
|
||||
|
||||
const props = defineProps<{
|
||||
open: boolean
|
||||
@@ -177,6 +177,7 @@ const emit = defineEmits<{
|
||||
'load-input': [asset: any]
|
||||
'load-input-raw': [asset: any]
|
||||
delete: [asset: any]
|
||||
wiped: [payload: any]
|
||||
'toggle-preview': []
|
||||
}>()
|
||||
|
||||
@@ -298,32 +299,19 @@ function onDeleteClick() {
|
||||
emit('delete', asset)
|
||||
}
|
||||
|
||||
function mergeIds(prev: { id: string }[], next: { id: string }[]) {
|
||||
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)
|
||||
}
|
||||
for (const item of next) {
|
||||
if (!drop.has(item.id)) map.set(item.id, item)
|
||||
}
|
||||
return [...map.values()]
|
||||
}
|
||||
|
||||
function applyLibraryPage(data: any, replace: boolean) {
|
||||
folders.value = data?.folders || folders.value
|
||||
const drop = dropIds()
|
||||
const keep = <T extends { id: string }>(list: T[]) => list.filter(item => !drop.has(item.id))
|
||||
if (Array.isArray(data?.folders) && data.folders.length) folders.value = data.folders
|
||||
const drop = [...dropIds()]
|
||||
if (replace) {
|
||||
clips.value = keep(data?.clips || []) as LibraryClip[]
|
||||
stills.value = keep(data?.stills || []) as LibraryStill[]
|
||||
tracks.value = keep(data?.tracks || []) as LibraryTrack[]
|
||||
clips.value = replaceLibraryRows(data?.clips || [], drop) as LibraryClip[]
|
||||
stills.value = replaceLibraryRows(data?.stills || [], drop) as LibraryStill[]
|
||||
tracks.value = replaceLibraryRows(data?.tracks || [], drop) as LibraryTrack[]
|
||||
} else {
|
||||
clips.value = mergeIds(clips.value, data?.clips || []) as LibraryClip[]
|
||||
stills.value = mergeIds(stills.value, data?.stills || []) as LibraryStill[]
|
||||
tracks.value = mergeIds(tracks.value, data?.tracks || []) as LibraryTrack[]
|
||||
clips.value = mergeLibraryRows(clips.value, data?.clips || [], drop) as LibraryClip[]
|
||||
stills.value = mergeLibraryRows(stills.value, data?.stills || [], drop) as LibraryStill[]
|
||||
tracks.value = mergeLibraryRows(tracks.value, data?.tracks || [], drop) as LibraryTrack[]
|
||||
}
|
||||
nextCursor.value = data?.nextCursor || null
|
||||
nextCursor.value = data?.nextCursor ?? null
|
||||
fetchedAt.value = Date.now()
|
||||
}
|
||||
|
||||
@@ -343,20 +331,35 @@ async function confirmWipeFolder() {
|
||||
if (!pending || wipeBusy.value) return
|
||||
pendingWipe.value = null
|
||||
wipeBusy.value = true
|
||||
fetchGen += 1
|
||||
const gone = [
|
||||
...stills.value.filter(item => item.folderId === pending.folderId).map(item => item.id),
|
||||
...clips.value.filter(item => item.folderId === pending.folderId).map(item => item.id),
|
||||
...tracks.value.filter(item => item.folderId === pending.folderId).map(item => item.id)
|
||||
]
|
||||
const pendingIds = new Set(suppressedDeletedIds.value)
|
||||
for (const id of gone) pendingIds.add(id)
|
||||
suppressedDeletedIds.value = pendingIds
|
||||
stills.value = stills.value.filter(item => item.folderId !== pending.folderId)
|
||||
clips.value = clips.value.filter(item => item.folderId !== pending.folderId)
|
||||
tracks.value = tracks.value.filter(item => item.folderId !== pending.folderId)
|
||||
try {
|
||||
const gone = [
|
||||
...stills.value.filter(item => item.folderId === pending.folderId).map(item => item.id),
|
||||
...clips.value.filter(item => item.folderId === pending.folderId).map(item => item.id),
|
||||
...tracks.value.filter(item => item.folderId === pending.folderId).map(item => item.id)
|
||||
]
|
||||
const next = new Set(suppressedDeletedIds.value)
|
||||
for (const id of gone) next.add(id)
|
||||
suppressedDeletedIds.value = next
|
||||
stills.value = stills.value.filter(item => item.folderId !== pending.folderId)
|
||||
clips.value = clips.value.filter(item => item.folderId !== pending.folderId)
|
||||
tracks.value = tracks.value.filter(item => item.folderId !== pending.folderId)
|
||||
const result = await $fetch<any>(`/api/library/folders/${pending.folderId}/wipe`, { method: 'POST' })
|
||||
applyLibraryPage(result, true)
|
||||
const next = libraryAfterWipe({
|
||||
folders: folders.value,
|
||||
stills: [...stills.value, ...gone.map(id => ({ id, folderId: pending.folderId }))],
|
||||
clips: clips.value,
|
||||
tracks: tracks.value,
|
||||
suppressedIds: [...suppressedDeletedIds.value]
|
||||
}, result, pending.folderId)
|
||||
suppressedDeletedIds.value = new Set(next.suppressedIds)
|
||||
folders.value = next.folders
|
||||
stills.value = next.stills as LibraryStill[]
|
||||
clips.value = next.clips as LibraryClip[]
|
||||
tracks.value = next.tracks as LibraryTrack[]
|
||||
nextCursor.value = null
|
||||
fetchedAt.value = 0
|
||||
emit('wiped', { ...result, folderId: pending.folderId, suppressedIds: next.suppressedIds })
|
||||
await fetchLibrary(true)
|
||||
} catch (e: any) {
|
||||
loadError.value = e?.data?.statusMessage || e?.message || 'Could not empty that folder'
|
||||
@@ -378,14 +381,6 @@ 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
|
||||
@@ -394,11 +389,9 @@ 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())
|
||||
@@ -407,14 +400,10 @@ 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'
|
||||
|
||||
@@ -125,7 +125,7 @@
|
||||
playsinline
|
||||
/>
|
||||
<img
|
||||
v-else-if="ctx.selected"
|
||||
v-else-if="ctx.selected && ctx.showSelectedStill"
|
||||
v-show="!ctx.isHidden(ctx.selected)"
|
||||
:key="ctx.selected.id+'-'+(ctx.stagePreviewNonce||0)"
|
||||
class="m-stage-still"
|
||||
@@ -155,6 +155,7 @@
|
||||
@load-input="ctx.onLibraryLoadInput"
|
||||
@load-input-raw="ctx.onLibraryLoadInputRaw"
|
||||
@delete="ctx.onLibraryDelete"
|
||||
@wiped="ctx.onLibraryWiped"
|
||||
@toggle-preview="ctx.toggleReveal()"
|
||||
/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user