mirror of
https://github.com/flibusta-apps/books_downloader.git
synced 2025-12-06 06:55:37 +01:00
Add BookLibraryClient.sources cache
This commit is contained in:
@@ -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
|
||||||
@@ -46,6 +46,8 @@ class BookLibraryClient:
|
|||||||
API_KEY = env_config.BOOK_LIBRARY_API_KEY
|
API_KEY = env_config.BOOK_LIBRARY_API_KEY
|
||||||
BASE_URL = env_config.BOOK_LIBRARY_URL
|
BASE_URL = env_config.BOOK_LIBRARY_URL
|
||||||
|
|
||||||
|
_sources_cache: Optional[list[Source]] = None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@property
|
@property
|
||||||
def auth_headers(cls):
|
def auth_headers(cls):
|
||||||
@@ -58,11 +60,16 @@ class BookLibraryClient:
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def get_sources(cls) -> list[Source]:
|
async def get_sources(cls) -> list[Source]:
|
||||||
|
if cls._sources_cache:
|
||||||
|
return cls._sources_cache
|
||||||
|
|
||||||
data = await cls._make_request(f"{cls.BASE_URL}/api/v1/sources")
|
data = await cls._make_request(f"{cls.BASE_URL}/api/v1/sources")
|
||||||
|
|
||||||
page = Page[Source].parse_obj(data)
|
page = Page[Source].parse_obj(data)
|
||||||
|
|
||||||
return [Source.parse_obj(item) for item in page.items]
|
sources = [Source.parse_obj(item) for item in page.items]
|
||||||
|
cls._sources_cache = sources
|
||||||
|
return sources
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
async def get_book(cls, book_id: int) -> BookDetail:
|
async def get_book(cls, book_id: int) -> BookDetail:
|
||||||
|
|||||||
Reference in New Issue
Block a user