Add basic recursive tag searching support based on the search path
This commit is contained in:
@@ -105,6 +105,7 @@ pub struct FilesRequest {
|
||||
pub path: String,
|
||||
pub tag_ids: Option<String>, // comma separated numbers
|
||||
pub tag_filter_mode: Option<FilterMode>,
|
||||
pub recursive: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Deserialize, PartialEq)]
|
||||
|
||||
17
src/files.rs
17
src/files.rs
@@ -35,7 +35,9 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
|
||||
) -> 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<TagD: TagDao, FS: FileSystemAccess>(
|
||||
|
||||
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::<Vec<String>>(),
|
||||
dirs: vec![],
|
||||
})
|
||||
})
|
||||
@@ -77,6 +84,12 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
|
||||
})
|
||||
.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::<Vec<&str>>().len();
|
||||
let filter_path_slash_count = path.split("/").collect::<Vec<&str>>().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(',')
|
||||
|
||||
Reference in New Issue
Block a user