diff --git a/file_converter/routes/base.py b/file_converter/routes/base.py index 250ec17..b837375 100644 --- a/file_converter/routes/base.py +++ b/file_converter/routes/base.py @@ -48,8 +48,8 @@ async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) - app.add_middleware(LimitUploadSize, max_upload_size=settings.MAX_SIZE) -@app.exception_handler(aiohttp.client_exceptions.ClientConnectorError) -async def not_found_error(request: Request, exc: aiohttp.client_exceptions.ClientConnectorError): +@app.exception_handler(aiohttp.ClientConnectorError) +async def not_found_error(request: Request, exc: aiohttp.ClientConnectorError): raise HTTPException(404, f"request failed: {exc} ") diff --git a/file_converter/routes/file.py b/file_converter/routes/file.py index a11520b..ce3d40c 100644 --- a/file_converter/routes/file.py +++ b/file_converter/routes/file.py @@ -33,7 +33,8 @@ async def process( except UnsupportedToExt: raise HTTPException( - status_code=415, detail=f'Files are allowed to be converted only to {", ".join(settings.CONVERT_TYPES)}' + status_code=415, + detail=f'Files are allowed to be converted only to {", ".join(settings.CONVERT_TYPES)}', ) except ConvertError: @@ -43,4 +44,7 @@ async def process( raise HTTPException(status_code=415, detail=f'Only {", ".join(settings.EXTENTIONS)} files are allowed.') root_path = settings.ROOT_PATH.removesuffix('/') - return {"status": "Success", "file_url": f'{root_path}/{settings.STATIC_FOLDER}/{result}'} # Отдает URL на файл + return { + "status": "Success", + "file_url": f'{root_path}/{str(settings.STATIC_FOLDER)}/{result}', + } # Отдает URL на файл diff --git a/file_converter/settings.py b/file_converter/settings.py index 1400e9d..f650996 100644 --- a/file_converter/settings.py +++ b/file_converter/settings.py @@ -2,7 +2,8 @@ from functools import lru_cache from typing import List -from pydantic import BaseSettings, DirectoryPath +from pydantic import ConfigDict, DirectoryPath +from pydantic_settings import BaseSettings class Settings(BaseSettings): @@ -18,11 +19,7 @@ class Settings(BaseSettings): MAX_SIZE: int = 5000000 # Максимальный размер файла в байтах STATIC_FOLDER: DirectoryPath | None = "static" - class Config: - """Pydantic BaseSettings config""" - - case_sensitive = True - env_file = ".env" + model_config = ConfigDict(case_sensitive=True, env_file=".env", extra="ignore") @lru_cache diff --git a/requirements.txt b/requirements.txt index 22f252c..14af476 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,6 @@ fastapi -pydantic[dotenv] +pydantic +pydantic_settings uvicorn gunicorn aiofiles