Add folder wipe and drop broken still tiles from the library.

Delete all in this folder removes every still, clip, and track with files; list builders prune missing masters; select-all and delete no longer resurrect suppressed ids from later pages.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Towsty
2026-10-12 13:34:31 -05:00
co-authored by Cursor
parent 97c7547da9
commit 4b22c95b4b
4 changed files with 398 additions and 31 deletions
+164 -5
View File
@@ -40,6 +40,13 @@
class="lib-modal-preview-all"
@click="$emit('toggle-preview')"
>{{ previewHidden ? 'Show all previews' : 'Hide all previews' }}</button>
<button
v-if="canWipeFolder"
type="button"
class="lib-modal-wipe"
:disabled="wipeBusy"
@click="askWipeFolder"
>Delete all in this folder</button>
<div class="lib-modal-filters" role="group" aria-label="Type">
<button
v-for="opt in filterOptions"
@@ -51,6 +58,23 @@
>{{ opt.label }}</button>
</div>
</div>
<div
v-if="pendingWipe"
class="lib-modal-confirm"
role="dialog"
aria-modal="true"
>
<div class="lib-modal-confirm-card">
<h3>Delete all in this folder?</h3>
<p class="lib-modal-confirm-name">{{ pendingWipe.name }}</p>
<p class="lib-modal-confirm-detail">{{ pendingWipe.count }} item{{ pendingWipe.count === 1 ? '' : 's' }} · images, videos, and music</p>
<p class="lib-modal-confirm-body">Every still, clip, and track in this folder will be permanently removed from the library and disk.</p>
<div class="lib-modal-confirm-actions">
<button type="button" @click="pendingWipe = null">Keep them</button>
<button type="button" class="danger" :disabled="wipeBusy" @click="confirmWipeFolder">Delete all</button>
</div>
</div>
</div>
<div class="lib-modal-body">
<div ref="gridScrollEl" class="lib-modal-grid" aria-label="Folder assets">
<p v-if="loading && !entries.length" class="lib-modal-empty">Loading library…</p>
@@ -174,10 +198,22 @@ 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 wipeBusy = ref(false)
const pendingWipe = ref<{ folderId: string; name: string; count: number } | null>(null)
let thumbObserver: IntersectionObserver | null = null
let scrollLoadBound = false
const activeFolderId = computed(() => props.folderId || folders.value[0]?.id || 'all')
const activeFolder = computed(() => folders.value.find(folder => folder.id === activeFolderId.value) || null)
const folderAssetCount = computed(() => {
const id = activeFolderId.value
if (!id || id === 'all') return 0
return stills.value.filter(item => item.folderId === id).length
+ clips.value.filter(item => item.folderId === id).length
+ tracks.value.filter(item => item.folderId === id).length
})
const canWipeFolder = computed(() => Boolean(activeFolder.value && activeFolderId.value !== 'all' && folderAssetCount.value > 0))
const entries = computed(() => buildLibraryEntries({
clips: clips.value,
@@ -252,6 +288,9 @@ function useAndClose() {
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)
@@ -266,17 +305,25 @@ function onDeleteClick() {
}
function mergeIds(prev: { id: string }[], next: { id: string }[]) {
const map = new Map(prev.map(item => [item.id, item]))
for (const item of next) map.set(item.id, item)
const drop = suppressedDeletedIds.value
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 = suppressedDeletedIds.value
const keep = <T extends { id: string }>(list: T[]) => list.filter(item => !drop.has(item.id))
if (replace) {
clips.value = data?.clips || []
stills.value = data?.stills || []
tracks.value = data?.tracks || []
clips.value = keep(data?.clips || []) as LibraryClip[]
stills.value = keep(data?.stills || []) as LibraryStill[]
tracks.value = keep(data?.tracks || []) as LibraryTrack[]
} else {
clips.value = mergeIds(clips.value, data?.clips || []) as LibraryClip[]
stills.value = mergeIds(stills.value, data?.stills || []) as LibraryStill[]
@@ -286,6 +333,45 @@ function applyLibraryPage(data: any, replace: boolean) {
fetchedAt.value = Date.now()
}
function askWipeFolder() {
if (!activeFolder.value || activeFolderId.value === 'all' || wipeBusy.value) return
const count = folderAssetCount.value
if (!count) return
pendingWipe.value = {
folderId: activeFolderId.value,
name: activeFolder.value.name,
count
}
}
async function confirmWipeFolder() {
const pending = pendingWipe.value
if (!pending || wipeBusy.value) return
pendingWipe.value = null
wipeBusy.value = true
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)
await fetchLibrary(true)
} catch (e: any) {
loadError.value = e?.data?.statusMessage || e?.message || 'Could not empty that folder'
await fetchLibrary(true)
} finally {
wipeBusy.value = false
}
}
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'
@@ -411,6 +497,8 @@ watch(entries, () => nextTick(() => observeThumbs()))
watch([filter, activeFolderId], () => {
if (!props.open) return
suppressedDeletedIds.value = new Set()
pendingWipe.value = null
void fetchLibrary(true)
})
@@ -534,6 +622,77 @@ onBeforeUnmount(() => {
border-color: #f5a524;
color: #f5a524;
}
.lib-modal-wipe {
border: 1px solid #5c2a2a;
border-radius: 8px;
background: transparent;
color: #f0a0a0;
padding: 8px 10px;
font: inherit;
font-size: 12px;
cursor: pointer;
white-space: nowrap;
}
.lib-modal-wipe:hover:not(:disabled) {
border-color: #e07070;
color: #ffc0c0;
}
.lib-modal-wipe:disabled { opacity: 0.5; cursor: default; }
.lib-modal-confirm {
position: absolute;
inset: 0;
z-index: 5;
display: flex;
align-items: center;
justify-content: center;
background: #000a;
padding: 16px;
}
.lib-modal-confirm-card {
width: min(420px, 100%);
border: 1px solid #2a2a2e;
border-radius: 12px;
background: #1a1a1e;
padding: 18px;
}
.lib-modal-confirm-card h3 {
margin: 0;
font-size: 18px;
}
.lib-modal-confirm-name {
margin: 10px 0 0;
font-weight: 600;
}
.lib-modal-confirm-detail {
margin: 4px 0 0;
font-size: 12px;
color: #9a9588;
}
.lib-modal-confirm-body {
margin: 12px 0 0;
font-size: 13px;
color: #c8c4b8;
}
.lib-modal-confirm-actions {
display: flex;
justify-content: flex-end;
gap: 8px;
margin-top: 16px;
}
.lib-modal-confirm-actions button {
border: 1px solid #2a2a2e;
border-radius: 999px;
background: transparent;
color: inherit;
padding: 8px 14px;
font: inherit;
font-size: 13px;
cursor: pointer;
}
.lib-modal-confirm-actions button.danger {
border-color: #5c2a2a;
color: #f0a0a0;
}
.lib-modal-filters { display: inline-flex; gap: 4px; }
.lib-modal-chip {
border: 1px solid #2a2a2e;