Spaces:
Running
Running
update api route
Browse files
src/routes/api/images/[id]/+server.ts
CHANGED
|
@@ -1,30 +1,10 @@
|
|
| 1 |
-
import {
|
| 2 |
import { promises } from 'fs';
|
| 3 |
|
| 4 |
-
import prisma from '$lib/prisma';
|
| 5 |
-
|
| 6 |
/** @type {import('./$types').RequestHandler} */
|
| 7 |
|
| 8 |
export async function GET({ params } : RequestEvent) {
|
| 9 |
-
const
|
| 10 |
-
const gallery = await prisma.gallery.findFirst({
|
| 11 |
-
where: {
|
| 12 |
-
image: id,
|
| 13 |
-
},
|
| 14 |
-
select: {
|
| 15 |
-
image: true,
|
| 16 |
-
}
|
| 17 |
-
})
|
| 18 |
-
|
| 19 |
-
if (!gallery) {
|
| 20 |
-
return json({
|
| 21 |
-
error: {
|
| 22 |
-
token: "Gallery not found"
|
| 23 |
-
}
|
| 24 |
-
}, { status: 404 })
|
| 25 |
-
}
|
| 26 |
-
|
| 27 |
-
const file = await promises.readFile(`${process.env.PUBLIC_FILE_UPLOAD_DIR}/${gallery.image}`)
|
| 28 |
return new Response(file, {
|
| 29 |
headers: {
|
| 30 |
'Content-Type': 'image/png',
|
|
|
|
| 1 |
+
import { type RequestEvent } from '@sveltejs/kit';
|
| 2 |
import { promises } from 'fs';
|
| 3 |
|
|
|
|
|
|
|
| 4 |
/** @type {import('./$types').RequestHandler} */
|
| 5 |
|
| 6 |
export async function GET({ params } : RequestEvent) {
|
| 7 |
+
const file = await promises.readFile(`${process.env.PUBLIC_FILE_UPLOAD_DIR}/${params.id}`)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
return new Response(file, {
|
| 9 |
headers: {
|
| 10 |
'Content-Type': 'image/png',
|