File size: 1,452 Bytes
1c0590e
 
 
 
 
d6da254
 
 
 
1c0590e
 
 
d6da254
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1c0590e
 
 
 
 
 
 
 
 
 
d6da254
 
 
 
 
 
 
 
 
 
1c0590e
d6da254
 
1c0590e
 
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
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,
          }
        },
        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
  })
}