Refactor file type checking for better consistency
Fix tests
This commit is contained in:
43
src/main.rs
43
src/main.rs
@@ -54,6 +54,7 @@ mod data;
|
||||
mod database;
|
||||
mod error;
|
||||
mod exif;
|
||||
mod file_types;
|
||||
mod files;
|
||||
mod geo;
|
||||
mod state;
|
||||
@@ -142,14 +143,8 @@ async fn get_image(
|
||||
}
|
||||
|
||||
fn is_video_file(path: &Path) -> bool {
|
||||
if let Some(extension) = path.extension() {
|
||||
matches!(
|
||||
extension.to_str().unwrap_or("").to_lowercase().as_str(),
|
||||
"mp4" | "mov" | "avi" | "mkv"
|
||||
)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
use image_api::file_types;
|
||||
file_types::is_video_file(path)
|
||||
}
|
||||
|
||||
#[get("/image/metadata")]
|
||||
@@ -176,9 +171,10 @@ async fn get_file_metadata(
|
||||
|
||||
// Query EXIF data if available
|
||||
if let Ok(mut dao) = exif_dao.lock()
|
||||
&& let Ok(Some(exif)) = dao.get_exif(&path.path) {
|
||||
response.exif = Some(exif.into());
|
||||
}
|
||||
&& let Ok(Some(exif)) = dao.get_exif(&path.path)
|
||||
{
|
||||
response.exif = Some(exif.into());
|
||||
}
|
||||
|
||||
span.add_event(
|
||||
"Metadata fetched",
|
||||
@@ -678,23 +674,13 @@ fn update_media_counts(media_dir: &Path) {
|
||||
}
|
||||
|
||||
fn is_image(entry: &DirEntry) -> bool {
|
||||
entry
|
||||
.path()
|
||||
.extension()
|
||||
.and_then(|ext| ext.to_str())
|
||||
.map(|ext| ext.to_lowercase())
|
||||
.map(|ext| ext == "jpg" || ext == "jpeg" || ext == "png" || ext == "nef")
|
||||
.unwrap_or(false)
|
||||
use image_api::file_types;
|
||||
file_types::direntry_is_image(entry)
|
||||
}
|
||||
|
||||
fn is_video(entry: &DirEntry) -> bool {
|
||||
entry
|
||||
.path()
|
||||
.extension()
|
||||
.and_then(|ext| ext.to_str())
|
||||
.map(|ext| ext.to_lowercase())
|
||||
.map(|ext| ext == "mp4" || ext == "mov")
|
||||
.unwrap_or(false)
|
||||
use image_api::file_types;
|
||||
file_types::direntry_is_video(entry)
|
||||
}
|
||||
|
||||
fn main() -> std::io::Result<()> {
|
||||
@@ -903,9 +889,10 @@ fn process_new_files(
|
||||
// Filter by modification time if specified
|
||||
if let Some(since) = modified_since {
|
||||
if let Ok(metadata) = entry.metadata()
|
||||
&& let Ok(modified) = metadata.modified() {
|
||||
return modified >= since;
|
||||
}
|
||||
&& let Ok(modified) = metadata.modified()
|
||||
{
|
||||
return modified >= since;
|
||||
}
|
||||
// If we can't get metadata, include the file to be safe
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user