diff --git a/src/services/book_library/mod.rs b/src/services/book_library/mod.rs index c7ee639..ea0f701 100644 --- a/src/services/book_library/mod.rs +++ b/src/services/book_library/mod.rs @@ -46,13 +46,16 @@ pub async fn get_sources() -> Result Result> { +) -> Result> { _make_request(format!("/api/v1/books/{book_id}").as_str(), vec![]).await } pub async fn get_remote_book( source_id: u32, - book_id: u32, -) -> Result> { - _make_request(format!("/api/v1/books/remote/{source_id}/{book_id}").as_ref(), vec![]).await + remote_id: u32, +) -> Result> { + match _make_request::(format!("/api/v1/books/remote/{source_id}/{remote_id}").as_ref(), vec![]).await { + Ok(v) => Ok(types::BookWithRemote::from_book(v, remote_id)), + Err(err) => Err(err), + } } diff --git a/src/services/book_library/types.rs b/src/services/book_library/types.rs index 463b3f7..60e11c8 100644 --- a/src/services/book_library/types.rs +++ b/src/services/book_library/types.rs @@ -17,6 +17,16 @@ pub struct BookAuthor { #[derive(Deserialize, Debug, Clone)] pub struct Book { + pub id: u32, + pub title: String, + pub lang: String, + pub file_type: String, + pub uploaded: String, + pub authors: Vec, +} + +#[derive(Deserialize, Debug, Clone)] +pub struct BookWithRemote { pub id: u32, pub remote_id: u32, pub title: String, @@ -25,3 +35,17 @@ pub struct Book { pub uploaded: String, pub authors: Vec, } + +impl BookWithRemote { + pub fn from_book(book: Book, remote_id: u32) -> Self { + Self { + id: book.id, + remote_id, + title: book.title, + lang: book.lang, + file_type: book.file_type, + uploaded: book.uploaded, + authors: book.authors + } + } +} diff --git a/src/services/downloader/mod.rs b/src/services/downloader/mod.rs index 6be0b91..8607928 100644 --- a/src/services/downloader/mod.rs +++ b/src/services/downloader/mod.rs @@ -10,7 +10,7 @@ use self::types::{DownloadResult, Data, SpooledTempAsyncRead}; use self::utils::response_to_tempfile; use self::zip::{unzip, zip}; -use super::book_library::types::Book; +use super::book_library::types::BookWithRemote; use super::covert::convert_file; use super::{book_library::get_remote_book, filename_getter::get_filename_by_book}; @@ -75,7 +75,7 @@ pub async fn download<'a>( } pub async fn download_chain<'a>( - book: &'a Book, + book: &'a BookWithRemote, file_type: &'a str, source_config: &'a config::SourceConfig, converting: bool @@ -150,7 +150,7 @@ pub async fn download_chain<'a>( } pub async fn start_download_futures( - book: &Book, + book: &BookWithRemote, file_type: &str, ) -> Option { let mut futures = FuturesUnordered::new(); diff --git a/src/services/filename_getter.rs b/src/services/filename_getter.rs index 57541f3..2a2a123 100644 --- a/src/services/filename_getter.rs +++ b/src/services/filename_getter.rs @@ -1,6 +1,6 @@ use translit::{gost779b_ru, CharsMapping, Transliterator}; -use super::book_library::types::{BookAuthor, Book}; +use super::book_library::types::{BookAuthor, BookWithRemote}; pub fn get_author_short_name(author: BookAuthor) -> String { let mut parts: Vec = vec![]; @@ -22,7 +22,7 @@ pub fn get_author_short_name(author: BookAuthor) -> String { parts.join(" ") } -pub fn get_filename_by_book(book: &Book, file_type: &str, force_zip: bool) -> String { +pub fn get_filename_by_book(book: &BookWithRemote, file_type: &str, force_zip: bool) -> String { let book_id = book.remote_id; let mut filename_parts: Vec = vec![]; diff --git a/src/views.rs b/src/views.rs index a9062df..f44c0a4 100644 --- a/src/views.rs +++ b/src/views.rs @@ -25,7 +25,10 @@ pub async fn download( let download_result = match book_download(source_id, remote_id, file_type.as_str()).await { Ok(v) => v, - Err(_) => return Err((StatusCode::NO_CONTENT, "Can't download!".to_string())), + Err(err) => { + log::debug!("{:?}", err); + return Err((StatusCode::NO_CONTENT, "Can't download!".to_string())) + }, }; let (data, filename) = match download_result {