Fallback to sorting by Metadata date
This commit is contained in:
15
src/files.rs
15
src/files.rs
@@ -51,6 +51,7 @@ fn apply_sorting_with_exif(
|
|||||||
sort_type: SortType,
|
sort_type: SortType,
|
||||||
exif_dao: &mut Box<dyn ExifDao>,
|
exif_dao: &mut Box<dyn ExifDao>,
|
||||||
span_context: &opentelemetry::Context,
|
span_context: &opentelemetry::Context,
|
||||||
|
base_path: &Path,
|
||||||
) -> Vec<String> {
|
) -> Vec<String> {
|
||||||
match sort_type {
|
match sort_type {
|
||||||
SortType::DateTakenAsc | SortType::DateTakenDesc => {
|
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(|| {
|
let date_taken = exif_map.get(&f.file_name).copied().or_else(|| {
|
||||||
// Fallback to filename extraction
|
// Fallback to filename extraction
|
||||||
extract_date_from_filename(&f.file_name).map(|dt| dt.timestamp())
|
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 {
|
FileWithMetadata {
|
||||||
@@ -324,7 +333,7 @@ pub async fn list_photos<TagD: TagDao, FS: FileSystemAccess>(
|
|||||||
let sort_type = req.sort.unwrap_or(NameAsc);
|
let sort_type = req.sort.unwrap_or(NameAsc);
|
||||||
let mut exif_dao_guard = exif_dao.lock().expect("Unable to get ExifDao");
|
let mut exif_dao_guard = exif_dao.lock().expect("Unable to get ExifDao");
|
||||||
let result =
|
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);
|
drop(exif_dao_guard);
|
||||||
result
|
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 response_files = if let Some(sort_type) = req.sort {
|
||||||
let mut exif_dao_guard = exif_dao.lock().expect("Unable to get ExifDao");
|
let mut exif_dao_guard = exif_dao.lock().expect("Unable to get ExifDao");
|
||||||
let result =
|
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);
|
drop(exif_dao_guard);
|
||||||
result
|
result
|
||||||
} else {
|
} else {
|
||||||
@@ -875,7 +884,7 @@ mod tests {
|
|||||||
|
|
||||||
struct MockExifDao;
|
struct MockExifDao;
|
||||||
|
|
||||||
impl crate::database::ExifDao for MockExifDao {
|
impl ExifDao for MockExifDao {
|
||||||
fn store_exif(
|
fn store_exif(
|
||||||
&mut self,
|
&mut self,
|
||||||
_context: &opentelemetry::Context,
|
_context: &opentelemetry::Context,
|
||||||
|
|||||||
Reference in New Issue
Block a user