mirror of
https://github.com/flibusta-apps/books_downloader.git
synced 2025-12-06 15:05:37 +01:00
Fix library service
This commit is contained in:
@@ -46,13 +46,16 @@ pub async fn get_sources() -> Result<types::Source, Box<dyn std::error::Error +
|
||||
|
||||
pub async fn get_book(
|
||||
book_id: u32,
|
||||
) -> Result<types::Book, Box<dyn std::error::Error + Send + Sync>> {
|
||||
) -> Result<types::BookWithRemote, Box<dyn std::error::Error + Send + Sync>> {
|
||||
_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<types::Book, Box<dyn std::error::Error + Send + Sync>> {
|
||||
_make_request(format!("/api/v1/books/remote/{source_id}/{book_id}").as_ref(), vec![]).await
|
||||
remote_id: u32,
|
||||
) -> Result<types::BookWithRemote, Box<dyn std::error::Error + Send + Sync>> {
|
||||
match _make_request::<types::Book>(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),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<BookAuthor>,
|
||||
}
|
||||
|
||||
#[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<BookAuthor>,
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<DownloadResult> {
|
||||
let mut futures = FuturesUnordered::new();
|
||||
|
||||
@@ -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<String> = 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<String> = vec![];
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user