Delete library stills from disk before the catalog write, and stop caching their media.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+57
-41
@@ -556,7 +556,7 @@ import {
|
||||
type LibraryStill,
|
||||
type LibraryTrack
|
||||
} from '~/utils/libraryBrowse'
|
||||
import { libraryAfterWipe, mergeLibraryRows, replaceLibraryRows } from '~/shared/studio2/viewer.mjs'
|
||||
import { libraryAfterWipe, libraryMediaUrl, mergeLibraryRows } from '~/shared/studio2/viewer.mjs'
|
||||
import { isXaigenStudio } from '~/utils/videoModels'
|
||||
import { clipSettingsRows, stillSettingsRows, trackSettingsRows } from '~/utils/libraryGeneration'
|
||||
|
||||
@@ -637,7 +637,7 @@ const pendingDelete = ref<{ title: string; name: string; detail?: string; conseq
|
||||
const pendingWipe = ref<{ folderId: string; name: string; count: number } | null>(null)
|
||||
const wipeBusy = ref(false)
|
||||
const libraryLoading = ref(false)
|
||||
const suppressedDeletedIds = ref(new Set<string>())
|
||||
const catalogEpoch = ref(0)
|
||||
const keepingInputBusy = ref(false)
|
||||
const toasts = ref<Array<{ id: number; message: string }>>([])
|
||||
let toastId = 0
|
||||
@@ -711,12 +711,13 @@ const visibleEntries = computed(() => {
|
||||
const previewVideo = computed(() => {
|
||||
if (focused.value?.kind !== 'clip' || !focused.value.group) return ''
|
||||
const id = focusedPartId.value || focused.value.group.head.id
|
||||
return `/api/library/clips/${id}/video`
|
||||
return libraryMediaUrl(`/api/library/clips/${id}/video`, catalogEpoch.value)
|
||||
})
|
||||
const previewStillSrc = computed(() => {
|
||||
if (focused.value?.kind !== 'still' || !focused.value.stillGroup) return ''
|
||||
const id = focusedPartId.value || focused.value.stillGroup.head.id
|
||||
return `/api/library/stills/${id}`
|
||||
if (!stills.value.some(item => item.id === id)) return ''
|
||||
return libraryMediaUrl(`/api/library/stills/${id}`, catalogEpoch.value)
|
||||
})
|
||||
const previewAudio = computed(() => {
|
||||
if (focused.value?.kind !== 'track' || !focused.value.track) return ''
|
||||
@@ -777,14 +778,14 @@ const detailMeta = computed(() => {
|
||||
const downloadHref = computed(() => {
|
||||
if (focused.value?.kind === 'clip' && focused.value.group) {
|
||||
const id = focusedPartId.value || focused.value.group.head.id
|
||||
return `/api/library/clips/${id}/video`
|
||||
return libraryMediaUrl(`/api/library/clips/${id}/video`, catalogEpoch.value)
|
||||
}
|
||||
if (focused.value?.kind === 'track' && focused.value.track) {
|
||||
return `/api/library/tracks/${focused.value.track.id}/audio`
|
||||
return libraryMediaUrl(`/api/library/tracks/${focused.value.track.id}/audio`, catalogEpoch.value)
|
||||
}
|
||||
if (focused.value?.stillGroup) {
|
||||
const id = focusedPartId.value || focused.value.stillGroup.head.id
|
||||
return `/api/library/stills/${id}`
|
||||
return libraryMediaUrl(`/api/library/stills/${id}`, catalogEpoch.value)
|
||||
}
|
||||
return ''
|
||||
})
|
||||
@@ -809,6 +810,7 @@ function applyLibrary(data: unknown, opts?: { replace?: boolean }) {
|
||||
tracks?: LibraryTrack[]
|
||||
nextCursor?: string | null
|
||||
hasMore?: boolean
|
||||
catalogEpoch?: number
|
||||
}
|
||||
if (payload.id && !payload.folders && !payload.clips && !payload.stills && !payload.tracks) {
|
||||
if (typeof payload.hideInput === 'boolean') {
|
||||
@@ -822,15 +824,16 @@ function applyLibrary(data: unknown, opts?: { replace?: boolean }) {
|
||||
return
|
||||
}
|
||||
if (payload.folders?.length) folders.value = payload.folders
|
||||
const drop = [...suppressedDeletedIds.value]
|
||||
if (typeof payload.catalogEpoch === 'number') catalogEpoch.value = payload.catalogEpoch
|
||||
const rows = <T,>(list: T[] | undefined) => (Array.isArray(list) ? list : []).filter(item => (item as { id?: string })?.id)
|
||||
if (replace) {
|
||||
clips.value = replaceLibraryRows(payload.clips || [], drop)
|
||||
stills.value = replaceLibraryRows(payload.stills || [], drop)
|
||||
tracks.value = replaceLibraryRows(payload.tracks || [], drop)
|
||||
clips.value = rows(payload.clips)
|
||||
stills.value = rows(payload.stills)
|
||||
tracks.value = rows(payload.tracks)
|
||||
} else {
|
||||
clips.value = mergeLibraryRows(clips.value, payload.clips || [], drop)
|
||||
stills.value = mergeLibraryRows(stills.value, payload.stills || [], drop)
|
||||
tracks.value = mergeLibraryRows(tracks.value, payload.tracks || [], drop)
|
||||
clips.value = mergeLibraryRows(clips.value, payload.clips || [], [])
|
||||
stills.value = mergeLibraryRows(stills.value, payload.stills || [], [])
|
||||
tracks.value = mergeLibraryRows(tracks.value, payload.tracks || [], [])
|
||||
}
|
||||
libraryNextCursor.value = payload.nextCursor || null
|
||||
if (folderId.value !== 'all' && !folders.value.some(folder => folder.id === folderId.value)) {
|
||||
@@ -948,9 +951,14 @@ async function toggleFocusedHidden() {
|
||||
}
|
||||
|
||||
function thumbSrc(entry: LibraryEntry) {
|
||||
if (entry.kind === 'clip' && entry.group) return `/api/library/clips/${entry.group.head.id}/thumb`
|
||||
const version = catalogEpoch.value
|
||||
if (entry.kind === 'clip' && entry.group) return libraryMediaUrl(`/api/library/clips/${entry.group.head.id}/thumb`, version)
|
||||
if (entry.kind === 'track') return ''
|
||||
if (entry.stillGroup) return `/api/library/stills/${entry.stillGroup.parts[cardImageIndex(entry)].id}/thumb`
|
||||
if (entry.stillGroup) {
|
||||
const id = entry.stillGroup.parts[cardImageIndex(entry)]?.id
|
||||
if (!id || !stills.value.some(item => item.id === id)) return ''
|
||||
return libraryMediaUrl(`/api/library/stills/${id}/thumb`, version)
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
@@ -974,9 +982,9 @@ function partThumb(part: LibraryClip | LibraryStill) {
|
||||
if ('hideThumbnail' in part && !('role' in part)) {
|
||||
const clip = part as LibraryClip
|
||||
// Prefer this clip’s first frame so siblings don’t all look like the Start thumb.
|
||||
return `/api/library/clips/${clip.id}/first-frame?thumb=1&v=${encodeURIComponent(clip.id)}`
|
||||
return libraryMediaUrl(`/api/library/clips/${clip.id}/first-frame?thumb=1`, catalogEpoch.value)
|
||||
}
|
||||
return `/api/library/stills/${part.id}/thumb`
|
||||
return libraryMediaUrl(`/api/library/stills/${part.id}/thumb`, catalogEpoch.value)
|
||||
}
|
||||
|
||||
function focusPart(id: string) {
|
||||
@@ -1032,16 +1040,11 @@ function entryPartIds(entry: LibraryEntry) {
|
||||
}
|
||||
|
||||
async function selectAll() {
|
||||
// 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)
|
||||
selectedKeys.value = entries.value.map(entry => entry.key)
|
||||
lastSelectedKey.value = selectedKeys.value.at(-1) || ''
|
||||
}
|
||||
|
||||
@@ -1282,14 +1285,12 @@ function askRemoveKeys(keys: string[]) {
|
||||
}
|
||||
}
|
||||
|
||||
function markDeletedIds(ids: string[]) {
|
||||
function dropLocalIds(ids: string[]) {
|
||||
if (!ids.length) return
|
||||
const next = new Set(suppressedDeletedIds.value)
|
||||
for (const id of ids) next.add(id)
|
||||
suppressedDeletedIds.value = next
|
||||
stills.value = stills.value.filter(item => !next.has(item.id))
|
||||
clips.value = clips.value.filter(item => !next.has(item.id))
|
||||
tracks.value = tracks.value.filter(item => !next.has(item.id))
|
||||
const gone = new Set(ids)
|
||||
stills.value = stills.value.filter(item => !gone.has(item.id))
|
||||
clips.value = clips.value.filter(item => !gone.has(item.id))
|
||||
tracks.value = tracks.value.filter(item => !gone.has(item.id))
|
||||
}
|
||||
|
||||
async function confirmDelete() {
|
||||
@@ -1309,13 +1310,8 @@ async function confirmDelete() {
|
||||
for (const part of entry.stillGroup.parts || [entry.stillGroup.head]) gone.push(part.id)
|
||||
}
|
||||
}
|
||||
markDeletedIds(gone)
|
||||
if (pending.keys.includes(focusedKey.value)) {
|
||||
focusedKey.value = ''
|
||||
focusedPartId.value = ''
|
||||
}
|
||||
clearSelection()
|
||||
await Promise.allSettled(items.map((entry) => {
|
||||
libraryFetchGen += 1
|
||||
const results = await Promise.allSettled(items.map((entry) => {
|
||||
if (entry.kind === 'clip') {
|
||||
return $fetch(`/api/library/clips/${entry.group!.head.id}`, { method: 'DELETE', query: { family: '1' } })
|
||||
}
|
||||
@@ -1324,6 +1320,27 @@ async function confirmDelete() {
|
||||
}
|
||||
return $fetch(`/api/library/stills/${entry.stillGroup!.head.id}`, { method: 'DELETE', query: { family: '1' } })
|
||||
}))
|
||||
const removed: string[] = []
|
||||
results.forEach((result, index) => {
|
||||
if (result.status === 'fulfilled') {
|
||||
const entry = items[index]
|
||||
removed.push(...entryPartIds(entry))
|
||||
return
|
||||
}
|
||||
const status = Number((result.reason as { statusCode?: number, status?: number })?.statusCode || (result.reason as { status?: number })?.status || 0)
|
||||
if (status === 404) removed.push(...entryPartIds(items[index]))
|
||||
})
|
||||
if (removed.length !== gone.length) {
|
||||
const failed = results.find(result => result.status === 'rejected') as PromiseRejectedResult | undefined
|
||||
const reason = failed?.reason as { data?: { statusMessage?: string }, message?: string } | undefined
|
||||
toast(reason?.data?.statusMessage || reason?.message || 'Could not delete every item')
|
||||
}
|
||||
dropLocalIds(removed)
|
||||
if (pending.keys.includes(focusedKey.value)) {
|
||||
focusedKey.value = ''
|
||||
focusedPartId.value = ''
|
||||
}
|
||||
clearSelection()
|
||||
await loadLibrary()
|
||||
} finally {
|
||||
deleteBusy.value = false
|
||||
@@ -1356,7 +1373,6 @@ async function confirmWipeFolder() {
|
||||
...clips.value.filter(item => item.folderId === pending.folderId).map(item => item.id),
|
||||
...tracks.value.filter(item => item.folderId === pending.folderId).map(item => item.id)
|
||||
]
|
||||
markDeletedIds(gone)
|
||||
clearSelection()
|
||||
clearFocus()
|
||||
try {
|
||||
@@ -1366,9 +1382,9 @@ async function confirmWipeFolder() {
|
||||
stills: [...stills.value, ...gone.map(id => ({ id, folderId: pending.folderId }))],
|
||||
clips: clips.value,
|
||||
tracks: tracks.value,
|
||||
suppressedIds: [...suppressedDeletedIds.value]
|
||||
suppressedIds: []
|
||||
}, result, pending.folderId)
|
||||
suppressedDeletedIds.value = new Set(next.suppressedIds)
|
||||
if (typeof result?.catalogEpoch === 'number') catalogEpoch.value = result.catalogEpoch
|
||||
folders.value = next.folders
|
||||
stills.value = next.stills
|
||||
clips.value = next.clips
|
||||
|
||||
Reference in New Issue
Block a user