diff --git a/src/database/mod.rs b/src/database/mod.rs index 77ac42e..dd8cc1f 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -41,7 +41,7 @@ pub mod test { .run_pending_migrations(DB_MIGRATIONS) .expect("Failure running DB migrations"); - return connection; + connection } } diff --git a/src/files.rs b/src/files.rs index bee4037..22d2e21 100644 --- a/src/files.rs +++ b/src/files.rs @@ -19,6 +19,7 @@ use log::{debug, error, info, trace}; use crate::data::{Claims, FilesRequest, FilterMode, PhotosResponse, SortType}; use crate::{create_thumbnails, AppState}; +use crate::data::SortType::{NameAsc}; use crate::error::IntoHttpError; use crate::tags::TagDao; use crate::video::StreamActor; @@ -54,7 +55,7 @@ pub async fn list_photos( let exclude_tag_ids = req .exclude_tag_ids .clone() - .unwrap_or(String::new()) + .unwrap_or_default() .split(',') .filter_map(|t| t.parse().ok()) .collect::>(); @@ -72,17 +73,18 @@ pub async fn list_photos( .into_iter() .filter(|f| { // When searching at the root, everything matches recursively - if search_path.trim() == "" { return true; } + if search_path.trim() == "" { + return true; + } - f.starts_with( - &format!( - "{}/", - search_path.strip_suffix('/').unwrap_or_else(|| search_path) - ), - ) + f.starts_with(&format!( + "{}/", + search_path.strip_suffix('/').unwrap_or_else(|| search_path) + )) }) .collect::>() }) + .map(|files| sort(files, req.sort.unwrap_or(NameAsc))) .inspect(|files| debug!("Found {:?} files", files.len())) .map(|tagged_files: Vec| { trace!( @@ -130,7 +132,7 @@ pub async fn list_photos( let excluded_tag_ids = &req .exclude_tag_ids .clone() - .unwrap_or(String::new()) + .unwrap_or_default() .split(',') .filter_map(|t| t.parse().ok()) .collect::>(); @@ -178,10 +180,10 @@ fn sort(mut files: Vec, sort_type: SortType) -> Vec { match sort_type { SortType::Shuffle => files.shuffle(&mut thread_rng()), SortType::NameAsc => { - files.sort_by(|l, r| l.cmp(&r)); + files.sort(); } SortType::NameDesc => { - files.sort_by(|l, r| r.cmp(&l)); + files.sort_by(|l, r| r.cmp(l)); } } @@ -393,15 +395,13 @@ mod tests { fn get_files_for_path(&self, path: &str) -> anyhow::Result> { if self.err { Err(anyhow!("Error for test")) + } else if let Some(files) = self.files.get(path) { + Ok(files + .iter() + .map(PathBuf::from) + .collect::>()) } else { - if let Some(files) = self.files.get(path) { - Ok(files - .iter() - .map(|p| PathBuf::from(p)) - .collect::>()) - } else { - Ok(Vec::new()) - } + Ok(Vec::new()) } } @@ -593,7 +593,7 @@ mod tests { ], ); - let request: Query = Query::from_query(&*format!( + let request: Query = Query::from_query(&format!( "path=&tag_ids={},{}&tag_filter_mode=All", tag1.id, tag3.id )) diff --git a/src/tags.rs b/src/tags.rs index 1c2d4c0..212ec7a 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -449,7 +449,7 @@ mod tests { let tag_id = self.tag_count; let tag = Tag { - id: tag_id as i32, + id: tag_id, name: name.to_string(), created_time: Utc::now().timestamp(), }; diff --git a/src/testhelpers.rs b/src/testhelpers.rs index e6097db..e288716 100644 --- a/src/testhelpers.rs +++ b/src/testhelpers.rs @@ -51,8 +51,7 @@ impl UserDao for TestUserDao { self.user_map .borrow() .iter() - .find(|&u| u.username == user) - .is_some() + .any(|u| u.username == user) } } diff --git a/src/video.rs b/src/video.rs index d593f90..b9112da 100644 --- a/src/video.rs +++ b/src/video.rs @@ -132,7 +132,7 @@ impl Handler for VideoPlaylistManager { .into_iter() .filter_map(|e| e.ok()) .filter(|e| e.file_type().is_file()) - .filter(|e| is_video(e)) + .filter(is_video) .collect::>(); let scan_dir_name = msg.directory.clone();