feature/exif-endpoint #44
48
src/files.rs
48
src/files.rs
@@ -261,7 +261,53 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
|
||||
})
|
||||
.collect::<Vec<FileWithTagCount>>()
|
||||
})
|
||||
.map(|files| sort(files, req.sort.unwrap_or(NameAsc)))
|
||||
.map(|files| {
|
||||
// Handle sorting - use FileWithMetadata for date sorting to support EXIF dates
|
||||
let sort_type = req.sort.unwrap_or(NameAsc);
|
||||
match sort_type {
|
||||
SortType::DateTakenAsc | SortType::DateTakenDesc => {
|
||||
info!("Date sorting requested in tagged/recursive search, fetching EXIF data");
|
||||
|
||||
// Collect file paths for batch EXIF query
|
||||
let file_paths: Vec<String> =
|
||||
files.iter().map(|f| f.file_name.clone()).collect();
|
||||
|
||||
// Batch fetch EXIF data
|
||||
let mut exif_dao_guard = exif_dao.lock().expect("Unable to get ExifDao");
|
||||
let exif_map: std::collections::HashMap<String, i64> = exif_dao_guard
|
||||
.get_exif_batch(&file_paths)
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.filter_map(|exif| exif.date_taken.map(|dt| (exif.file_path, dt)))
|
||||
.collect();
|
||||
drop(exif_dao_guard);
|
||||
|
||||
// Convert to FileWithMetadata with date fallback logic
|
||||
let files_with_metadata: Vec<FileWithMetadata> = files
|
||||
.into_iter()
|
||||
.map(|f| {
|
||||
// Try EXIF date first
|
||||
let date_taken = exif_map.get(&f.file_name).copied().or_else(|| {
|
||||
// Fallback to filename extraction
|
||||
extract_date_from_filename(&f.file_name).map(|dt| dt.timestamp())
|
||||
});
|
||||
|
||||
FileWithMetadata {
|
||||
file_name: f.file_name,
|
||||
tag_count: f.tag_count,
|
||||
date_taken,
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
|
||||
sort_with_metadata(files_with_metadata, sort_type)
|
||||
}
|
||||
_ => {
|
||||
// Use regular sort for non-date sorting
|
||||
sort(files, sort_type)
|
||||
}
|
||||
}
|
||||
})
|
||||
.inspect(|files| debug!("Found {:?} files", files.len()))
|
||||
.map(|tagged_files: Vec<String>| {
|
||||
info!(
|
||||
|
||||
Reference in New Issue
Block a user