Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 1,060 Bytes
eb29a95 17aecfb 98b0aa6 b34e9b1 1c0590e b34e9b1 17aecfb eb29a95 17aecfb 1c0590e 17aecfb b1a4d81 eb29a95 b1a4d81 b34e9b1 98b0aa6 17aecfb 98b0aa6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
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
})
}
|