File size: 1,004 Bytes
7b25d55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
615c1b6
7b25d55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
615c1b6
7b25d55
 
 
 
 
 
 
 
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
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
  })
}