Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
import { json, type RequestEvent } from '@sveltejs/kit'; | |
import prisma from '$lib/prisma'; | |
/** @type {import('./$types').RequestHandler} */ | |
export async function GET({ url, params } : RequestEvent) { | |
const id = params.id?.replace("@", "/") | |
// to Booelan | |
const full = Boolean(url.searchParams.get('full')) ?? false | |
const model = await prisma.model.findFirst({ | |
where: { | |
id, | |
}, | |
...(full && { | |
select: { | |
id: true, | |
likes: true, | |
downloads: true, | |
image: true, | |
title: true, | |
gallery: { | |
select: { | |
id: true, | |
prompt: true, | |
image: true, | |
createdAt: true, | |
}, | |
where: { | |
isPublic: true | |
} | |
}, | |
comments: { | |
select: { | |
id: true, | |
createdAt: true, | |
text: true, | |
user: { | |
select: { | |
id: true, | |
name: true, | |
sub: true, | |
picture: true, | |
preferred_username: true, | |
} | |
} | |
} | |
} | |
} | |
}) | |
}) | |
if (!model) { | |
return json({ | |
error: { | |
token: "Model params is required" | |
} | |
}, { status: 401 }) | |
} | |
// const gallery = await prisma.gallery.findMany({ | |
// where: { | |
// modelId: model.id | |
// }, | |
// orderBy: { | |
// createdAt: "desc" | |
// }, | |
// take: 5 | |
// }) | |
return json({ | |
model, | |
// gallery | |
}) | |
} | |