Fix for reuse connections

This commit is contained in:
2024-05-13 12:58:08 +02:00
parent 989f276d40
commit 91c704dd07
3 changed files with 9 additions and 5 deletions

View File

@@ -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(&params)
.header("Authorization", &config::CONFIG.book_library_api_key)

View File

@@ -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;

View File

@@ -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,
}