This commit is contained in:
2023-08-06 22:36:30 +02:00
parent f31a4645c9
commit fe2aceaa73
4 changed files with 13 additions and 19 deletions

View File

@@ -10,7 +10,7 @@ pub fn get_minio() -> Minio {
None
);
return Minio::builder()
Minio::builder()
.host(&config::CONFIG.minio_host)
.provider(provider)
.secure(false)

View File

@@ -5,12 +5,11 @@ use smallvec::SmallVec;
use smartstring::alias::String as SmartString;
use tempfile::SpooledTempFile;
use tracing::log;
use translit::{Transliterator, gost779b_ru, CharsMapping};
use zip::write::FileOptions;
use crate::{structures::{CreateTask, Task, ObjectType}, config, views::TASK_RESULTS, services::{downloader::download, utils::{get_stream, get_filename}, minio::get_minio}};
use super::{library_client::{Book, get_sequence_books, get_author_books, get_translator_books, Page, get_sequence, get_author}, utils::get_key};
use super::{library_client::{Book, get_sequence_books, get_author_books, get_translator_books, Page}, utils::get_key};
pub async fn get_books<Fut>(
@@ -46,8 +45,7 @@ where
let result = result
.iter()
.filter(|book| book.available_types.contains(&file_format.to_string()))
.map(|b| b.clone())
.filter(|book| book.available_types.contains(&file_format.to_string())).cloned()
.collect();
Ok(result)
@@ -188,7 +186,7 @@ pub async fn create_archive_task(key: String, data: CreateTask) {
},
};
let archive_result = match create_archive(books, data.file_format).await {
let archive_result = match create_archive(key.clone(), books, data.file_format).await {
Ok(v) => v,
Err(err) => {
set_task_error(key.clone(), "Failed downloading books!".to_string()).await;

View File

@@ -62,21 +62,17 @@ pub fn get_stream(mut temp_file: Box<dyn Read + Send>) -> impl futures_core::Str
stream! {
let mut buf = [0; 2048];
loop {
match temp_file.read(&mut buf) {
Ok(count) => {
if count == 0 {
break;
}
yield Ok(Bytes::copy_from_slice(&buf[0..count]))
},
Err(_) => break
while let Ok(count) = temp_file.read(&mut buf) {
if count == 0 {
break;
}
yield Ok(Bytes::copy_from_slice(&buf[0..count]))
}
}
}
pub async fn get_filename(object_type: ObjectType, object_id: u32) -> Result<String, Box<dyn std::error::Error + Send + Sync>> {
let result_filename = match object_type {
ObjectType::Sequence => {
@@ -132,7 +128,7 @@ pub async fn get_filename(object_type: ObjectType, object_id: u32) -> Result<Str
let normal_filename = normal_filename.replace(|c: char| !c.is_ascii(), "");
let right_part = format!(".zip");
let right_part = ".zip".to_string();
let normal_filename_slice = std::cmp::min(64 - right_part.len() - 1, normal_filename.len() - 1);
let left_part = if normal_filename_slice == normal_filename.len() - 1 {

View File

@@ -29,7 +29,7 @@ async fn create_archive_task(
None => create_task(data).await,
};
Json::<Task>(result.into()).into_response()
Json::<Task>(result).into_response()
}
@@ -37,7 +37,7 @@ async fn check_archive_task_status(
Path(task_id): Path<String>
) -> impl IntoResponse {
match TASK_RESULTS.get(&task_id) {
Some(result) => Json::<Task>(result.into()).into_response(),
Some(result) => Json::<Task>(result).into_response(),
None => StatusCode::NOT_FOUND.into_response(),
}
}