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:
@@ -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 = ''
|
||||
|
||||
Reference in New Issue
Block a user