File size: 700 Bytes
309cbbe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b628664
309cbbe
 
 
 
 
 
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
import { json, type RequestEvent } from '@sveltejs/kit';
import { promises } from 'fs';

import prisma from '$lib/prisma';

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

export async function GET({ params } : RequestEvent) {
  const id = params.id;
  const gallery = await prisma.gallery.findFirst({
    where: {
      image: id,
    },
    select: {
      image: true,
    }
  })

  if (!gallery) {
    return json({
      error: {
        token: "Gallery not found"
      }
    }, { status: 404 })
  }

  const file = await promises.readFile(`${process.env.PUBLIC_FILE_UPLOAD_DIR}/${gallery.image}`)
  return new Response(file, {
    headers: {
      'Content-Type': 'image/png',
    },
  })
}