fix(upload): configure chat attachment size limit (#2439)

This commit is contained in:
nubs
2026-06-07 20:42:24 +00:00
committed by GitHub
parent 8746c9c0df
commit 865e61450e
9 changed files with 106 additions and 4 deletions
+6 -2
View File
@@ -12,6 +12,10 @@ import threading
from datetime import datetime, timedelta
from typing import Dict, Any, Optional
from fastapi import HTTPException, UploadFile
from src.upload_limits import format_byte_limit, get_chat_upload_max_bytes
def secure_filename(filename: str) -> str:
"""Sanitize a filename (replaces werkzeug.utils.secure_filename)."""
import unicodedata
@@ -73,7 +77,7 @@ class UploadHandler:
def __init__(self, base_dir: str, upload_dir: str):
self.base_dir = base_dir
self.upload_dir = upload_dir
self.max_upload_size = 10 * 1024 * 1024 # 10MB
self.max_upload_size = get_chat_upload_max_bytes()
self.max_concurrent_uploads = 3
self.cleanup_days = 30
# Per-IP per-minute cap. save_upload() counts EACH file, and the chat
@@ -518,7 +522,7 @@ class UploadHandler:
if file_size > self.max_upload_size:
raise HTTPException(
status_code=400,
detail=f"File size exceeds {self.max_upload_size/1024/1024}MB limit"
detail=f"File size exceeds {format_byte_limit(self.max_upload_size)} limit"
)
# Get original filename and sanitize it