From 1d1cd63e7b7431d396155d91d276f3332a3b83d8 Mon Sep 17 00:00:00 2001 From: Bulat Kurbanov Date: Wed, 9 Aug 2023 00:23:26 +0200 Subject: [PATCH] Fix --- src/app/services/downloader.py | 6 ++++-- src/app/views.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/app/services/downloader.py b/src/app/services/downloader.py index cf9f1bd..d6d514a 100644 --- a/src/app/services/downloader.py +++ b/src/app/services/downloader.py @@ -35,7 +35,7 @@ async def download( return response, client, name -async def get_filename(book_id: int, file_type: str) -> Optional[str]: +async def get_filename(book_id: int, file_type: str) -> Optional[tuple[str, str]]: headers = {"Authorization": env_config.DOWNLOADER_API_KEY} try: @@ -49,7 +49,9 @@ async def get_filename(book_id: int, file_type: str) -> Optional[str]: if response.status_code != 200: return None - return response.text + data = response.json() + + return data["filename"], data["filename_ascii"] except httpx.HTTPError as e: capture_exception(e) return None diff --git a/src/app/views.py b/src/app/views.py index 1c5b6c4..fc7a42d 100644 --- a/src/app/views.py +++ b/src/app/views.py @@ -70,7 +70,7 @@ async def download_cached_file(request: Request, object_id: int, object_type: st if data is None: raise HTTPException(status_code=status.HTTP_204_NO_CONTENT) - if (filename := await get_filename(object_id, object_type)) is None: + if (filename_data := await get_filename(object_id, object_type)) is None: raise HTTPException(status_code=status.HTTP_204_NO_CONTENT) if (book := await get_book(object_id)) is None: @@ -82,7 +82,7 @@ async def download_cached_file(request: Request, object_id: int, object_type: st await response.aclose() await client.aclose() - filename_ascii = filename.encode("ascii", "ignore").decode("ascii") + filename, filename_ascii = filename_data return StreamingResponse( response.aiter_bytes(),