mirror of
https://github.com/flibusta-apps/batch_downloader.git
synced 2025-12-06 06:15:37 +01:00
Fix
This commit is contained in:
@@ -4,6 +4,7 @@ use base64::{engine::general_purpose, Engine};
|
||||
use reqwest::StatusCode;
|
||||
use smartstring::alias::String as SmartString;
|
||||
use tempfile::SpooledTempFile;
|
||||
use tracing::log;
|
||||
|
||||
use crate::config;
|
||||
|
||||
@@ -54,7 +55,13 @@ pub async fn download(
|
||||
.unwrap()
|
||||
.to_string();
|
||||
|
||||
let output_file = response_to_tempfile(&mut response).await.unwrap();
|
||||
let output_file = match response_to_tempfile(&mut response).await {
|
||||
Ok(v) => v,
|
||||
Err(err) => {
|
||||
log::error!("Error: {}", err);
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
|
||||
Ok((output_file.0, filename))
|
||||
}
|
||||
|
||||
@@ -23,7 +23,9 @@ pub fn get_key(input_data: CreateTask) -> String {
|
||||
format!("{:x}", md5::compute(data_string))
|
||||
}
|
||||
|
||||
pub async fn response_to_tempfile(res: &mut Response) -> Option<(SpooledTempFile, usize)> {
|
||||
pub async fn response_to_tempfile(
|
||||
res: &mut Response,
|
||||
) -> Result<(SpooledTempFile, usize), Box<dyn std::error::Error + Send + Sync>> {
|
||||
let mut tmp_file = tempfile::spooled_tempfile(5 * 1024 * 1024);
|
||||
|
||||
let mut data_size: usize = 0;
|
||||
@@ -34,7 +36,7 @@ pub async fn response_to_tempfile(res: &mut Response) -> Option<(SpooledTempFile
|
||||
|
||||
let result = match chunk {
|
||||
Ok(v) => v,
|
||||
Err(_) => return None,
|
||||
Err(err) => return Err(Box::new(err)),
|
||||
};
|
||||
|
||||
let data = match result {
|
||||
@@ -46,14 +48,16 @@ pub async fn response_to_tempfile(res: &mut Response) -> Option<(SpooledTempFile
|
||||
|
||||
match tmp_file.write(data.chunk()) {
|
||||
Ok(_) => (),
|
||||
Err(_) => return None,
|
||||
Err(err) => {
|
||||
return Err(Box::new(err));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tmp_file.seek(SeekFrom::Start(0)).unwrap();
|
||||
}
|
||||
|
||||
Some((tmp_file, data_size))
|
||||
Ok((tmp_file, data_size))
|
||||
}
|
||||
|
||||
pub fn get_stream(
|
||||
|
||||
Reference in New Issue
Block a user