enzostvs HF staff commited on
Commit
eeee9c4
·
1 Parent(s): b73edb4

error getting image

Browse files
src/routes/api/images/[id]/+server.ts CHANGED
@@ -4,10 +4,17 @@ import { promises } from 'fs';
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',
11
- },
12
- })
 
 
 
 
 
 
 
13
  }
 
4
  /** @type {import('./$types').RequestHandler} */
5
 
6
  export async function GET({ params } : RequestEvent) {
7
+ try {
8
+ const file = await promises.readFile(`${process.env.PUBLIC_FILE_UPLOAD_DIR}/${params.id}`)
9
+ if (!file) {
10
+ return new Response(null, { status: 404 });
11
+ }
12
+ return new Response(file, {
13
+ headers: {
14
+ 'Content-Type': 'image/png',
15
+ },
16
+ });
17
+ } catch (error) {
18
+ return new Response(null, { status: 500 });
19
+ }
20
  }