configurable upload limits

This commit is contained in:
Gamosoft 2026-04-06 15:23:30 +02:00
parent 52926f4a63
commit 7090e835b1
3 changed files with 36 additions and 10 deletions

View File

@ -224,6 +224,12 @@ app.add_middleware(
DEMO_MODE = os.getenv('DEMO_MODE', 'false').lower() in ('true', '1', 'yes') DEMO_MODE = os.getenv('DEMO_MODE', 'false').lower() in ('true', '1', 'yes')
ALREADY_DONATED = os.getenv('ALREADY_DONATED', '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: if DEMO_MODE:
# Enable rate limiting for demo deployments # Enable rate limiting for demo deployments
limiter = Limiter(key_func=get_remote_address, default_limits=["200/hour"]) 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 # Validate file size - different limits for different types
media_type = get_media_type(file.filename) if file.filename else None 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 = { size_limits = {
'image': 10 * 1024 * 1024, 'image': UPLOAD_MAX_IMAGE_MB * 1024 * 1024,
'audio': 50 * 1024 * 1024, 'audio': UPLOAD_MAX_AUDIO_MB * 1024 * 1024,
'video': 100 * 1024 * 1024, 'video': UPLOAD_MAX_VIDEO_MB * 1024 * 1024,
'document': 20 * 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: if len(file_data) > max_size:
raise HTTPException( raise HTTPException(

View File

@ -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! > 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 Priority
Configuration is loaded in this order (later overrides earlier): Configuration is loaded in this order (later overrides earlier):

View File

@ -17,10 +17,10 @@
### Media Support ### Media Support
- **Drag & drop upload** - Drop files from your file system directly into the editor - **Drag & drop upload** - Drop files from your file system directly into the editor
- **Clipboard paste** - Paste images from clipboard with Ctrl+V - **Clipboard paste** - Paste images from clipboard with Ctrl+V
- **Images** - JPG, PNG, GIF, WebP (max 10MB) - **Images** - JPG, PNG, GIF, WebP (default max 10MB, configurable)
- **Audio** - MP3, WAV, OGG, M4A (max 50MB) - **Audio** - MP3, WAV, OGG, M4A (default max 50MB, configurable)
- **Video** - MP4, WebM, MOV, AVI (max 100MB) - **Video** - MP4, WebM, MOV, AVI (default max 100MB, configurable)
- **Documents** - PDF (max 20MB) - **Documents** - PDF (default max 20MB, configurable)
- **In-app viewing** - View all media types directly in the sidebar - **In-app viewing** - View all media types directly in the sidebar
- **Inline preview** - Audio/video players and PDF viewer embedded in notes - **Inline preview** - Audio/video players and PDF viewer embedded in notes