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
+37
View File
@@ -3,6 +3,7 @@ import logging
import uuid
import asyncpg
import botocore.exceptions
from fastapi import FastAPI, Request, status
from fastapi.exceptions import RequestValidationError
from fastapi.responses import JSONResponse
@@ -33,6 +34,14 @@ class ConflictError(StorageError):
pass
class PayloadTooLargeError(StorageError):
pass
class UnsupportedMediaTypeError(StorageError):
pass
class UnauthorizedError(StorageError):
pass
@@ -113,6 +122,30 @@ def register_error_handlers(app: FastAPI) -> None:
status.HTTP_409_CONFLICT, ErrorCode.CONFLICT, str(exc), req_id
)
@app.exception_handler(PayloadTooLargeError)
async def payload_too_large_handler(
request: Request, exc: PayloadTooLargeError
) -> JSONResponse:
req_id = get_request_id(request)
return make_error_response(
status.HTTP_413_REQUEST_ENTITY_TOO_LARGE,
ErrorCode.PAYLOAD_TOO_LARGE,
str(exc),
req_id,
)
@app.exception_handler(UnsupportedMediaTypeError)
async def unsupported_media_type_handler(
request: Request, exc: UnsupportedMediaTypeError
) -> JSONResponse:
req_id = get_request_id(request)
return make_error_response(
status.HTTP_415_UNSUPPORTED_MEDIA_TYPE,
ErrorCode.UNSUPPORTED_MEDIA_TYPE,
str(exc),
req_id,
)
@app.exception_handler(RequestValidationError)
async def validation_error_handler(
request: Request, exc: RequestValidationError
@@ -185,6 +218,8 @@ def register_error_handlers(app: FastAPI) -> None:
asyncpg.PostgresError,
asyncpg.InterfaceError,
redis.exceptions.RedisError,
botocore.exceptions.BotoCoreError,
botocore.exceptions.ClientError,
TimeoutError,
asyncio.TimeoutError,
ConnectionError,
@@ -204,6 +239,8 @@ def register_error_handlers(app: FastAPI) -> None:
asyncpg.PostgresError,
asyncpg.InterfaceError,
redis.exceptions.RedisError,
botocore.exceptions.BotoCoreError,
botocore.exceptions.ClientError,
TimeoutError,
asyncio.TimeoutError,
ConnectionError,