Recursive Sorting fix and many logging/tracing enhancements #33

Merged
cameron merged 11 commits from feature/fix-recursive-sort into master 2025-06-12 20:03:21 +00:00
Showing only changes of commit 7c882fd31c - Show all commits

View File

@@ -47,7 +47,7 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
if let Some(tag_ids) = &req.tag_ids { if let Some(tag_ids) = &req.tag_ids {
if search_recursively { if search_recursively {
let filter_mode = &req.tag_filter_mode.unwrap_or(FilterMode::Any); let filter_mode = &req.tag_filter_mode.unwrap_or(FilterMode::Any);
debug!( info!(
"Searching for tags: {}. With path: '{}' and filter mode: {:?}", "Searching for tags: {}. With path: '{}' and filter mode: {:?}",
tag_ids, search_path, filter_mode tag_ids, search_path, filter_mode
); );
@@ -75,7 +75,7 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
tag_ids, filter_mode tag_ids, filter_mode
)) ))
.inspect(|files| { .inspect(|files| {
debug!( info!(
"Found {:?} tagged files, filtering down by search path {:?}", "Found {:?} tagged files, filtering down by search path {:?}",
files.len(), files.len(),
search_path search_path
@@ -100,7 +100,7 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
.map(|files| sort(files, req.sort.unwrap_or(NameAsc))) .map(|files| sort(files, req.sort.unwrap_or(NameAsc)))
.inspect(|files| debug!("Found {:?} files", files.len())) .inspect(|files| debug!("Found {:?} files", files.len()))
.map(|tagged_files: Vec<String>| { .map(|tagged_files: Vec<String>| {
trace!( info!(
"Found {:?} tagged files: {:?}", "Found {:?} tagged files: {:?}",
tagged_files.len(), tagged_files.len(),
tagged_files tagged_files
@@ -119,7 +119,7 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
} }
if let Ok(files) = file_system.get_files_for_path(search_path) { if let Ok(files) = file_system.get_files_for_path(search_path) {
debug!("Valid search path: {:?}", search_path); info!("Found {:?} files in path: {:?}", files.len(), search_path);
let photos = files let photos = files
.iter() .iter()
@@ -240,6 +240,7 @@ pub fn list_files(dir: &Path) -> io::Result<Vec<PathBuf>> {
let mut span = tracer.start("list_files"); let mut span = tracer.start("list_files");
let dir_name_string = dir.to_str().unwrap_or_default().to_string(); let dir_name_string = dir.to_str().unwrap_or_default().to_string();
span.set_attribute(KeyValue::new("dir", dir_name_string)); span.set_attribute(KeyValue::new("dir", dir_name_string));
info!("Listing files in: {:?}", dir);
let files = read_dir(dir)? let files = read_dir(dir)?
.filter_map(|res| res.ok()) .filter_map(|res| res.ok())
@@ -248,6 +249,7 @@ pub fn list_files(dir: &Path) -> io::Result<Vec<PathBuf>> {
.collect::<Vec<PathBuf>>(); .collect::<Vec<PathBuf>>();
span.set_attribute(KeyValue::new("file_count", files.len().to_string())); span.set_attribute(KeyValue::new("file_count", files.len().to_string()));
info!("Found {:?} files in directory: {:?}", files.len(), dir);
Ok(files) Ok(files)
} }
@@ -263,6 +265,7 @@ pub fn is_image_or_video(path: &Path) -> bool {
|| extension == "mp4" || extension == "mp4"
|| extension == "mov" || extension == "mov"
|| extension == "nef" || extension == "nef"
|| extension == "webp"
} }
pub fn is_valid_full_path<P: AsRef<Path> + Debug + AsRef<std::ffi::OsStr>>( pub fn is_valid_full_path<P: AsRef<Path> + Debug + AsRef<std::ffi::OsStr>>(
@@ -319,6 +322,8 @@ pub async fn move_file<FS: FileSystemAccess>(
app_state: Data<AppState>, app_state: Data<AppState>,
request: web::Json<MoveFileRequest>, request: web::Json<MoveFileRequest>,
) -> HttpResponse { ) -> HttpResponse {
info!("Moving file: {:?}", request);
match is_valid_full_path(&app_state.base_path, &request.source, false) match is_valid_full_path(&app_state.base_path, &request.source, false)
.ok_or(ErrorKind::InvalidData) .ok_or(ErrorKind::InvalidData)
.and_then(|source| { .and_then(|source| {
@@ -358,7 +363,7 @@ pub async fn move_file<FS: FileSystemAccess>(
} }
} }
#[derive(Deserialize)] #[derive(Deserialize, Debug)]
pub struct MoveFileRequest { pub struct MoveFileRequest {
source: String, source: String,
destination: String, destination: String,