logigate/server/api/library/index.get.ts

10 lines
505 B
TypeScript
Raw Permalink Normal View History

// Everybody's published components, newest first. ?q= narrows them to the
// ones whose name, description, group or author has every word typed.
export default defineEventHandler(async event => {
const q = getQuery(event).q
const names = await playerNames()
const list = (await libraryIndex()).map(m => publicMeta(m, names))
setHeader(event, 'cache-control', 'no-store')
return { entries: searchLibrary(list, typeof q === 'string' ? q.slice(0, 100) : '').slice(0, 500), total: list.length }
})