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