This commit is contained in:
2023-05-09 00:10:09 +02:00
parent c39138459c
commit 345bdc85ae
3 changed files with 9 additions and 16 deletions

View File

@@ -27,7 +27,7 @@ pub fn unzip(tmp_file: SpooledTempFile, file_type: &str) -> Option<SpooledTempFi
} }
} }
return None; None
} }
pub fn zip(tmp_file: &mut SpooledTempFile, filename: &str) -> Option<SpooledTempFile> { pub fn zip(tmp_file: &mut SpooledTempFile, filename: &str) -> Option<SpooledTempFile> {

View File

@@ -5,16 +5,16 @@ use super::book_library::types::{BookAuthor, BookWithRemote};
pub fn get_author_short_name(author: BookAuthor) -> String { pub fn get_author_short_name(author: BookAuthor) -> String {
let mut parts: Vec<String> = vec![]; let mut parts: Vec<String> = vec![];
if author.last_name.len() != 0 { if !author.last_name.is_empty() {
parts.push(author.last_name); parts.push(author.last_name);
} }
if author.first_name.len() != 0 { if !author.first_name.is_empty() {
let first_char = author.first_name.chars().next().unwrap(); let first_char = author.first_name.chars().next().unwrap();
parts.push(first_char.to_string()); parts.push(first_char.to_string());
} }
if author.middle_name.len() != 0 { if !author.middle_name.is_empty() {
let first_char = author.middle_name.chars().next().unwrap(); let first_char = author.middle_name.chars().next().unwrap();
parts.push(first_char.to_string()); parts.push(first_char.to_string());
} }
@@ -34,12 +34,12 @@ pub fn get_filename_by_book(book: &BookWithRemote, file_type: &str, force_zip: b
file_type.to_string() file_type.to_string()
}; };
if book.authors.len() != 0 { if !book.authors.is_empty() {
filename_parts.push( filename_parts.push(
book.authors book.authors
.clone() .clone()
.into_iter() .into_iter()
.map(|author| get_author_short_name(author)) .map(get_author_short_name)
.collect::<Vec<String>>() .collect::<Vec<String>>()
.join("_-_"), .join("_-_"),
); );
@@ -67,10 +67,7 @@ pub fn get_filename_by_book(book: &BookWithRemote, file_type: &str, force_zip: b
("[", ""), ("[", ""),
("]", ""), ("]", ""),
("\"", ""), ("\"", ""),
] ].to_vec();
.iter()
.cloned()
.collect();
let replace_transliterator = Transliterator::new(replace_char_map); let replace_transliterator = Transliterator::new(replace_char_map);
let mut normal_filename = replace_transliterator.convert(&filename_without_type, false); let mut normal_filename = replace_transliterator.convert(&filename_without_type, false);
@@ -81,9 +78,7 @@ pub fn get_filename_by_book(book: &BookWithRemote, file_type: &str, force_zip: b
let right_part = format!(".{book_id}.{file_type_}"); let right_part = format!(".{book_id}.{file_type_}");
let normal_filename_slice = std::cmp::min(64 - right_part.len() - 1, normal_filename.len() -1); let normal_filename_slice = std::cmp::min(64 - right_part.len() - 1, normal_filename.len() -1);
let left_part = normal_filename.get(..normal_filename_slice).expect( let left_part = normal_filename.get(..normal_filename_slice).unwrap_or_else(|| panic!("Can't slice left part: {:?} {:?}", normal_filename, normal_filename_slice));
&format!("Can't slice left part: {:?} {:?}", normal_filename, normal_filename_slice)
);
format!("{left_part}{right_part}") format!("{left_part}{right_part}")
} }

View File

@@ -27,9 +27,7 @@ pub async fn download(
Path((source_id, remote_id, file_type)): Path<(u32, u32, String)>, Path((source_id, remote_id, file_type)): Path<(u32, u32, String)>,
headers: HeaderMap headers: HeaderMap
) -> impl IntoResponse { ) -> impl IntoResponse {
if let Err(v) = check_authorization(headers) { check_authorization(headers)?;
return Err(v);
}
let download_result = match book_download(source_id, remote_id, file_type.as_str()).await { let download_result = match book_download(source_id, remote_id, file_type.as_str()).await {
Ok(v) => v, Ok(v) => v,