From 107a467bcc056d36f7c5f911264202b56e18d4cc Mon Sep 17 00:00:00 2001 From: PunchEnergyFTW <61878903+PunchEnergyFTW@users.noreply.github.com> Date: Mon, 28 Apr 2025 04:30:18 +0200 Subject: [PATCH] Feat: Add max filesize environment variable (#20) Co-authored-by: Charly Gley --- apps/docs/content/docs/2.0.0-beta/installation.mdx | 2 ++ apps/server/.env.example | 2 +- apps/server/prisma/seed.ts | 3 ++- apps/server/src/env.ts | 1 + docker-compose.yaml | 1 + 5 files changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/docs/content/docs/2.0.0-beta/installation.mdx b/apps/docs/content/docs/2.0.0-beta/installation.mdx index 85e6d56..fd22b13 100644 --- a/apps/docs/content/docs/2.0.0-beta/installation.mdx +++ b/apps/docs/content/docs/2.0.0-beta/installation.mdx @@ -49,6 +49,7 @@ services: - MINIO_BUCKET_NAME=files # MinIO bucket name - This is needed for MinIO to work properly, dont change it if you don't know what you are doing - FRONTEND_URL=${APP_URL:-http://${SERVER_IP:-localhost}:${APP_EXTERNAL_PORT:-5487}} # Frontend URL - Make sure to use the correct frontend URL, depends on where the frontend is running, its prepared for localhost, but you can change it to your frontend URL if needed - SERVER_IP=${SERVER_IP:-localhost} # Server IP - Make sure to use the correct server IP if you running on a cloud provider or a virtual machine. This prepared for localhost, but you can change it to your server IP if needed + - MAX_FILESIZE=${MAX_FILESIZE:-1073741824} # Max Filesize for upload - Declared in Bytes. Default is 1GiB ports: - "${API_EXTERNAL_PORT:-3333}:${API_INTERNAL_PORT:-3333}" # Backend port mapping restart: unless-stopped @@ -179,6 +180,7 @@ The table below shows all environment variables that can be set | MINIO_EXTERNAL_CONSOLE_PORT | 6422 | Exposed port on host for MinIO console | | POSTGRESQL_USERNAME | postgres | PostgreSQL user | | POSTGRESQL_DATABASE | palmr_db | Database name | +| MAX_FILESIZE | 1073741824 | Max Uploadsize per file. Unit in Bytes | > *All these variables can be configured through a .env file in the project root or defined directly in the environment where docker-compose will be executed. The best way to do this is up to you. But be careful to replace correctly if doing directly in the compose instead of providing an environment var.* > diff --git a/apps/server/.env.example b/apps/server/.env.example index 5dc3ee0..77dfa66 100644 --- a/apps/server/.env.example +++ b/apps/server/.env.example @@ -10,4 +10,4 @@ MINIO_REGION="sa-east-1" MINIO_BUCKET_NAME="files" PORT=3333 SERVER_IP="localhost" - +MAX_FILESIZE="1073741824" diff --git a/apps/server/prisma/seed.ts b/apps/server/prisma/seed.ts index 47193da..abd0160 100644 --- a/apps/server/prisma/seed.ts +++ b/apps/server/prisma/seed.ts @@ -1,6 +1,7 @@ import { prisma } from "../src/shared/prisma"; import bcrypt from "bcryptjs"; import crypto from "node:crypto"; +import { env } from '../src/env'; const defaultConfigs = [ // General Configurations @@ -31,7 +32,7 @@ const defaultConfigs = [ // Storage Configurations { key: "maxFileSize", - value: "1073741824", // 1GB in bytes + value: env.MAX_FILESIZE, // default 1GiB in bytes - 1073741824 type: "bigint", group: "storage", }, diff --git a/apps/server/src/env.ts b/apps/server/src/env.ts index b554749..324be19 100644 --- a/apps/server/src/env.ts +++ b/apps/server/src/env.ts @@ -12,6 +12,7 @@ const envSchema = z.object({ PORT: z.string().min(1), DATABASE_URL: z.string().min(1), SERVER_IP: z.string().min(1), + MAX_FILESIZE: z.string().min(1), }); export const env = envSchema.parse(process.env); diff --git a/docker-compose.yaml b/docker-compose.yaml index e1ff7a5..e7e428c 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -19,6 +19,7 @@ services: - MINIO_BUCKET_NAME=files # MinIO bucket name - This is needed for MinIO to work properly, dont change it if you don't know what you are doing - FRONTEND_URL=${APP_URL:-http://${SERVER_IP:-localhost}:${APP_EXTERNAL_PORT:-5487}} # Frontend URL - Make sure to use the correct frontend URL, depends on where the frontend is running, its prepared for localhost, but you can change it to your frontend URL if needed - SERVER_IP=${SERVER_IP:-localhost} # Server IP - Make sure to use the correct server IP if you running on a cloud provider or a virtual machine. This prepared for localhost, but you can change it to your server IP if needed + - MAX_FILESIZE=${MAX_FILESIZE:-1073741824} # Max Filesize for upload - Declared in Bytes. Default is 1GiB ports: - "${API_EXTERNAL_PORT:-3333}:${API_INTERNAL_PORT:-3333}" # Backend port mapping restart: unless-stopped