enzostvs's picture
enzostvs HF staff
refacto models + community
eb29a95
raw
history blame
1.06 kB
import { json, type RequestEvent } from '@sveltejs/kit';
import prisma from '$lib/prisma';
/** @type {import('./$types').RequestHandler} */
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 limit = parseInt(request.url.searchParams.get('limit') || '20')
const cards = await prisma.model.findMany({
where: {
isPublic: true,
OR: [
{ title: { contains: search } },
{ id: { contains: search } },
]
},
orderBy: {
...(filter === 'hotest' ? { downloads: 'desc' } : { likes: 'desc' })
},
skip: limit * page,
take: limit,
})
const total_reposId = await prisma.model.count({
where: {
isPublic: true,
OR: [
{ title: { contains: search } },
{ id: { contains: search } },
]
},
})
return json({
cards,
total_items: total_reposId
})
}