Spaces:
Running
Running
| import { json, type RequestEvent } from '@sveltejs/kit'; | |
| import prisma from '$lib/prisma'; | |
| import { tokenIsAvailable } from '$lib/utils'; | |
| /** @type {import('./$types').RequestHandler} */ | |
| export async function GET({ cookies } : RequestEvent) { | |
| const token = cookies.get('hf_access_token') | |
| if (!token) { | |
| return json({ | |
| error: { | |
| token: "You must be logged" | |
| } | |
| }, { status: 401 }) | |
| } | |
| const user = await tokenIsAvailable(token) | |
| if (!user) { | |
| return json({ | |
| error: { | |
| token: "Invalid token" | |
| } | |
| }, { status: 401 }) | |
| } | |
| const cards = await prisma.gallery.findMany({ | |
| where: { | |
| userId: user.sub | |
| }, | |
| orderBy: { | |
| createdAt: 'desc' | |
| }, | |
| select: { | |
| reactions: true, | |
| id: true, | |
| prompt: true, | |
| image: true, | |
| model: true, | |
| }, | |
| }) | |
| const total_reposId = await prisma.gallery.count({ | |
| where: { | |
| userId: user.sub | |
| }, | |
| }) | |
| return json({ | |
| cards, | |
| total_items: total_reposId | |
| }) | |
| } | |