diff --git a/src/data/mod.rs b/src/data/mod.rs index ed9cc5f..23d5844 100644 --- a/src/data/mod.rs +++ b/src/data/mod.rs @@ -105,6 +105,7 @@ pub struct FilesRequest { pub path: String, pub tag_ids: Option, // comma separated numbers pub tag_filter_mode: Option, + pub recursive: Option, } #[derive(Copy, Clone, Deserialize, PartialEq)] diff --git a/src/files.rs b/src/files.rs index 031420d..d7ea0dd 100644 --- a/src/files.rs +++ b/src/files.rs @@ -35,7 +35,9 @@ pub async fn list_photos( ) -> HttpResponse { let path = &req.path; + // Do we need this? if let (Some(tag_ids), Some(filter_mode)) = (&req.tag_ids, &req.tag_filter_mode) { + let search_recursively = &req.recursive.unwrap_or(false); if *filter_mode == FilterMode::All { let mut dao = tag_dao.lock().expect("Unable to get TagDao"); let tag_ids = tag_ids @@ -45,10 +47,15 @@ pub async fn list_photos( return dao .get_files_with_tag_ids(tag_ids.clone()) - .context(format!("Failed to files with tag_ids: {:?}", tag_ids)) + .context(format!("Failed to get files with tag_ids: {:?}", tag_ids)) .map(|tagged_files| { HttpResponse::Ok().json(PhotosResponse { - photos: tagged_files, + photos: tagged_files.iter().filter(|&file_path| { + let slash_count = file_path.split('/').count(); + let search_path_slash_count = path.split('/').count(); + + slash_count > search_path_slash_count + }).map(|p| p.clone()).collect::>(), dirs: vec![], }) }) @@ -77,6 +84,12 @@ pub async fn list_photos( }) .map(|f| f.to_str().unwrap().to_string()) .filter(|file_path| { + let recursive = req.recursive.unwrap_or(false); + let file_slash_count = file_path.split("/").collect::>().len(); + let filter_path_slash_count = path.split("/").collect::>().len(); + // Skip if this path is below/deeper than the search path + if !recursive && file_slash_count > filter_path_slash_count { return false; } + if let (Some(tag_ids), Ok(mut tag_dao)) = (&req.tag_ids, tag_dao.lock()) { let tag_ids = tag_ids .split(',')