diff --git a/src/api/mod.rs b/src/api/mod.rs index d5804e3..d3d36b6 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -4,6 +4,7 @@ pub mod auth; pub mod docs; pub mod files; pub mod five_w1h_agent_api; +pub mod processing; pub mod health; pub mod identities; pub mod identity_agent_api; diff --git a/src/api/processing.rs b/src/api/processing.rs index 0b48435..ae88750 100644 --- a/src/api/processing.rs +++ b/src/api/processing.rs @@ -110,7 +110,7 @@ struct ProcessRequest { processors: Option>, } -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, Deserialize)] struct ProgressResponse { file_uuid: String, user: Option, @@ -126,7 +126,7 @@ struct ProgressResponse { processors: Vec, } -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, Deserialize)] struct SystemHealthInfo { cpu_idle_pct: f64, memory_available_mb: u64, @@ -140,7 +140,7 @@ struct SystemHealthInfo { running_processors: u32, } -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, Deserialize)] struct ProcessorProgressInfo { name: String, status: String, @@ -281,19 +281,17 @@ async fn download_json( let output_dir = std::env::var("MOMENTRY_OUTPUT_DIR") .unwrap_or_else(|_| "/Users/accusys/momentry/output_dev".to_string()); let path = std::path::Path::new(&output_dir).join(format!("{}.{}.json", file_uuid, processor)); - match tokio::fs::read_to_string(&path).await { - Ok(content) => serde_json::from_str(&content).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR), - Err(_) => Err(StatusCode::NOT_FOUND), - } + let content = tokio::fs::read_to_string(&path).await.map_err(|_| StatusCode::NOT_FOUND)?; + Ok(Json(serde_json::from_str(&content).map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?)) } async fn get_chunk_by_path( State(state): State, Path((file_uuid, chunk_id)): Path<(String, String)>, -) -> Result, StatusCode> { +) -> Result, StatusCode> { let table = schema::table_name("chunk"); - let chunk: Option = sqlx::query_as(&format!( - "SELECT * FROM {} WHERE uuid = $1 AND chunk_id = $2", + let row: Option = sqlx::query_scalar(&format!( + "SELECT row_to_json(t) FROM (SELECT * FROM {} WHERE uuid = $1 AND chunk_id = $2) t", table )) .bind(&file_uuid) @@ -302,7 +300,7 @@ async fn get_chunk_by_path( .await .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?; - chunk.ok_or(StatusCode::NOT_FOUND) + row.map(Json).ok_or(StatusCode::NOT_FOUND) } async fn get_progress( @@ -354,7 +352,7 @@ async fn get_progress( cpu_percent: cpu, gpu_percent: gpu, memory_percent: mem_pct, - memory_mb, + memory_mb: mem_mb, system: Some(sys), processors, })) @@ -461,10 +459,6 @@ async fn cache_toggle( Json(req): Json, ) -> Json { crate::core::config::set_cache_enabled(req.enabled); - if !req.enabled { - let _ = state.mongo_cache.flush_all().await; - let _ = state.redis_cache.flush().await; - } Json(CacheToggleResponse { success: true, cache_enabled: req.enabled, diff --git a/src/api/server.rs b/src/api/server.rs index 7497bf5..1fdd558 100644 --- a/src/api/server.rs +++ b/src/api/server.rs @@ -14,6 +14,7 @@ use super::auth; use super::docs; use super::files; use super::five_w1h_agent_api; +use super::processing; use super::health; use super::identities; use super::identity_agent_api; @@ -106,6 +107,7 @@ pub async fn start_server(host: &str, port: u16) -> anyhow::Result<()> { .merge(identity_api::identity_routes()) .merge(agent_api::agent_routes()) .merge(agent_search::agent_search_routes()) + .merge(processing::processing_routes()) .merge(identity_agent_api::identity_agent_routes()) .merge(five_w1h_agent_api::five_w1h_agent_routes()) .merge(media_api::bbox_routes())