Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
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 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
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 |
}
|