fix s3 storage

This commit is contained in:
2026-11-04 22:00:11 +03:00
parent 7576ee8c83
commit 5ceab4825e
10 changed files with 274 additions and 108 deletions
+16 -6
View File
@@ -8,24 +8,34 @@ import unicodedata
from anyio import CancelScope
from app.core.s3 import S3Settings
from app.errors.exceptions import image_validation_error, invalid_request, payload_too_large
from app.errors.exceptions import (
image_validation_error,
invalid_request,
payload_too_large,
)
from app.errors.handlers import operation_timeout
def validate_filename(filename: str) -> None:
if not 1 <= len(filename) <= 255 or any(
char in '/\\' or unicodedata.category(char) in {'Cc', 'Cf', 'Cs'} for char in filename
char in "/\\" or unicodedata.category(char) in {"Cc", "Cf", "Cs"}
for char in filename
):
raise invalid_request('Недопустимое имя файла')
raise invalid_request("Недопустимое имя файла")
async def validate_image(path: Path, content_type: str, settings: S3Settings) -> None:
process = await asyncio.create_subprocess_exec(
sys.executable, '-m', 'app.core.image_worker', str(path), content_type,
str(settings.max_image_pixels), stdout=asyncio.subprocess.DEVNULL,
sys.executable,
"-m",
"app.core.image_worker",
str(path),
content_type,
str(settings.max_image_pixels),
stdout=asyncio.subprocess.DEVNULL,
stderr=asyncio.subprocess.DEVNULL,
)
error = payload_too_large('Превышен бюджет проверки изображения')
error = payload_too_large("Превышен бюджет проверки изображения")
try:
async with operation_timeout(settings.image_timeout_seconds, error):
code = await process.wait()