diff --git a/src/files.rs b/src/files.rs index df2a233..db96067 100644 --- a/src/files.rs +++ b/src/files.rs @@ -32,7 +32,7 @@ pub async fn list_photos( file_system: web::Data, tag_dao: web::Data>, ) -> HttpResponse { - let path = &req.path; + let search_path = &req.path; let search_recursively = req.recursive.unwrap_or(false); if let Some(tag_ids) = &req.tag_ids { @@ -40,7 +40,7 @@ pub async fn list_photos( let filter_mode = req.tag_filter_mode.unwrap_or(FilterMode::Any); debug!( "Searching for tags: {}. With path: '{}' and filter mode: {:?}", - tag_ids, path, filter_mode + tag_ids, search_path, filter_mode ); let mut dao = tag_dao.lock().expect("Unable to get TagDao"); @@ -53,10 +53,18 @@ pub async fn list_photos( .get_files_with_any_tag_ids(tag_ids.clone()) .context(format!("Failed to get files with tag_ids: {:?}", tag_ids)) .map(|tagged_files| match filter_mode { - FilterMode::Any => tagged_files, + FilterMode::Any => tagged_files + .iter() + .filter(|file| file.starts_with(search_path)) + .cloned() + .collect(), FilterMode::All => tagged_files .iter() .filter(|&file_path| { + if !file_path.starts_with(search_path) { + return false; + } + let file_tags = dao.get_tags_for_path(file_path).unwrap_or_default(); tag_ids .iter() @@ -78,8 +86,8 @@ pub async fn list_photos( } } - if let Ok(files) = file_system.get_files_for_path(path) { - debug!("Valid search path: {:?}", path); + if let Ok(files) = file_system.get_files_for_path(search_path) { + debug!("Valid search path: {:?}", search_path); let photos = files .iter()