Fix for reuse connections

This commit is contained in:
2024-05-13 13:16:42 +02:00
parent a390a5aa8e
commit 548b3d66d7
5 changed files with 38 additions and 17 deletions

View File

@@ -1,3 +1,4 @@
use once_cell::sync::Lazy;
use smallvec::SmallVec;
use smartstring::alias::String as SmartString;
@@ -5,6 +6,10 @@ use serde::{Deserialize, Serialize};
use crate::config;
pub static CLIENT: Lazy<reqwest::Client> = Lazy::new(reqwest::Client::new);
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum TaskObjectType {
@@ -43,7 +48,7 @@ pub struct Task {
pub async fn create_task(
data: CreateTaskData,
) -> Result<Task, Box<dyn std::error::Error + Send + Sync>> {
Ok(reqwest::Client::new()
Ok(CLIENT
.post(format!("{}/api/", &config::CONFIG.batch_downloader_url))
.body(serde_json::to_string(&data).unwrap())
.header("Authorization", &config::CONFIG.batch_downloader_api_key)
@@ -56,7 +61,7 @@ pub async fn create_task(
}
pub async fn get_task(task_id: String) -> Result<Task, Box<dyn std::error::Error + Send + Sync>> {
Ok(reqwest::Client::new()
Ok(CLIENT
.get(format!(
"{}/api/check_archive/{task_id}",
&config::CONFIG.batch_downloader_url