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:
@@ -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 }) {
|
||||
const light = opts?.light === true
|
||||
const owner = libraryOwnerKey(event)
|
||||
const catalog = readCatalog(owner)
|
||||
const catalog = catalogWithPrunedStills(owner)
|
||||
const clipIds = new Set(catalog.clips.map(clip => clip.id.toLowerCase()))
|
||||
const clipCounts = 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(
|
||||
event: H3Event,
|
||||
opts: { limit?: number; cursor?: string; folderId?: string; type?: string } = {}
|
||||
@@ -644,7 +644,7 @@ export function publicLibraryPage(
|
||||
const folderId = String(opts.folderId || '')
|
||||
const typeFilter = String(opts.type || 'all')
|
||||
const owner = libraryOwnerKey(event)
|
||||
const catalog = readCatalog(owner)
|
||||
const catalog = catalogWithPrunedStills(owner)
|
||||
const clipIds = new Set(catalog.clips.map(clip => clip.id.toLowerCase()))
|
||||
const clipCounts = 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: {
|
||||
name?: string
|
||||
thumbnailDefault?: boolean
|
||||
|
||||
Reference in New Issue
Block a user