import { error, json, type RequestEvent } from '@sveltejs/kit'; import prisma from '$lib/prisma'; /** @type {import('./$types').RequestHandler} */ // TODO // run hooks to update each model by repo using hugging face api. // refer to bulk-create-models +server.ts for example export async function GET(request : RequestEvent) { const page = parseInt(request.url.searchParams.get('page') || '0') const filter = request.url.searchParams.get('filter') || 'hotest' const search = request.url.searchParams.get('search') || '' const cards = await prisma.model.findMany({ where: { isPublic: true, OR: [ { title: { contains: search } }, { repo: { contains: search } }, ] }, orderBy: { ...(filter === 'hotest' ? { downloads: 'desc' } : { likes: 'desc' }) }, skip: 20 * page, take: 20, }) const total_reposId = await prisma.model.count({ where: { isPublic: true, OR: [ { title: { contains: search } }, { repo: { contains: search } }, ] }, }) const hasError = false if (hasError) { return error(500, 'Internal Server Error') } return json({ cards, total_items: total_reposId }) }