From 7090e835b19b9ed2e09b838a608ca009cdee89d0 Mon Sep 17 00:00:00 2001 From: Gamosoft Date: Mon, 6 Apr 2026 15:23:30 +0200 Subject: [PATCH] configurable upload limits --- backend/main.py | 18 ++++++++++++------ documentation/ENVIRONMENT_VARIABLES.md | 20 ++++++++++++++++++++ documentation/FEATURES.md | 8 ++++---- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/backend/main.py b/backend/main.py index d4cb453..6499f8b 100644 --- a/backend/main.py +++ b/backend/main.py @@ -224,6 +224,12 @@ app.add_middleware( DEMO_MODE = os.getenv('DEMO_MODE', 'false').lower() in ('true', '1', 'yes') ALREADY_DONATED = os.getenv('ALREADY_DONATED', 'false').lower() in ('true', '1', 'yes') +# Upload size limits (in MB) - configurable via environment variables +UPLOAD_MAX_IMAGE_MB = int(os.getenv('UPLOAD_MAX_IMAGE_MB', '10')) +UPLOAD_MAX_AUDIO_MB = int(os.getenv('UPLOAD_MAX_AUDIO_MB', '50')) +UPLOAD_MAX_VIDEO_MB = int(os.getenv('UPLOAD_MAX_VIDEO_MB', '100')) +UPLOAD_MAX_PDF_MB = int(os.getenv('UPLOAD_MAX_PDF_MB', '20')) + if DEMO_MODE: # Enable rate limiting for demo deployments limiter = Limiter(key_func=get_remote_address, default_limits=["200/hour"]) @@ -656,14 +662,14 @@ async def upload_media(request: Request, file: UploadFile = File(...), note_path # Validate file size - different limits for different types media_type = get_media_type(file.filename) if file.filename else None - # Size limits: images 10MB, audio 50MB, video 100MB, PDF 20MB + # Size limits (configurable via UPLOAD_MAX_*_MB environment variables) size_limits = { - 'image': 10 * 1024 * 1024, - 'audio': 50 * 1024 * 1024, - 'video': 100 * 1024 * 1024, - 'document': 20 * 1024 * 1024, + 'image': UPLOAD_MAX_IMAGE_MB * 1024 * 1024, + 'audio': UPLOAD_MAX_AUDIO_MB * 1024 * 1024, + 'video': UPLOAD_MAX_VIDEO_MB * 1024 * 1024, + 'document': UPLOAD_MAX_PDF_MB * 1024 * 1024, } - max_size = size_limits.get(media_type, 10 * 1024 * 1024) + max_size = size_limits.get(media_type, UPLOAD_MAX_IMAGE_MB * 1024 * 1024) if len(file_data) > max_size: raise HTTPException( diff --git a/documentation/ENVIRONMENT_VARIABLES.md b/documentation/ENVIRONMENT_VARIABLES.md index 45dae01..3dfe1b9 100644 --- a/documentation/ENVIRONMENT_VARIABLES.md +++ b/documentation/ENVIRONMENT_VARIABLES.md @@ -47,6 +47,26 @@ AUTHENTICATION_PASSWORD=mysecretpassword > > Haven't donated yet? [☕ Buy me a coffee](https://ko-fi.com/gamosoft) - it takes 30 seconds and makes my day! +### Upload Limits + +| Variable | Type | Default | Description | +|----------|------|---------|-------------| +| `UPLOAD_MAX_IMAGE_MB` | integer | `10` | Maximum image upload size in MB | +| `UPLOAD_MAX_AUDIO_MB` | integer | `50` | Maximum audio upload size in MB | +| `UPLOAD_MAX_VIDEO_MB` | integer | `100` | Maximum video upload size in MB | +| `UPLOAD_MAX_PDF_MB` | integer | `20` | Maximum PDF upload size in MB | + +#### Example: Allowing larger video uploads + +```bash +# Docker +docker run -e UPLOAD_MAX_VIDEO_MB=500 ... + +# Docker Compose +environment: + - UPLOAD_MAX_VIDEO_MB=500 +``` + ## 🎯 Configuration Priority Configuration is loaded in this order (later overrides earlier): diff --git a/documentation/FEATURES.md b/documentation/FEATURES.md index 950be8a..dfb100c 100644 --- a/documentation/FEATURES.md +++ b/documentation/FEATURES.md @@ -17,10 +17,10 @@ ### Media Support - **Drag & drop upload** - Drop files from your file system directly into the editor - **Clipboard paste** - Paste images from clipboard with Ctrl+V -- **Images** - JPG, PNG, GIF, WebP (max 10MB) -- **Audio** - MP3, WAV, OGG, M4A (max 50MB) -- **Video** - MP4, WebM, MOV, AVI (max 100MB) -- **Documents** - PDF (max 20MB) +- **Images** - JPG, PNG, GIF, WebP (default max 10MB, configurable) +- **Audio** - MP3, WAV, OGG, M4A (default max 50MB, configurable) +- **Video** - MP4, WebM, MOV, AVI (default max 100MB, configurable) +- **Documents** - PDF (default max 20MB, configurable) - **In-app viewing** - View all media types directly in the sidebar - **Inline preview** - Audio/video players and PDF viewer embedded in notes