diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..bd4861e --- /dev/null +++ b/.env.example @@ -0,0 +1,5 @@ +PORT=3000 +DOMAIN=localhost:3000 + +# max upload size in MB, defaults to 20 if unset +MAX_FILE_SIZE=20 diff --git a/app/routes/home.tsx b/app/routes/home.tsx index 49bdc3a..8d0e952 100644 --- a/app/routes/home.tsx +++ b/app/routes/home.tsx @@ -4,6 +4,8 @@ import { useFetcher } from "react-router"; import type { Route } from "./+types/home"; +const maxFileSize = Number(process.env.MAX_FILE_SIZE) || 20; + export function meta(_args: Route.MetaArgs) { return [ { title: "NoBG" }, @@ -22,8 +24,8 @@ export async function action({ request }: Route.ActionArgs) { if (!(image instanceof File) || image.size === 0) { return { error: "Choose an image first" }; } - if (image.size > 20 * 1024 * 1024) { // 20mb limit - return { error: "Image is too large (max 20MB)" }; + if (image.size > maxFileSize * 1024 * 1024) { + return { error: `Image is too large (max ${maxFileSize}MB)` }; } try {