import { json, type RequestEvent } from '@sveltejs/kit'; import { env } from '$env/dynamic/private' 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, }, select: full ? { id: true, likes: true, downloads: true, image: true, title: true, instance_prompt: true, gallery: { select: { id: true, prompt: true, image: true, createdAt: true, }, where: { isPublic: true }, orderBy: { createdAt: 'desc' }, take: 10 }, comments: { select: { id: true, createdAt: true, text: true, user: { select: { id: true, name: true, sub: true, picture: true, preferred_username: true, } } } } } : { instance_prompt: true, image: true, title: true, id: true, } }) if (!model) { return json({ error: { token: "Model params is required" } }, { status: 401 }) } let infos: Record = {}; if (full) { const hf_model_request = await fetch(`https://huggingface.co/api/models/${id}`, { headers: { "Authorization": `Bearer ${env.SECRET_HF_TOKEN}` } }) const hf_model_response = await hf_model_request.json(); infos = { base_model: hf_model_response?.cardData?.base_model, license: hf_model_response?.cardData?.license, tags: hf_model_response?.cardData?.tags, } } return json({ model: { ...model, infos } }) }