use axum::extract::Path; use axum::routing::post; use axum::{Json, Router}; use serde_json::{json, Value}; use crate::core::config; use crate::core::db::postgres_db::PostgresDb; use crate::core::pipeline as pipeline_core; async fn handle_store_asrx( Path(uuid): Path, ) -> Result, (axum::http::StatusCode, Json)> { let db = PostgresDb::new(&config::DATABASE_URL).await.map_err(|e| { tracing::error!("DB error: {}", e); ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": "DB connection failed"})), ) })?; pipeline_core::store_asrx_chunks(&db, &uuid) .await .map_err(|e| { tracing::error!("store_asrx error: {}", e); ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()})), ) })?; Ok(Json( json!({"success": true, "message": "ASRX chunks stored", "file_uuid": uuid}), )) } async fn handle_rule1( Path(uuid): Path, ) -> Result, (axum::http::StatusCode, Json)> { let db = PostgresDb::new(&config::DATABASE_URL).await.map_err(|e| { tracing::error!("DB error: {}", e); ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": "DB connection failed"})), ) })?; let count = pipeline_core::execute_rule1(&db, &uuid) .await .map_err(|e| { tracing::error!("rule1 error: {}", e); ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()})), ) })?; Ok(Json( json!({"success": true, "message": format!("Rule 1 complete: {} chunks", count), "file_uuid": uuid, "chunks": count}), )) } async fn handle_vectorize( Path(uuid): Path, ) -> Result, (axum::http::StatusCode, Json)> { pipeline_core::vectorize_chunks(&uuid).await.map_err(|e| { tracing::error!("vectorize error: {}", e); ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()})), ) })?; Ok(Json( json!({"success": true, "message": "Vectorization complete", "file_uuid": uuid}), )) } async fn handle_phase1( Path(uuid): Path, ) -> Result, (axum::http::StatusCode, Json)> { pipeline_core::run_phase1(&uuid).await.map_err(|e| { tracing::error!("phase1 error: {}", e); ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()})), ) })?; Ok(Json( json!({"success": true, "message": "Phase 1 complete", "file_uuid": uuid}), )) } async fn handle_complete( Path(uuid): Path, ) -> Result, (axum::http::StatusCode, Json)> { let db = PostgresDb::new(&config::DATABASE_URL).await.map_err(|e| { tracing::error!("DB error: {}", e); ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": "DB connection failed"})), ) })?; pipeline_core::mark_complete(&db, &uuid) .await .map_err(|e| { tracing::error!("complete error: {}", e); ( axum::http::StatusCode::INTERNAL_SERVER_ERROR, Json(json!({"error": e.to_string()})), ) })?; Ok(Json( json!({"success": true, "message": "Video marked as completed", "file_uuid": uuid}), )) } pub fn pipeline_routes() -> Router { Router::new() .route( "/api/v1/file/:file_uuid/store-asrx", post(handle_store_asrx), ) .route("/api/v1/file/:file_uuid/rule1", post(handle_rule1)) .route("/api/v1/file/:file_uuid/vectorize", post(handle_vectorize)) .route("/api/v1/file/:file_uuid/phase1", post(handle_phase1)) .route("/api/v1/file/:file_uuid/complete", post(handle_complete)) }