feat: ЛР4 - S3 хранилище MinIO, загрузка вложений и защита от атак

This commit is contained in:
Ильяс
2026-11-06 15:59:44 +03:00
parent 9b574fa5e9
commit 4979731408
24 changed files with 1418 additions and 72 deletions
+20 -4
View File
@@ -32,19 +32,35 @@ class RequestIdAndLoggingMiddleware(BaseHTTPMiddleware):
start_time = time.monotonic()
if request.method in ("POST", "PUT", "PATCH") and request.url.path != "/api/v1/auth/sessions":
is_attachment_upload = (
request.method == "POST"
and "/attachments" in request.url.path
and request.url.path.startswith("/api/v1/chats/")
)
ct = request.headers.get("content-type")
if ct:
ct_clean = ct.split(";")[0].strip().lower()
if ct_clean != "application/json":
ct_clean = ct.split(";")[0].strip().lower() if ct else ""
if is_attachment_upload:
if not ct or ct_clean not in ("image/png", "image/jpeg"):
from fastapi import status
from app.errors import make_error_response
from app.schemas import ErrorCode
return make_error_response(
status.HTTP_415_UNSUPPORTED_MEDIA_TYPE,
ErrorCode.UNSUPPORTED_MEDIA_TYPE,
f"Неподдерживаемый тип содержимого '{ct}'. Ожидается application/json",
f"Неподдерживаемый тип содержимого '{ct}'. Ожидается image/png или image/jpeg",
request_id,
)
elif ct and ct_clean != "application/json":
from fastapi import status
from app.errors import make_error_response
from app.schemas import ErrorCode
return make_error_response(
status.HTTP_415_UNSUPPORTED_MEDIA_TYPE,
ErrorCode.UNSUPPORTED_MEDIA_TYPE,
f"Неподдерживаемый тип содержимого '{ct}'. Ожидается application/json",
request_id,
)
try:
response = await call_next(request)