fix: Face processor now saves status and total_faces to face.json
This commit is contained in:
+107
-50
@@ -88,8 +88,7 @@ fn default_python_path() -> String {
|
||||
}
|
||||
|
||||
fn default_ffmpeg_path() -> String {
|
||||
std::env::var("MOMENTRY_FFMPEG")
|
||||
.unwrap_or_else(|_| "ffmpeg".to_string())
|
||||
std::env::var("MOMENTRY_FFMPEG").unwrap_or_else(|_| "ffmpeg".to_string())
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
@@ -160,9 +159,32 @@ pub struct AdminSettings {
|
||||
pub api_key_expiry_days: u32,
|
||||
#[serde(default = "default_system_stats_refresh_sec")]
|
||||
pub system_stats_refresh_sec: u32,
|
||||
#[serde(default = "default_preferred_language")]
|
||||
pub preferred_language: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct SearchConfig {
|
||||
#[serde(default = "default_vlm_min_score")]
|
||||
pub vlm_min_score: f64,
|
||||
}
|
||||
|
||||
impl Default for SearchConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
vlm_min_score: default_vlm_min_score(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn default_vlm_min_score() -> f64 {
|
||||
std::env::var("MOMENTRY_VLM_MIN_SCORE")
|
||||
.ok()
|
||||
.and_then(|v| v.parse().ok())
|
||||
.unwrap_or(0.0)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct FaceFilterDefaults {
|
||||
#[serde(default = "default_min_confidence")]
|
||||
pub min_confidence: f64,
|
||||
@@ -172,9 +194,25 @@ pub struct FaceFilterDefaults {
|
||||
pub min_capture_quality: f64,
|
||||
}
|
||||
|
||||
fn default_min_confidence() -> f64 { crate::core::config::FACE_MIN_CONFIDENCE_DEFAULT }
|
||||
fn default_min_size() -> i32 { crate::core::config::FACE_MIN_SIZE_DEFAULT }
|
||||
fn default_min_capture_quality() -> f64 { 0.25 }
|
||||
impl Default for FaceFilterDefaults {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
min_confidence: default_min_confidence(),
|
||||
min_size: default_min_size(),
|
||||
min_capture_quality: default_min_capture_quality(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn default_min_confidence() -> f64 {
|
||||
crate::core::config::FACE_FILTER_CONFIDENCE_PCT_DEFAULT
|
||||
}
|
||||
fn default_min_size() -> i32 {
|
||||
crate::core::config::FACE_MIN_SIZE_DEFAULT
|
||||
}
|
||||
fn default_min_capture_quality() -> f64 {
|
||||
0.25
|
||||
}
|
||||
|
||||
fn default_session_timeout() -> u32 {
|
||||
3600
|
||||
@@ -195,6 +233,11 @@ fn default_system_stats_refresh_sec() -> u32 {
|
||||
.unwrap_or(5)
|
||||
}
|
||||
|
||||
fn default_preferred_language() -> String {
|
||||
std::env::var("MOMENTRY_PREFERRED_LANGUAGE")
|
||||
.unwrap_or_else(|_| "zh-TW".to_string())
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
pub struct ServerConfig {
|
||||
#[serde(default = "default_server_port")]
|
||||
@@ -253,6 +296,8 @@ pub struct AdminConfig {
|
||||
pub server: ServerConfig,
|
||||
#[serde(default)]
|
||||
pub admin_settings: AdminSettings,
|
||||
#[serde(default)]
|
||||
pub search: SearchConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
|
||||
@@ -277,6 +322,8 @@ pub struct PartialAdminConfig {
|
||||
pub server: Option<ServerConfig>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub admin_settings: Option<AdminSettings>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub search: Option<SearchConfig>,
|
||||
}
|
||||
|
||||
pub struct AdminConfigManager {
|
||||
@@ -293,86 +340,91 @@ impl AdminConfigManager {
|
||||
config_path: config_path.to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
fn load_config(path: &str) -> Result<AdminConfig> {
|
||||
let content = std::fs::read_to_string(path)
|
||||
.with_context(|| format!("Failed to read config file: {}", path))?;
|
||||
let config: AdminConfig = serde_json::from_str(&content)
|
||||
.with_context(|| "Failed to parse config JSON")?;
|
||||
let config: AdminConfig =
|
||||
serde_json::from_str(&content).with_context(|| "Failed to parse config JSON")?;
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
|
||||
pub async fn get_vlm_prompt(&self, key: &str) -> Option<VlmPrompt> {
|
||||
let config = self.config.read().await;
|
||||
config.vlm_prompts.get(key).cloned()
|
||||
}
|
||||
|
||||
|
||||
pub async fn get_all_vlm_prompts(&self) -> HashMap<String, VlmPrompt> {
|
||||
let config = self.config.read().await;
|
||||
config.vlm_prompts.clone()
|
||||
}
|
||||
|
||||
|
||||
pub async fn get_llm_config(&self, key: &str) -> Option<LlmConfig> {
|
||||
let config = self.config.read().await;
|
||||
config.llm_config.get(key).cloned()
|
||||
}
|
||||
|
||||
|
||||
pub async fn get_processor_config(&self, key: &str) -> Option<ProcessorConfig> {
|
||||
let config = self.config.read().await;
|
||||
config.processor_config.get(key).cloned()
|
||||
}
|
||||
|
||||
|
||||
pub async fn get_filter_config(&self, key: &str) -> Option<FilterConfig> {
|
||||
let config = self.config.read().await;
|
||||
config.filter_config.get(key).cloned()
|
||||
}
|
||||
|
||||
|
||||
pub async fn get_paths(&self) -> PathsConfig {
|
||||
let config = self.config.read().await;
|
||||
config.paths.clone()
|
||||
}
|
||||
|
||||
|
||||
pub async fn get_concurrency(&self) -> ConcurrencyConfig {
|
||||
let config = self.config.read().await;
|
||||
config.concurrency.clone()
|
||||
}
|
||||
|
||||
|
||||
pub async fn get_feature_flags(&self) -> FeatureFlags {
|
||||
let config = self.config.read().await;
|
||||
config.feature_flags.clone()
|
||||
}
|
||||
|
||||
|
||||
pub async fn get_server(&self) -> ServerConfig {
|
||||
let config = self.config.read().await;
|
||||
config.server.clone()
|
||||
}
|
||||
|
||||
|
||||
pub async fn get_admin_settings(&self) -> AdminSettings {
|
||||
let config = self.config.read().await;
|
||||
config.admin_settings.clone()
|
||||
}
|
||||
|
||||
|
||||
pub async fn get_search(&self) -> SearchConfig {
|
||||
let config = self.config.read().await;
|
||||
config.search.clone()
|
||||
}
|
||||
|
||||
pub async fn get_full_config(&self) -> AdminConfig {
|
||||
let config = self.config.read().await;
|
||||
config.clone()
|
||||
}
|
||||
|
||||
|
||||
pub async fn update_vlm_prompt(&self, key: &str, prompt: VlmPrompt) -> Result<()> {
|
||||
let mut config = self.config.write().await;
|
||||
config.vlm_prompts.insert(key.to_string(), prompt);
|
||||
|
||||
|
||||
config.updated_at = chrono::Utc::now().to_rfc3339();
|
||||
config.updated_by = "admin".to_string();
|
||||
|
||||
|
||||
self.save_config(&config)?;
|
||||
|
||||
|
||||
tracing::info!("[AdminConfig] Updated VLM prompt: {}", key);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
pub async fn update_partial_config(&self, partial: PartialAdminConfig) -> Result<()> {
|
||||
let mut config = self.config.write().await;
|
||||
|
||||
|
||||
if let Some(vlm_prompts) = partial.vlm_prompts {
|
||||
config.vlm_prompts.extend(vlm_prompts);
|
||||
}
|
||||
@@ -403,28 +455,31 @@ impl AdminConfigManager {
|
||||
if let Some(admin_settings) = partial.admin_settings {
|
||||
config.admin_settings = admin_settings;
|
||||
}
|
||||
|
||||
if let Some(search) = partial.search {
|
||||
config.search = search;
|
||||
}
|
||||
|
||||
config.updated_at = chrono::Utc::now().to_rfc3339();
|
||||
config.updated_by = "admin".to_string();
|
||||
|
||||
|
||||
self.save_config(&config)?;
|
||||
|
||||
|
||||
tracing::info!("[AdminConfig] Updated partial config");
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
pub async fn reload(&self) -> Result<()> {
|
||||
let new_config = Self::load_config(&self.config_path)?;
|
||||
let mut config = self.config.write().await;
|
||||
*config = new_config;
|
||||
|
||||
|
||||
tracing::info!("[AdminConfig] Reloaded config from {}", self.config_path);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
fn save_config(&self, config: &AdminConfig) -> Result<()> {
|
||||
let content = serde_json::to_string_pretty(config)
|
||||
.with_context(|| "Failed to serialize config")?;
|
||||
let content =
|
||||
serde_json::to_string_pretty(config).with_context(|| "Failed to serialize config")?;
|
||||
std::fs::write(&self.config_path, content)
|
||||
.with_context(|| format!("Failed to write config file: {}", self.config_path))?;
|
||||
Ok(())
|
||||
@@ -435,19 +490,22 @@ pub fn get_default_config_path() -> String {
|
||||
let mut path = std::env::current_dir().unwrap_or_else(|_| std::path::PathBuf::from("."));
|
||||
path.push("config");
|
||||
path.push("admin_config.json");
|
||||
path.to_str().unwrap_or("config/admin_config.json").to_string()
|
||||
path.to_str()
|
||||
.unwrap_or("config/admin_config.json")
|
||||
.to_string()
|
||||
}
|
||||
|
||||
pub static ADMIN_CONFIG: once_cell::sync::Lazy<Arc<AdminConfigManager>> = once_cell::sync::Lazy::new(|| {
|
||||
let config_path = get_default_config_path();
|
||||
match AdminConfigManager::new(&config_path) {
|
||||
Ok(manager) => Arc::new(manager),
|
||||
Err(e) => {
|
||||
error!("[AdminConfig] Failed to initialize: {}", e);
|
||||
panic!("Failed to initialize AdminConfigManager: {}", e);
|
||||
pub static ADMIN_CONFIG: once_cell::sync::Lazy<Arc<AdminConfigManager>> =
|
||||
once_cell::sync::Lazy::new(|| {
|
||||
let config_path = get_default_config_path();
|
||||
match AdminConfigManager::new(&config_path) {
|
||||
Ok(manager) => Arc::new(manager),
|
||||
Err(e) => {
|
||||
error!("[AdminConfig] Failed to initialize: {}", e);
|
||||
panic!("Failed to initialize AdminConfigManager: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
pub async fn get_vlm_prompt(key: &str) -> Option<VlmPrompt> {
|
||||
ADMIN_CONFIG.get_vlm_prompt(key).await
|
||||
@@ -471,7 +529,7 @@ pub fn get_face_filter_defaults() -> (f64, i32, f64) {
|
||||
// Try to read without blocking - use try_read for non-blocking access
|
||||
// If config is locked, fall back to hardcoded defaults
|
||||
let config = ADMIN_CONFIG.config.try_read();
|
||||
|
||||
|
||||
match config {
|
||||
Ok(cfg) => (
|
||||
cfg.face_filter_defaults.min_confidence,
|
||||
@@ -481,9 +539,9 @@ pub fn get_face_filter_defaults() -> (f64, i32, f64) {
|
||||
Err(_) => {
|
||||
// Config locked, use hardcoded defaults
|
||||
(
|
||||
crate::core::config::FACE_MIN_CONFIDENCE_DEFAULT,
|
||||
crate::core::config::FACE_FILTER_CONFIDENCE_PCT_DEFAULT,
|
||||
crate::core::config::FACE_MIN_SIZE_DEFAULT,
|
||||
0.25, // min_capture_quality default
|
||||
0.25, // min_capture_quality default
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -515,8 +573,7 @@ pub fn get_paths_sync() -> PathsConfig {
|
||||
.unwrap_or_else(|_| "/Users/accusys/momentry_core_0.1/scripts".to_string()),
|
||||
python_path: std::env::var("MOMENTRY_PYTHON_PATH")
|
||||
.unwrap_or_else(|_| "/opt/homebrew/bin/python3.11".to_string()),
|
||||
ffmpeg_path: std::env::var("MOMENTRY_FFMPEG")
|
||||
.unwrap_or_else(|_| "ffmpeg".to_string()),
|
||||
ffmpeg_path: std::env::var("MOMENTRY_FFMPEG").unwrap_or_else(|_| "ffmpeg".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -559,4 +616,4 @@ pub fn get_concurrency_sync() -> ConcurrencyConfig {
|
||||
.and_then(|v| v.parse().ok())
|
||||
.unwrap_or(3600),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user