Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
File size: 1,171 Bytes
eb29a95 97ec6f2 c479a59 eb29a95 404baa5 eb29a95 0d2d95b eb29a95 c479a59 eb29a95 7398577 eb29a95 c479a59 a084673 eb29a95 a084673 97ec6f2 |
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 43 44 45 46 47 48 49 50 51 52 53 54 |
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') || 'new'
const search = request.url.searchParams.get('search') || ''
const limit = parseInt(request.url.searchParams.get('limit') || '20')
const cards = await prisma.gallery.findMany({
where: {
OR: [
{ prompt: { contains: search } },
],
isPublic: true
},
orderBy: {
...(filter === 'new' ? {
createdAt: 'desc'
} : {
reactions: {
_count: 'desc'
}
}
)
},
select: {
reactions: true,
id: true,
prompt: true,
image: true,
model: true,
},
skip: limit * page,
take: limit,
})
const total_reposId = await prisma.gallery.count({
where: {
isPublic: true,
OR: [
{ prompt: { contains: search } },
]
},
})
return json({
cards,
total_items: total_reposId
})
}
|