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', }, }) }