Add Exif storing and update to Metadata endpoint
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use std::{fs, str::FromStr};
|
||||
|
||||
use anyhow::{Context, anyhow};
|
||||
use crate::database::models::ImageExif;
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use log::error;
|
||||
@@ -173,6 +174,7 @@ pub struct MetadataResponse {
|
||||
pub created: Option<i64>,
|
||||
pub modified: Option<i64>,
|
||||
pub size: u64,
|
||||
pub exif: Option<ExifMetadata>,
|
||||
}
|
||||
|
||||
impl From<fs::Metadata> for MetadataResponse {
|
||||
@@ -187,6 +189,95 @@ impl From<fs::Metadata> for MetadataResponse {
|
||||
utc.timestamp()
|
||||
}),
|
||||
size: metadata.len(),
|
||||
exif: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct ExifMetadata {
|
||||
pub camera: Option<CameraInfo>,
|
||||
pub image_properties: Option<ImageProperties>,
|
||||
pub gps: Option<GpsCoordinates>,
|
||||
pub capture_settings: Option<CaptureSettings>,
|
||||
pub date_taken: Option<i64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct CameraInfo {
|
||||
pub make: Option<String>,
|
||||
pub model: Option<String>,
|
||||
pub lens: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct ImageProperties {
|
||||
pub width: Option<i32>,
|
||||
pub height: Option<i32>,
|
||||
pub orientation: Option<i32>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct GpsCoordinates {
|
||||
pub latitude: Option<f64>,
|
||||
pub longitude: Option<f64>,
|
||||
pub altitude: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
pub struct CaptureSettings {
|
||||
pub focal_length: Option<f64>,
|
||||
pub aperture: Option<f64>,
|
||||
pub shutter_speed: Option<String>,
|
||||
pub iso: Option<i32>,
|
||||
}
|
||||
|
||||
impl From<ImageExif> for ExifMetadata {
|
||||
fn from(exif: ImageExif) -> Self {
|
||||
let has_camera_info = exif.camera_make.is_some() || exif.camera_model.is_some() || exif.lens_model.is_some();
|
||||
let has_image_properties = exif.width.is_some() || exif.height.is_some() || exif.orientation.is_some();
|
||||
let has_gps = exif.gps_latitude.is_some() || exif.gps_longitude.is_some() || exif.gps_altitude.is_some();
|
||||
let has_capture_settings = exif.focal_length.is_some() || exif.aperture.is_some() || exif.shutter_speed.is_some() || exif.iso.is_some();
|
||||
|
||||
ExifMetadata {
|
||||
camera: if has_camera_info {
|
||||
Some(CameraInfo {
|
||||
make: exif.camera_make,
|
||||
model: exif.camera_model,
|
||||
lens: exif.lens_model,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
},
|
||||
image_properties: if has_image_properties {
|
||||
Some(ImageProperties {
|
||||
width: exif.width,
|
||||
height: exif.height,
|
||||
orientation: exif.orientation,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
},
|
||||
gps: if has_gps {
|
||||
Some(GpsCoordinates {
|
||||
latitude: exif.gps_latitude,
|
||||
longitude: exif.gps_longitude,
|
||||
altitude: exif.gps_altitude,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
},
|
||||
capture_settings: if has_capture_settings {
|
||||
Some(CaptureSettings {
|
||||
focal_length: exif.focal_length,
|
||||
aperture: exif.aperture,
|
||||
shutter_speed: exif.shutter_speed,
|
||||
iso: exif.iso,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
},
|
||||
date_taken: exif.date_taken,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user