From fa600f1c2cf705457fc6019d56fb26fe3f61ff90 Mon Sep 17 00:00:00 2001 From: Cameron Date: Sun, 11 Jan 2026 14:39:50 -0500 Subject: [PATCH] Fallback to sorting by Metadata date --- src/files.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/files.rs b/src/files.rs index 785a219..600445f 100644 --- a/src/files.rs +++ b/src/files.rs @@ -51,6 +51,7 @@ fn apply_sorting_with_exif( sort_type: SortType, exif_dao: &mut Box, span_context: &opentelemetry::Context, + base_path: &Path, ) -> Vec { match sort_type { SortType::DateTakenAsc | SortType::DateTakenDesc => { @@ -75,6 +76,14 @@ fn apply_sorting_with_exif( 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()) + }).or_else(|| { + // Fallback to filesystem metadata creation date + let full_path = base_path.join(&f.file_name); + std::fs::metadata(full_path) + .and_then(|md| md.created()) + .ok() + .and_then(|ct| ct.duration_since(std::time::UNIX_EPOCH).ok()) + .map(|d| d.as_secs() as i64) }); FileWithMetadata { @@ -324,7 +333,7 @@ pub async fn list_photos( let sort_type = req.sort.unwrap_or(NameAsc); let mut exif_dao_guard = exif_dao.lock().expect("Unable to get ExifDao"); let result = - apply_sorting_with_exif(files, sort_type, &mut exif_dao_guard, &span_context); + apply_sorting_with_exif(files, sort_type, &mut exif_dao_guard, &span_context, (&app_state.base_path).as_ref()); drop(exif_dao_guard); result }) @@ -468,7 +477,7 @@ pub async fn list_photos( let response_files = if let Some(sort_type) = req.sort { let mut exif_dao_guard = exif_dao.lock().expect("Unable to get ExifDao"); let result = - apply_sorting_with_exif(photos, sort_type, &mut exif_dao_guard, &span_context); + apply_sorting_with_exif(photos, sort_type, &mut exif_dao_guard, &span_context, (&app_state.base_path).as_ref()); drop(exif_dao_guard); result } else { @@ -875,7 +884,7 @@ mod tests { struct MockExifDao; - impl crate::database::ExifDao for MockExifDao { + impl ExifDao for MockExifDao { fn store_exif( &mut self, _context: &opentelemetry::Context,