Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions file_converter/routes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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} ")


Expand Down
8 changes: 6 additions & 2 deletions file_converter/routes/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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}',
Comment thread
Wudext marked this conversation as resolved.
} # Отдает URL на файл
9 changes: 3 additions & 6 deletions file_converter/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
fastapi
pydantic[dotenv]
pydantic
pydantic_settings
uvicorn
gunicorn
aiofiles
Expand Down