Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
/** @type {import('./$types').RequestHandler} */ | |
import { json, type RequestEvent } from '@sveltejs/kit'; | |
import prisma from '$lib/prisma'; | |
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 | |
}) | |
} | |