File size: 923 Bytes
7398577
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { json, type RequestEvent } from '@sveltejs/kit';
import { tokenIsAvailable } from '$lib/utils';
import prisma from '$lib/prisma';

/** @type {import('./$types').RequestHandler} */

export async function POST({ cookies, params } : RequestEvent) {
  const id = params.id

  const gallery = await prisma.gallery.findFirst({
    where: {
      id,
    },
  })
  if (!gallery) {
    return json({
      error: "Image not found",
    }, { status: 404 })
  }
  
  const token = cookies.get('hf_access_token')
  if (!token) {
    return json({
      error: "You must be logged",
    }, { status: 401 })
  }

  const is_token_available = await tokenIsAvailable(token)
  if (!is_token_available) {
    return json({
      error: "Invalid token",
    }, { status: 401 })
  }

  await prisma.gallery.update({
    where: {
      id,
    },
    data: {
      isPublic: true,
    }
  })

  return json({
    success: true,
  })
}