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:
@@ -40,6 +40,13 @@
|
|||||||
class="lib-modal-preview-all"
|
class="lib-modal-preview-all"
|
||||||
@click="$emit('toggle-preview')"
|
@click="$emit('toggle-preview')"
|
||||||
>{{ previewHidden ? 'Show all previews' : 'Hide all previews' }}</button>
|
>{{ 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">
|
<div class="lib-modal-filters" role="group" aria-label="Type">
|
||||||
<button
|
<button
|
||||||
v-for="opt in filterOptions"
|
v-for="opt in filterOptions"
|
||||||
@@ -51,6 +58,23 @@
|
|||||||
>{{ opt.label }}</button>
|
>{{ opt.label }}</button>
|
||||||
</div>
|
</div>
|
||||||
</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 class="lib-modal-body">
|
||||||
<div ref="gridScrollEl" class="lib-modal-grid" aria-label="Folder assets">
|
<div ref="gridScrollEl" class="lib-modal-grid" aria-label="Folder assets">
|
||||||
<p v-if="loading && !entries.length" class="lib-modal-empty">Loading library…</p>
|
<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 fetchedAt = ref(0)
|
||||||
const nextCursor = ref<string | null>(null)
|
const nextCursor = ref<string | null>(null)
|
||||||
const liveThumbs = ref(new Set<string>())
|
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 thumbObserver: IntersectionObserver | null = null
|
||||||
let scrollLoadBound = false
|
let scrollLoadBound = false
|
||||||
|
|
||||||
const activeFolderId = computed(() => props.folderId || folders.value[0]?.id || 'all')
|
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({
|
const entries = computed(() => buildLibraryEntries({
|
||||||
clips: clips.value,
|
clips: clips.value,
|
||||||
@@ -252,6 +288,9 @@ function useAndClose() {
|
|||||||
|
|
||||||
function removeLocalAsset(asset: any) {
|
function removeLocalAsset(asset: any) {
|
||||||
if (!asset?.id) return
|
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)
|
stills.value = stills.value.filter(s => s.id !== asset.id)
|
||||||
clips.value = clips.value.filter(c => c.id !== asset.id)
|
clips.value = clips.value.filter(c => c.id !== asset.id)
|
||||||
tracks.value = tracks.value.filter(t => t.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 }[]) {
|
function mergeIds(prev: { id: string }[], next: { id: string }[]) {
|
||||||
const map = new Map(prev.map(item => [item.id, item]))
|
const drop = suppressedDeletedIds.value
|
||||||
for (const item of next) map.set(item.id, item)
|
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()]
|
return [...map.values()]
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyLibraryPage(data: any, replace: boolean) {
|
function applyLibraryPage(data: any, replace: boolean) {
|
||||||
folders.value = data?.folders || folders.value
|
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) {
|
if (replace) {
|
||||||
clips.value = data?.clips || []
|
clips.value = keep(data?.clips || []) as LibraryClip[]
|
||||||
stills.value = data?.stills || []
|
stills.value = keep(data?.stills || []) as LibraryStill[]
|
||||||
tracks.value = data?.tracks || []
|
tracks.value = keep(data?.tracks || []) as LibraryTrack[]
|
||||||
} else {
|
} else {
|
||||||
clips.value = mergeIds(clips.value, data?.clips || []) as LibraryClip[]
|
clips.value = mergeIds(clips.value, data?.clips || []) as LibraryClip[]
|
||||||
stills.value = mergeIds(stills.value, data?.stills || []) as LibraryStill[]
|
stills.value = mergeIds(stills.value, data?.stills || []) as LibraryStill[]
|
||||||
@@ -286,6 +333,45 @@ function applyLibraryPage(data: any, replace: boolean) {
|
|||||||
fetchedAt.value = Date.now()
|
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) {
|
async function fetchLibraryPage(cursor: string | null) {
|
||||||
const folder = activeFolderId.value && activeFolderId.value !== 'all' ? activeFolderId.value : ''
|
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 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], () => {
|
watch([filter, activeFolderId], () => {
|
||||||
if (!props.open) return
|
if (!props.open) return
|
||||||
|
suppressedDeletedIds.value = new Set()
|
||||||
|
pendingWipe.value = null
|
||||||
void fetchLibrary(true)
|
void fetchLibrary(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -534,6 +622,77 @@ onBeforeUnmount(() => {
|
|||||||
border-color: #f5a524;
|
border-color: #f5a524;
|
||||||
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-filters { display: inline-flex; gap: 4px; }
|
||||||
.lib-modal-chip {
|
.lib-modal-chip {
|
||||||
border: 1px solid #2a2a2e;
|
border: 1px solid #2a2a2e;
|
||||||
|
|||||||
+157
-23
@@ -87,8 +87,8 @@
|
|||||||
>
|
>
|
||||||
{{ selectMode ? 'Done selecting' : 'Select' }}
|
{{ selectMode ? 'Done selecting' : 'Select' }}
|
||||||
</button>
|
</button>
|
||||||
<button v-if="entries.length" type="button" class="text-zinc-400 hover:text-white" @click="selectedKeys.length === entries.length ? clearSelection() : selectAll()">
|
<button v-if="entries.length || folderWipeCount > 0" type="button" class="text-zinc-400 hover:text-white" @click="selectedKeys.length && selectedKeys.length === entries.length && !libraryLoading ? clearSelection() : selectAll()">
|
||||||
{{ selectedKeys.length && selectedKeys.length === entries.length ? 'Clear selection' : 'Select all' }}
|
{{ selectedKeys.length && selectedKeys.length === entries.length && !libraryLoading ? 'Clear selection' : 'Select all' }}
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
v-if="showPrivacyToggles && entries.length"
|
v-if="showPrivacyToggles && entries.length"
|
||||||
@@ -109,6 +109,13 @@
|
|||||||
{{ revealAll ? 'Hide all' : 'Reveal all' }}
|
{{ revealAll ? 'Hide all' : 'Reveal all' }}
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
|
<button
|
||||||
|
v-if="browseFolder && folderId !== 'all' && (entries.length || folderWipeCount > 0)"
|
||||||
|
type="button"
|
||||||
|
class="text-red-300 hover:text-red-200"
|
||||||
|
:disabled="deleteBusy || wipeBusy"
|
||||||
|
@click="askWipeFolder"
|
||||||
|
>Delete all in this folder</button>
|
||||||
<button v-if="browseFolder?.protected && browseFolder.unlocked" type="button" class="text-zinc-400 hover:text-white" @click="lockFolder">Lock folder</button>
|
<button v-if="browseFolder?.protected && browseFolder.unlocked" type="button" class="text-zinc-400 hover:text-white" @click="lockFolder">Lock folder</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -488,6 +495,31 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div
|
||||||
|
v-if="pendingWipe"
|
||||||
|
class="fixed inset-0 z-[70] flex items-center justify-center bg-black/70 p-4"
|
||||||
|
role="dialog"
|
||||||
|
aria-modal="true"
|
||||||
|
@click.self="pendingWipe = null"
|
||||||
|
>
|
||||||
|
<div class="glass w-full max-w-md rounded-3xl p-5 sm:p-6">
|
||||||
|
<h2 class="font-display text-xl font-bold">Delete all in this folder?</h2>
|
||||||
|
<p class="mt-2 text-sm font-medium text-zinc-100">{{ pendingWipe.name }}</p>
|
||||||
|
<p class="mt-1 text-xs text-zinc-500">{{ pendingWipe.count }} item{{ pendingWipe.count === 1 ? '' : 's' }} · images, videos, and music</p>
|
||||||
|
<p class="mt-3 text-sm text-zinc-400">Every still, clip, and track in this folder will be permanently removed from the library and disk.</p>
|
||||||
|
<div class="mt-5 flex flex-wrap justify-end gap-2">
|
||||||
|
<button type="button" class="rounded-full border border-white/15 px-4 py-2 text-sm text-zinc-300" @click="pendingWipe = null">Keep them</button>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="rounded-full border border-red-400/40 bg-red-400/10 px-4 py-2 text-sm font-semibold text-red-200 disabled:opacity-50"
|
||||||
|
:disabled="wipeBusy"
|
||||||
|
@click="confirmWipeFolder"
|
||||||
|
>
|
||||||
|
Delete all
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</Teleport>
|
</Teleport>
|
||||||
|
|
||||||
<div class="pointer-events-none fixed bottom-4 right-4 z-50 space-y-2">
|
<div class="pointer-events-none fixed bottom-4 right-4 z-50 space-y-2">
|
||||||
@@ -601,6 +633,10 @@ const revealAll = ref(false)
|
|||||||
const hidingFocused = ref(false)
|
const hidingFocused = ref(false)
|
||||||
const forceHiddenIds = ref<string[]>([])
|
const forceHiddenIds = ref<string[]>([])
|
||||||
const pendingDelete = ref<{ title: string; name: string; detail?: string; consequence: string; keys: string[] } | null>(null)
|
const pendingDelete = ref<{ title: string; name: string; detail?: string; consequence: string; keys: string[] } | null>(null)
|
||||||
|
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 keepingInputBusy = ref(false)
|
const keepingInputBusy = ref(false)
|
||||||
const toasts = ref<Array<{ id: number; message: string }>>([])
|
const toasts = ref<Array<{ id: number; message: string }>>([])
|
||||||
let toastId = 0
|
let toastId = 0
|
||||||
@@ -613,6 +649,13 @@ const viewportW = ref(800)
|
|||||||
|
|
||||||
const selectedSet = computed(() => new Set(selectedKeys.value))
|
const selectedSet = computed(() => new Set(selectedKeys.value))
|
||||||
const browseFolder = computed(() => folders.value.find(folder => folder.id === folderId.value) || null)
|
const browseFolder = computed(() => folders.value.find(folder => folder.id === folderId.value) || null)
|
||||||
|
const folderWipeCount = computed(() => {
|
||||||
|
if (!browseFolder.value || folderId.value === 'all') return 0
|
||||||
|
const id = folderId.value
|
||||||
|
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 entries = computed(() => buildLibraryEntries({
|
const entries = computed(() => buildLibraryEntries({
|
||||||
clips: clips.value,
|
clips: clips.value,
|
||||||
stills: stills.value,
|
stills: stills.value,
|
||||||
@@ -778,15 +821,21 @@ function applyLibrary(data: unknown, opts?: { replace?: boolean }) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if (payload.folders?.length) folders.value = payload.folders
|
if (payload.folders?.length) folders.value = payload.folders
|
||||||
|
const drop = suppressedDeletedIds.value
|
||||||
|
const keep = <T extends { id: string }>(list: T[]) => list.filter(item => !drop.has(item.id))
|
||||||
if (replace) {
|
if (replace) {
|
||||||
clips.value = payload.clips || []
|
clips.value = keep(payload.clips || [])
|
||||||
stills.value = payload.stills || []
|
stills.value = keep(payload.stills || [])
|
||||||
tracks.value = payload.tracks || []
|
tracks.value = keep(payload.tracks || [])
|
||||||
} else {
|
} else {
|
||||||
const merge = <T extends { id: string }>(prev: T[], next: T[]) => {
|
const merge = <T extends { id: string }>(prev: T[], next: T[]) => {
|
||||||
const map = new Map<string, T>()
|
const map = new Map<string, T>()
|
||||||
for (const item of prev) map.set(item.id, item)
|
for (const item of prev) {
|
||||||
for (const item of next) map.set(item.id, item)
|
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()]
|
return [...map.values()]
|
||||||
}
|
}
|
||||||
clips.value = merge(clips.value, payload.clips || [])
|
clips.value = merge(clips.value, payload.clips || [])
|
||||||
@@ -815,18 +864,37 @@ async function fetchLibraryPage(cursor: string | null) {
|
|||||||
async function loadLibrary() {
|
async function loadLibrary() {
|
||||||
// First page paints immediately; remaining pages append in the background
|
// First page paints immediately; remaining pages append in the background
|
||||||
const gen = ++libraryFetchGen
|
const gen = ++libraryFetchGen
|
||||||
const first = await fetchLibraryPage(null)
|
libraryLoading.value = true
|
||||||
if (gen !== libraryFetchGen) return
|
try {
|
||||||
applyLibrary(first, { replace: true })
|
const first = await fetchLibraryPage(null)
|
||||||
let cursor = first?.nextCursor || null
|
|
||||||
while (cursor && gen === libraryFetchGen) {
|
|
||||||
const page = await fetchLibraryPage(cursor)
|
|
||||||
if (gen !== libraryFetchGen) return
|
if (gen !== libraryFetchGen) return
|
||||||
applyLibrary(page, { replace: false })
|
applyLibrary(first, { replace: true })
|
||||||
cursor = page?.nextCursor || null
|
let cursor = first?.nextCursor || null
|
||||||
|
while (cursor && gen === libraryFetchGen) {
|
||||||
|
const page = await fetchLibraryPage(cursor)
|
||||||
|
if (gen !== libraryFetchGen) return
|
||||||
|
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)))
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (gen === libraryFetchGen) libraryLoading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function ensureLibraryFullyLoaded() {
|
||||||
|
if (!libraryLoading.value && !libraryNextCursor.value) return
|
||||||
|
await loadLibrary()
|
||||||
|
}
|
||||||
|
|
||||||
function folderChipCount(folder: LibraryFolder) {
|
function folderChipCount(folder: LibraryFolder) {
|
||||||
// Prefer server totals so chips match the full folder before pages finish appending
|
// Prefer server totals so chips match the full folder before pages finish appending
|
||||||
if (filter.value === 'videos') return folder.clipCount || 0
|
if (filter.value === 'videos') return folder.clipCount || 0
|
||||||
@@ -975,7 +1043,9 @@ function toggleSelectMode() {
|
|||||||
if (selectMode.value) clearFocus()
|
if (selectMode.value) clearFocus()
|
||||||
}
|
}
|
||||||
|
|
||||||
function selectAll() {
|
async function selectAll() {
|
||||||
|
// Whole folder — not only the page already painted
|
||||||
|
await ensureLibraryFullyLoaded()
|
||||||
selectedKeys.value = entries.value.map(entry => entry.key)
|
selectedKeys.value = entries.value.map(entry => entry.key)
|
||||||
lastSelectedKey.value = selectedKeys.value.at(-1) || ''
|
lastSelectedKey.value = selectedKeys.value.at(-1) || ''
|
||||||
}
|
}
|
||||||
@@ -1217,6 +1287,16 @@ function askRemoveKeys(keys: string[]) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function markDeletedIds(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))
|
||||||
|
}
|
||||||
|
|
||||||
async function confirmDelete() {
|
async function confirmDelete() {
|
||||||
const pending = pendingDelete.value
|
const pending = pendingDelete.value
|
||||||
if (!pending || deleteBusy.value) return
|
if (!pending || deleteBusy.value) return
|
||||||
@@ -1224,6 +1304,22 @@ async function confirmDelete() {
|
|||||||
deleteBusy.value = true
|
deleteBusy.value = true
|
||||||
try {
|
try {
|
||||||
const items = selectedEntries(pending.keys)
|
const items = selectedEntries(pending.keys)
|
||||||
|
const gone: string[] = []
|
||||||
|
for (const entry of items) {
|
||||||
|
if (entry.kind === 'clip' && entry.group) {
|
||||||
|
for (const part of entry.group.parts || [entry.group.head]) gone.push(part.id)
|
||||||
|
} else if (entry.kind === 'track' && entry.track) {
|
||||||
|
gone.push(entry.track.id)
|
||||||
|
} else if (entry.stillGroup) {
|
||||||
|
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) => {
|
await Promise.allSettled(items.map((entry) => {
|
||||||
if (entry.kind === 'clip') {
|
if (entry.kind === 'clip') {
|
||||||
return $fetch(`/api/library/clips/${entry.group!.head.id}`, { method: 'DELETE', query: { family: '1' } })
|
return $fetch(`/api/library/clips/${entry.group!.head.id}`, { method: 'DELETE', query: { family: '1' } })
|
||||||
@@ -1233,17 +1329,53 @@ async function confirmDelete() {
|
|||||||
}
|
}
|
||||||
return $fetch(`/api/library/stills/${entry.stillGroup!.head.id}`, { method: 'DELETE', query: { family: '1' } })
|
return $fetch(`/api/library/stills/${entry.stillGroup!.head.id}`, { method: 'DELETE', query: { family: '1' } })
|
||||||
}))
|
}))
|
||||||
if (pending.keys.includes(focusedKey.value)) {
|
|
||||||
focusedKey.value = ''
|
|
||||||
focusedPartId.value = ''
|
|
||||||
}
|
|
||||||
clearSelection()
|
|
||||||
await loadLibrary()
|
await loadLibrary()
|
||||||
} finally {
|
} finally {
|
||||||
deleteBusy.value = false
|
deleteBusy.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function askWipeFolder() {
|
||||||
|
if (!browseFolder.value || folderId.value === 'all' || wipeBusy.value) return
|
||||||
|
await ensureLibraryFullyLoaded()
|
||||||
|
const count = folderWipeCount.value
|
||||||
|
if (!count) {
|
||||||
|
toast('This folder is already empty.')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
pendingWipe.value = {
|
||||||
|
folderId: folderId.value,
|
||||||
|
name: browseFolder.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)
|
||||||
|
]
|
||||||
|
markDeletedIds(gone)
|
||||||
|
clearSelection()
|
||||||
|
clearFocus()
|
||||||
|
const result = await $fetch<any>(`/api/library/folders/${pending.folderId}/wipe`, { method: 'POST' })
|
||||||
|
applyLibrary(result, { replace: true })
|
||||||
|
toast(`Deleted ${result.deleted ?? pending.count} from ${pending.name}.`)
|
||||||
|
await loadLibrary()
|
||||||
|
} catch (error: any) {
|
||||||
|
toast(error?.data?.statusMessage || 'Could not empty that folder')
|
||||||
|
await loadLibrary()
|
||||||
|
} finally {
|
||||||
|
wipeBusy.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function unlockFolder() {
|
async function unlockFolder() {
|
||||||
if (!browseFolder.value) return
|
if (!browseFolder.value) return
|
||||||
try {
|
try {
|
||||||
@@ -1267,7 +1399,8 @@ function onKey(event: KeyboardEvent) {
|
|||||||
const target = event.target as HTMLElement | null
|
const target = event.target as HTMLElement | null
|
||||||
const typing = Boolean(target && (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.tagName === 'SELECT' || target.isContentEditable))
|
const typing = Boolean(target && (target.tagName === 'INPUT' || target.tagName === 'TEXTAREA' || target.tagName === 'SELECT' || target.isContentEditable))
|
||||||
if (event.key === 'Escape') {
|
if (event.key === 'Escape') {
|
||||||
if (pendingDelete.value) pendingDelete.value = null
|
if (pendingWipe.value) pendingWipe.value = null
|
||||||
|
else if (pendingDelete.value) pendingDelete.value = null
|
||||||
else if (lightboxOpen.value) lightboxOpen.value = false
|
else if (lightboxOpen.value) lightboxOpen.value = false
|
||||||
else if (renaming.value) cancelRename()
|
else if (renaming.value) cancelRename()
|
||||||
else if (focusedKey.value) clearFocus()
|
else if (focusedKey.value) clearFocus()
|
||||||
@@ -1276,7 +1409,7 @@ function onKey(event: KeyboardEvent) {
|
|||||||
}
|
}
|
||||||
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 'a' && !renaming.value) {
|
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 'a' && !renaming.value) {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
selectAll()
|
void selectAll()
|
||||||
}
|
}
|
||||||
if (event.key === 'Delete' && selectedKeys.value.length && !renaming.value) askRemoveSelected()
|
if (event.key === 'Delete' && selectedKeys.value.length && !renaming.value) askRemoveSelected()
|
||||||
if (!typing && (event.key === 'ArrowLeft' || event.key === 'ArrowRight') && focusedNavParts.value.length > 1) {
|
if (!typing && (event.key === 'ArrowLeft' || event.key === 'ArrowRight') && focusedNavParts.value.length > 1) {
|
||||||
@@ -1293,6 +1426,7 @@ watch(searchDraft, (value) => {
|
|||||||
})
|
})
|
||||||
watch([folderId, filter], () => {
|
watch([folderId, filter], () => {
|
||||||
clearSelection()
|
clearSelection()
|
||||||
|
suppressedDeletedIds.value = new Set()
|
||||||
if (scroller.value) scroller.value.scrollTop = 0
|
if (scroller.value) scroller.value.scrollTop = 0
|
||||||
})
|
})
|
||||||
watch(search, () => {
|
watch(search, () => {
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const { owner } = assertLibraryOwner(event)
|
||||||
|
const id = String(getRouterParam(event, 'id') || '')
|
||||||
|
assertFolderAccess(event, id)
|
||||||
|
const result = await wipeFolderContents(owner, id)
|
||||||
|
return { ...result, ...publicLibrary(event, { light: true }) }
|
||||||
|
})
|
||||||
+70
-3
@@ -587,7 +587,7 @@ export function publicFolder(event: H3Event, folder: LibraryFolder, clipCount =
|
|||||||
export function publicLibrary(event: H3Event, opts?: { light?: boolean }) {
|
export function publicLibrary(event: H3Event, opts?: { light?: boolean }) {
|
||||||
const light = opts?.light === true
|
const light = opts?.light === true
|
||||||
const owner = libraryOwnerKey(event)
|
const owner = libraryOwnerKey(event)
|
||||||
const catalog = readCatalog(owner)
|
const catalog = catalogWithPrunedStills(owner)
|
||||||
const clipIds = new Set(catalog.clips.map(clip => clip.id.toLowerCase()))
|
const clipIds = new Set(catalog.clips.map(clip => clip.id.toLowerCase()))
|
||||||
const clipCounts = new Map<string, number>()
|
const clipCounts = new Map<string, number>()
|
||||||
const imageCounts = new Map<string, number>()
|
const imageCounts = new Map<string, number>()
|
||||||
@@ -634,7 +634,7 @@ export function publicLibrary(event: H3Event, opts?: { light?: boolean }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Paginated metadata page — reads catalog rows only; no existsSync / full publicLibrary map. */
|
/** Paginated metadata page. Prunes stills whose master file is missing before listing. */
|
||||||
export function publicLibraryPage(
|
export function publicLibraryPage(
|
||||||
event: H3Event,
|
event: H3Event,
|
||||||
opts: { limit?: number; cursor?: string; folderId?: string; type?: string } = {}
|
opts: { limit?: number; cursor?: string; folderId?: string; type?: string } = {}
|
||||||
@@ -644,7 +644,7 @@ export function publicLibraryPage(
|
|||||||
const folderId = String(opts.folderId || '')
|
const folderId = String(opts.folderId || '')
|
||||||
const typeFilter = String(opts.type || 'all')
|
const typeFilter = String(opts.type || 'all')
|
||||||
const owner = libraryOwnerKey(event)
|
const owner = libraryOwnerKey(event)
|
||||||
const catalog = readCatalog(owner)
|
const catalog = catalogWithPrunedStills(owner)
|
||||||
const clipIds = new Set(catalog.clips.map(clip => clip.id.toLowerCase()))
|
const clipIds = new Set(catalog.clips.map(clip => clip.id.toLowerCase()))
|
||||||
const clipCounts = new Map<string, number>()
|
const clipCounts = new Map<string, number>()
|
||||||
const imageCounts = new Map<string, number>()
|
const imageCounts = new Map<string, number>()
|
||||||
@@ -876,6 +876,73 @@ export function deleteFolder(owner: string, id: string) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Delete every still, clip, and track in a folder — catalog rows and on-disk files. Keeps the folder. */
|
||||||
|
export function wipeFolderContents(owner: string, folderId: string) {
|
||||||
|
return mutate(owner, (catalog) => {
|
||||||
|
const folder = catalog.folders.find(item => item.id === folderId)
|
||||||
|
if (!folder) throw createError({ statusCode: 404, statusMessage: 'Folder not found' })
|
||||||
|
const clips = catalog.clips.filter(clip => clip.folderId === folderId)
|
||||||
|
const stills = catalog.stills.filter(still => still.folderId === folderId)
|
||||||
|
const tracks = (catalog.tracks || []).filter(track => track.folderId === folderId)
|
||||||
|
const deletedIds = new Set([
|
||||||
|
...clips.map(item => item.id),
|
||||||
|
...stills.map(item => item.id),
|
||||||
|
...tracks.map(item => item.id)
|
||||||
|
])
|
||||||
|
catalog.clips = catalog.clips.filter(clip => clip.folderId !== folderId)
|
||||||
|
catalog.stills = catalog.stills.filter(still => still.folderId !== folderId)
|
||||||
|
catalog.tracks = (catalog.tracks || []).filter(track => track.folderId !== folderId)
|
||||||
|
catalog.drafts = (catalog.drafts || []).map((draft) => {
|
||||||
|
if (!draft.stillId || !deletedIds.has(draft.stillId)) return draft
|
||||||
|
return { ...draft, stillId: undefined, stillFilename: undefined }
|
||||||
|
})
|
||||||
|
for (const clip of clips) {
|
||||||
|
rmSync(clipDir(owner, clip.id), { recursive: true, force: true })
|
||||||
|
}
|
||||||
|
for (const still of stills) {
|
||||||
|
removeStillFiles(owner, still.id)
|
||||||
|
}
|
||||||
|
for (const track of tracks) {
|
||||||
|
rmSync(trackDir(owner, track.id), { recursive: true, force: true })
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
folderId: folder.id,
|
||||||
|
folderName: folder.name,
|
||||||
|
deleted: clips.length + stills.length + tracks.length,
|
||||||
|
stills: stills.length,
|
||||||
|
clips: clips.length,
|
||||||
|
tracks: tracks.length
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Drop catalog stills whose master file is gone — a 204 thumb is not a still. */
|
||||||
|
function pruneMissingStillMasters(owner: string, catalog: Catalog) {
|
||||||
|
const keep: LibraryStill[] = []
|
||||||
|
const droppedIds = new Set<string>()
|
||||||
|
for (const still of catalog.stills) {
|
||||||
|
if (existsSync(stillPath(owner, still.id))) {
|
||||||
|
keep.push(still)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
droppedIds.add(still.id)
|
||||||
|
removeStillFiles(owner, still.id)
|
||||||
|
}
|
||||||
|
if (!droppedIds.size) return 0
|
||||||
|
catalog.stills = keep
|
||||||
|
catalog.drafts = (catalog.drafts || []).map((draft) => {
|
||||||
|
if (!draft.stillId || !droppedIds.has(draft.stillId)) return draft
|
||||||
|
return { ...draft, stillId: undefined, stillFilename: undefined }
|
||||||
|
})
|
||||||
|
return droppedIds.size
|
||||||
|
}
|
||||||
|
|
||||||
|
function catalogWithPrunedStills(owner: string): Catalog {
|
||||||
|
const catalog = readCatalog(owner)
|
||||||
|
if (pruneMissingStillMasters(owner, catalog)) writeCatalog(owner, catalog)
|
||||||
|
return catalog
|
||||||
|
}
|
||||||
|
|
||||||
export async function updateFolder(owner: string, id: string, patch: {
|
export async function updateFolder(owner: string, id: string, patch: {
|
||||||
name?: string
|
name?: string
|
||||||
thumbnailDefault?: boolean
|
thumbnailDefault?: boolean
|
||||||
|
|||||||
Reference in New Issue
Block a user