mirror of
https://github.com/flibusta-apps/books_downloader.git
synced 2025-12-06 15:05:37 +01:00
Fix for reuse connections
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
pub mod types;
|
pub mod types;
|
||||||
|
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
use serde::de::DeserializeOwned;
|
use serde::de::DeserializeOwned;
|
||||||
|
|
||||||
use crate::config;
|
use crate::config;
|
||||||
|
|
||||||
|
pub static CLIENT: Lazy<reqwest::Client> = Lazy::new(reqwest::Client::new);
|
||||||
|
|
||||||
async fn _make_request<T>(
|
async fn _make_request<T>(
|
||||||
url: &str,
|
url: &str,
|
||||||
params: Vec<(&str, String)>,
|
params: Vec<(&str, String)>,
|
||||||
@@ -11,11 +14,9 @@ async fn _make_request<T>(
|
|||||||
where
|
where
|
||||||
T: DeserializeOwned,
|
T: DeserializeOwned,
|
||||||
{
|
{
|
||||||
let client = reqwest::Client::new();
|
|
||||||
|
|
||||||
let formatted_url = format!("{}{}", &config::CONFIG.book_library_url, url);
|
let formatted_url = format!("{}{}", &config::CONFIG.book_library_url, url);
|
||||||
|
|
||||||
let response = client
|
let response = CLIENT
|
||||||
.get(formatted_url)
|
.get(formatted_url)
|
||||||
.query(¶ms)
|
.query(¶ms)
|
||||||
.header("Authorization", &config::CONFIG.book_library_api_key)
|
.header("Authorization", &config::CONFIG.book_library_api_key)
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ pub mod types;
|
|||||||
pub mod utils;
|
pub mod utils;
|
||||||
pub mod zip;
|
pub mod zip;
|
||||||
|
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
use reqwest::Response;
|
use reqwest::Response;
|
||||||
use tokio::task::JoinSet;
|
use tokio::task::JoinSet;
|
||||||
|
|
||||||
@@ -15,6 +16,8 @@ use super::book_library::types::BookWithRemote;
|
|||||||
use super::covert::convert_file;
|
use super::covert::convert_file;
|
||||||
use super::{book_library::get_remote_book, filename_getter::get_filename_by_book};
|
use super::{book_library::get_remote_book, filename_getter::get_filename_by_book};
|
||||||
|
|
||||||
|
pub static CLIENT: Lazy<reqwest::Client> = Lazy::new(reqwest::Client::new);
|
||||||
|
|
||||||
pub async fn download<'a>(
|
pub async fn download<'a>(
|
||||||
book_id: &'a u32,
|
book_id: &'a u32,
|
||||||
book_file_type: &'a str,
|
book_file_type: &'a str,
|
||||||
@@ -37,7 +40,7 @@ pub async fn download<'a>(
|
|||||||
.build()
|
.build()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
None => reqwest::Client::new(),
|
None => CLIENT.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let response = client.get(url).send().await;
|
let response = client.get(url).send().await;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ pub async fn response_to_tempfile(res: &mut Response) -> Option<(SpooledTempFile
|
|||||||
|
|
||||||
data_size += data.len();
|
data_size += data.len();
|
||||||
|
|
||||||
match tmp_file.write(data.chunk()) {
|
match tmp_file.write_all(data.chunk()) {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(_) => return None,
|
Err(_) => return None,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user