mirror of
https://github.com/flibusta-apps/telegram_files_cache_server.git
synced 2025-12-06 14:45:36 +01:00
Fix
This commit is contained in:
@@ -35,7 +35,7 @@ async def download(
|
|||||||
return response, client, name
|
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}
|
headers = {"Authorization": env_config.DOWNLOADER_API_KEY}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -49,7 +49,9 @@ async def get_filename(book_id: int, file_type: str) -> Optional[str]:
|
|||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return response.text
|
data = response.json()
|
||||||
|
|
||||||
|
return data["filename"], data["filename_ascii"]
|
||||||
except httpx.HTTPError as e:
|
except httpx.HTTPError as e:
|
||||||
capture_exception(e)
|
capture_exception(e)
|
||||||
return None
|
return None
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ async def download_cached_file(request: Request, object_id: int, object_type: st
|
|||||||
if data is None:
|
if data is None:
|
||||||
raise HTTPException(status_code=status.HTTP_204_NO_CONTENT)
|
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)
|
raise HTTPException(status_code=status.HTTP_204_NO_CONTENT)
|
||||||
|
|
||||||
if (book := await get_book(object_id)) is None:
|
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 response.aclose()
|
||||||
await client.aclose()
|
await client.aclose()
|
||||||
|
|
||||||
filename_ascii = filename.encode("ascii", "ignore").decode("ascii")
|
filename, filename_ascii = filename_data
|
||||||
|
|
||||||
return StreamingResponse(
|
return StreamingResponse(
|
||||||
response.aiter_bytes(),
|
response.aiter_bytes(),
|
||||||
|
|||||||
Reference in New Issue
Block a user