import { publicLibrary, publicLibraryPage } from '~/server/utils/library' export default defineEventHandler((event) => { const query = getQuery(event) const light = String(query.light || '') === '1' const limitRaw = query.limit const wantsPage = limitRaw != null && String(limitRaw) !== '' if (wantsPage) { const page = publicLibraryPage(event, { limit: Number(limitRaw) || 50, cursor: String(query.cursor || ''), folderId: String(query.folderId || query.folder || ''), type: String(query.type || query.filter || 'all') }) try { const { owner } = assertLibraryOwner(event) const folderId = page.folders.find(folder => folder.unlocked)?.id void maintainLibrary(owner, folderId).catch(() => null) } catch { /* locked or anonymous */ } return page } const library = publicLibrary(event, { light }) try { const { owner } = assertLibraryOwner(event) const folderId = library.folders.find(folder => folder.unlocked)?.id void maintainLibrary(owner, folderId).catch(() => null) } catch { /* locked or anonymous — still return what we can */ } return library })