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:
@@ -154,7 +154,7 @@ import {
|
||||
type LibraryTrack
|
||||
} from '~/utils/libraryBrowse'
|
||||
import { clipSettingsRows, stillSettingsRows, trackSettingsRows } from '~/utils/libraryGeneration'
|
||||
import { assetLabel, libraryAfterWipe, mergeLibraryRows, replaceLibraryRows } from '~/shared/studio2/viewer.mjs'
|
||||
import { assetLabel, libraryAfterWipe, libraryMediaUrl, mergeLibraryRows } from '~/shared/studio2/viewer.mjs'
|
||||
|
||||
const props = defineProps<{
|
||||
open: boolean
|
||||
@@ -201,7 +201,7 @@ const tracks = ref<LibraryTrack[]>([])
|
||||
const fetchedAt = ref(0)
|
||||
const nextCursor = ref<string | null>(null)
|
||||
const liveThumbs = ref(new Set<string>())
|
||||
const suppressedDeletedIds = ref(new Set<string>())
|
||||
const catalogEpoch = ref(0)
|
||||
const wipeBusy = ref(false)
|
||||
const pendingWipe = ref<{ folderId: string; name: string; count: number } | null>(null)
|
||||
let thumbObserver: IntersectionObserver | null = null
|
||||
@@ -252,9 +252,14 @@ const detailRows = computed(() => {
|
||||
})
|
||||
|
||||
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.head.id}/thumb`
|
||||
if (entry.stillGroup) {
|
||||
const id = entry.stillGroup.head.id
|
||||
if (!stills.value.some(item => item.id === id)) return ''
|
||||
return libraryMediaUrl(`/api/library/stills/${id}/thumb`, version)
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
@@ -289,10 +294,6 @@ function useAndClose() {
|
||||
close()
|
||||
}
|
||||
|
||||
function dropIds() {
|
||||
return new Set([...(props.hiddenIds || []), ...suppressedDeletedIds.value])
|
||||
}
|
||||
|
||||
function onDeleteClick() {
|
||||
const asset = detailAsset.value
|
||||
if (!asset?.id) return
|
||||
@@ -301,15 +302,16 @@ function onDeleteClick() {
|
||||
|
||||
function applyLibraryPage(data: any, replace: boolean) {
|
||||
if (Array.isArray(data?.folders) && data.folders.length) folders.value = data.folders
|
||||
const drop = [...dropIds()]
|
||||
if (typeof data?.catalogEpoch === 'number') catalogEpoch.value = data.catalogEpoch
|
||||
const rows = (list: any[]) => (Array.isArray(list) ? list : []).filter(item => item?.id)
|
||||
if (replace) {
|
||||
clips.value = replaceLibraryRows(data?.clips || [], drop) as LibraryClip[]
|
||||
stills.value = replaceLibraryRows(data?.stills || [], drop) as LibraryStill[]
|
||||
tracks.value = replaceLibraryRows(data?.tracks || [], drop) as LibraryTrack[]
|
||||
clips.value = rows(data?.clips) as LibraryClip[]
|
||||
stills.value = rows(data?.stills) as LibraryStill[]
|
||||
tracks.value = rows(data?.tracks) as LibraryTrack[]
|
||||
} else {
|
||||
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[]
|
||||
clips.value = mergeLibraryRows(clips.value, data?.clips || [], []) as LibraryClip[]
|
||||
stills.value = mergeLibraryRows(stills.value, data?.stills || [], []) as LibraryStill[]
|
||||
tracks.value = mergeLibraryRows(tracks.value, data?.tracks || [], []) as LibraryTrack[]
|
||||
}
|
||||
nextCursor.value = data?.nextCursor ?? null
|
||||
fetchedAt.value = Date.now()
|
||||
@@ -337,9 +339,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)
|
||||
]
|
||||
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)
|
||||
@@ -350,16 +349,16 @@ 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 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 })
|
||||
emit('wiped', { ...result, folderId: pending.folderId, deletedIds: [...new Set([...(result?.deletedIds || []), ...gone])] })
|
||||
await fetchLibrary(true)
|
||||
} catch (e: any) {
|
||||
loadError.value = e?.data?.statusMessage || e?.message || 'Could not empty that folder'
|
||||
@@ -500,9 +499,18 @@ watch([filter, activeFolderId], () => {
|
||||
|
||||
watch(() => props.refreshKey, () => {
|
||||
if (!props.open) return
|
||||
fetchGen += 1
|
||||
void fetchLibrary(true)
|
||||
})
|
||||
|
||||
watch(() => (props.hiddenIds || []).join('\n'), () => {
|
||||
const drop = new Set(props.hiddenIds || [])
|
||||
if (!drop.size) return
|
||||
stills.value = stills.value.filter(item => !drop.has(item.id))
|
||||
clips.value = clips.value.filter(item => !drop.has(item.id))
|
||||
tracks.value = tracks.value.filter(item => !drop.has(item.id))
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (import.meta.client) {
|
||||
document.body.style.overflow = ''
|
||||
|
||||
Reference in New Issue
Block a user