mirror of
https://github.com/flibusta-apps/books_downloader.git
synced 2025-12-06 06:55:37 +01:00
Add filename endpoint
This commit is contained in:
@@ -38,6 +38,10 @@ class Book(BaseModel):
|
||||
authors: list[BookAuthor]
|
||||
|
||||
|
||||
class BookDetail(Book):
|
||||
remote_id: int
|
||||
|
||||
|
||||
class BookLibraryClient:
|
||||
API_KEY = env_config.BOOK_LIBRARY_API_KEY
|
||||
BASE_URL = env_config.BOOK_LIBRARY_URL
|
||||
@@ -61,6 +65,12 @@ class BookLibraryClient:
|
||||
|
||||
return [Source.parse_obj(item) for item in page.items]
|
||||
|
||||
@classmethod
|
||||
async def get_book(cls, book_id: int) -> BookDetail:
|
||||
data = await cls._make_request(f"{cls.BASE_URL}/api/v1/books/{book_id}")
|
||||
|
||||
return BookDetail.parse_obj(data)
|
||||
|
||||
@classmethod
|
||||
async def get_remote_book(cls, source_id: int, book_id: int) -> Book:
|
||||
data = await cls._make_request(
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from fastapi.responses import Response
|
||||
from fastapi import APIRouter, Depends, Response
|
||||
|
||||
from app.depends import check_token
|
||||
from app.services.book_library import BookLibraryClient
|
||||
from app.services.dowloaders_manager import DownloadersManager
|
||||
from app.services.utils import get_filename as _get_filename
|
||||
|
||||
|
||||
router = APIRouter(
|
||||
@@ -20,3 +21,10 @@ async def download(source_id: int, remote_id: int, file_type: str):
|
||||
return Response(
|
||||
content, headers={"Content-Disposition": f"attachment; filename={filename}"}
|
||||
)
|
||||
|
||||
|
||||
@router.get("/filename/{book_id}/{file_type}", response_model=str)
|
||||
async def get_filename(book_id: int, file_type: str):
|
||||
book = await BookLibraryClient.get_book(book_id)
|
||||
|
||||
return _get_filename(book.remote_id, book, file_type)
|
||||
|
||||
Reference in New Issue
Block a user