The in-memory catalog could outlive the write, so delete-all came back as thousands of empty tiles and a stale badge. Co-authored-by: Cursor <cursoragent@cursor.com>
15 lines
770 B
TypeScript
15 lines
770 B
TypeScript
import { assertFolderAccess, assertLibraryOwner, invalidateCatalogCache, publicLibrary, publicLibraryPage, wipeFolderContents } from '~/server/utils/library'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const { owner } = assertLibraryOwner(event)
|
|
const id = String(getRouterParam(event, 'id') || '')
|
|
assertFolderAccess(event, id)
|
|
const result = await wipeFolderContents(owner, id)
|
|
// wipeFolderContents already drops the cache. Drop it again so this read
|
|
// cannot reuse a catalog object captured before the write.
|
|
invalidateCatalogCache(owner)
|
|
const library = publicLibrary(event, { light: true })
|
|
const page = publicLibraryPage(event, { folderId: id, limit: 50 })
|
|
return { ...result, ...library, page, folderId: result.folderId || id }
|
|
})
|