Fallback to sorting by Metadata date

This commit is contained in:
Cameron
2026-01-11 14:39:50 -05:00
parent 0efa8269a1
commit fa600f1c2c

View File

@@ -51,6 +51,7 @@ fn apply_sorting_with_exif(
sort_type: SortType,
exif_dao: &mut Box<dyn ExifDao>,
span_context: &opentelemetry::Context,
base_path: &Path,
) -> Vec<String> {
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<TagD: TagDao, FS: FileSystemAccess>(
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<TagD: TagDao, FS: FileSystemAccess>(
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,