Fix book getting

This commit is contained in:
2022-12-07 20:51:52 +01:00
parent 6c77f0ced2
commit 6dcf78736a
2 changed files with 8 additions and 2 deletions

View File

@@ -117,6 +117,9 @@ async def cache_file_by_book_id(
return None return None
raise Retry(defer=15) raise Retry(defer=15)
if book is None:
return None
if file_type not in book.available_types: if file_type not in book.available_types:
raise FileTypeNotAllowed(f"{file_type} not in {book.available_types}!") raise FileTypeNotAllowed(f"{file_type} not in {book.available_types}!")

View File

@@ -1,5 +1,5 @@
from datetime import date from datetime import date
from typing import Generic, TypeVar from typing import Generic, TypeVar, Optional
import httpx import httpx
from pydantic import BaseModel from pydantic import BaseModel
@@ -48,12 +48,15 @@ class BookDetail(Book):
AUTH_HEADERS = {"Authorization": env_config.LIBRARY_API_KEY} AUTH_HEADERS = {"Authorization": env_config.LIBRARY_API_KEY}
async def get_book(book_id: int) -> BookDetail: async def get_book(book_id: int) -> Optional[BookDetail]:
async with httpx.AsyncClient(timeout=2 * 60) as client: async with httpx.AsyncClient(timeout=2 * 60) as client:
response = await client.get( response = await client.get(
f"{env_config.LIBRARY_URL}/api/v1/books/{book_id}", headers=AUTH_HEADERS f"{env_config.LIBRARY_URL}/api/v1/books/{book_id}", headers=AUTH_HEADERS
) )
if response.status_code != 200:
return None
return BookDetail.parse_obj(response.json()) return BookDetail.parse_obj(response.json())