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:
+31
-12
@@ -851,8 +851,16 @@ function applyLibrary(data: unknown, opts?: { replace?: boolean }) {
|
||||
const libraryNextCursor = ref<string | null>(null)
|
||||
let libraryFetchGen = 0
|
||||
|
||||
function payloadIds(payload: { stills?: { id: string }[]; clips?: { id: string }[]; tracks?: { id: string }[] }) {
|
||||
return [
|
||||
...(payload?.stills || []).map(item => item.id),
|
||||
...(payload?.clips || []).map(item => item.id),
|
||||
...(payload?.tracks || []).map(item => item.id)
|
||||
]
|
||||
}
|
||||
|
||||
async function fetchLibraryPage(cursor: string | null) {
|
||||
const qs = new URLSearchParams({ limit: '50' })
|
||||
const qs = new URLSearchParams({ limit: '50', _: String(Date.now()) })
|
||||
if (folderId.value && folderId.value !== 'all') qs.set('folderId', folderId.value)
|
||||
if (filter.value === 'images') qs.set('type', 'images')
|
||||
else if (filter.value === 'videos') qs.set('type', 'videos')
|
||||
@@ -865,25 +873,23 @@ async function loadLibrary() {
|
||||
// First page paints immediately; remaining pages append in the background
|
||||
const gen = ++libraryFetchGen
|
||||
libraryLoading.value = true
|
||||
const serverIds = new Set<string>()
|
||||
try {
|
||||
const first = await fetchLibraryPage(null)
|
||||
if (gen !== libraryFetchGen) return
|
||||
for (const id of payloadIds(first)) serverIds.add(id)
|
||||
applyLibrary(first, { replace: true })
|
||||
let cursor = first?.nextCursor || null
|
||||
while (cursor && gen === libraryFetchGen) {
|
||||
const page = await fetchLibraryPage(cursor)
|
||||
if (gen !== libraryFetchGen) return
|
||||
for (const id of payloadIds(page)) serverIds.add(id)
|
||||
applyLibrary(page, { replace: false })
|
||||
cursor = page?.nextCursor || null
|
||||
}
|
||||
if (gen === libraryFetchGen) {
|
||||
// Drop suppressions that the server no longer returns
|
||||
const live = new Set([
|
||||
...stills.value.map(item => item.id),
|
||||
...clips.value.map(item => item.id),
|
||||
...tracks.value.map(item => item.id)
|
||||
])
|
||||
suppressedDeletedIds.value = new Set([...suppressedDeletedIds.value].filter(id => live.has(id)))
|
||||
// Keep hiding an id the server still returned. Drop it once a full fetch omits it.
|
||||
suppressedDeletedIds.value = new Set([...suppressedDeletedIds.value].filter(id => serverIds.has(id)))
|
||||
}
|
||||
} finally {
|
||||
if (gen === libraryFetchGen) libraryLoading.value = false
|
||||
@@ -1043,10 +1049,24 @@ function toggleSelectMode() {
|
||||
if (selectMode.value) clearFocus()
|
||||
}
|
||||
|
||||
function entryPartIds(entry: LibraryEntry) {
|
||||
if (entry.kind === 'clip' && entry.group) return (entry.group.parts || [entry.group.head]).map(part => part.id)
|
||||
if (entry.kind === 'track' && entry.track) return [entry.track.id]
|
||||
if (entry.stillGroup) return (entry.stillGroup.parts || [entry.stillGroup.head]).map(part => part.id)
|
||||
return []
|
||||
}
|
||||
|
||||
async function selectAll() {
|
||||
// Whole folder — not only the page already painted
|
||||
await ensureLibraryFullyLoaded()
|
||||
selectedKeys.value = entries.value.map(entry => entry.key)
|
||||
// Loaded rows only. A fresh full-catalog fetch would merge later pages and
|
||||
// can put suppressed ids back into the selection.
|
||||
const start = Date.now()
|
||||
while (libraryLoading.value && Date.now() - start < 15000) {
|
||||
await new Promise(resolve => setTimeout(resolve, 40))
|
||||
}
|
||||
const drop = suppressedDeletedIds.value
|
||||
selectedKeys.value = entries.value
|
||||
.filter(entry => entryPartIds(entry).every(id => !drop.has(id)))
|
||||
.map(entry => entry.key)
|
||||
lastSelectedKey.value = selectedKeys.value.at(-1) || ''
|
||||
}
|
||||
|
||||
@@ -1426,7 +1446,6 @@ watch(searchDraft, (value) => {
|
||||
})
|
||||
watch([folderId, filter], () => {
|
||||
clearSelection()
|
||||
suppressedDeletedIds.value = new Set()
|
||||
if (scroller.value) scroller.value.scrollTop = 0
|
||||
})
|
||||
watch(search, () => {
|
||||
|
||||
Reference in New Issue
Block a user