Skip to content

Commit

Permalink
Fix image error
Browse files Browse the repository at this point in the history
  • Loading branch information
istarkov committed May 6, 2024
1 parent 89979eb commit 0232fe3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion apps/builder/app/routes/cgi.image.$name.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createReadStream } from "node:fs";
import { createReadStream, existsSync } from "node:fs";
import { join } from "node:path";
import { createReadableStreamFromReadable } from "@remix-run/node";
import type { LoaderFunctionArgs } from "@remix-run/server-runtime";
Expand Down Expand Up @@ -52,6 +52,13 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
}
const fileUploadPath = env.FILE_UPLOAD_PATH;
const filePath = join(process.cwd(), fileUploadPath, name);

if (existsSync(filePath) === false) {
throw new Response("Not found", {
status: 404,
});
}

return new Response(
createReadableStreamFromReadable(createReadStream(filePath))
);
Expand Down

0 comments on commit 0232fe3

Please sign in to comment.