feat: add cache toggle, unregister API and chunk training docs
- Add POST /api/v1/config/cache for cache toggle - Add POST /api/v1/unregister for video deletion - Add CHUNK_DATA_STRUCTURE.md for marcom training - Fix processor_results query in delete_video
This commit is contained in:
@@ -148,6 +148,30 @@ struct SearchRequest {
|
||||
uuid: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct CacheToggleRequest {
|
||||
enabled: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct CacheToggleResponse {
|
||||
success: bool,
|
||||
cache_enabled: bool,
|
||||
message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
struct UnregisterRequest {
|
||||
uuid: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
struct UnregisterResponse {
|
||||
success: bool,
|
||||
uuid: String,
|
||||
message: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
struct SearchResult {
|
||||
uuid: String,
|
||||
@@ -1300,6 +1324,56 @@ async fn get_job(
|
||||
Ok(Json(response))
|
||||
}
|
||||
|
||||
async fn cache_toggle(
|
||||
State(_state): State<AppState>,
|
||||
Json(req): Json<CacheToggleRequest>,
|
||||
) -> Result<Json<CacheToggleResponse>, StatusCode> {
|
||||
tracing::info!("[cache_toggle] Setting cache enabled to: {}", req.enabled);
|
||||
|
||||
crate::core::config::set_cache_enabled(req.enabled);
|
||||
|
||||
let response = CacheToggleResponse {
|
||||
success: true,
|
||||
cache_enabled: req.enabled,
|
||||
message: if req.enabled {
|
||||
"Cache enabled".to_string()
|
||||
} else {
|
||||
"Cache disabled".to_string()
|
||||
},
|
||||
};
|
||||
|
||||
tracing::info!("[cache_toggle] SUCCESS");
|
||||
Ok(Json(response))
|
||||
}
|
||||
|
||||
async fn unregister(
|
||||
State(state): State<AppState>,
|
||||
Json(req): Json<UnregisterRequest>,
|
||||
) -> Result<Json<UnregisterResponse>, StatusCode> {
|
||||
tracing::info!("[unregister] Unregistering video: {}", req.uuid);
|
||||
|
||||
let db = &state.api_state.db;
|
||||
|
||||
match db.delete_video(&req.uuid).await {
|
||||
Ok(_) => {
|
||||
tracing::info!("[unregister] SUCCESS - deleted: {}", req.uuid);
|
||||
Ok(Json(UnregisterResponse {
|
||||
success: true,
|
||||
uuid: req.uuid,
|
||||
message: "Video unregistered successfully".to_string(),
|
||||
}))
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("[unregister] ERROR - {}", e);
|
||||
Ok(Json(UnregisterResponse {
|
||||
success: false,
|
||||
uuid: req.uuid,
|
||||
message: format!("Failed to unregister: {}", e),
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn start_server(host: &str, port: u16) -> anyhow::Result<()> {
|
||||
let _ = SERVER_START.set(Instant::now());
|
||||
|
||||
@@ -1319,6 +1393,7 @@ pub async fn start_server(host: &str, port: u16) -> anyhow::Result<()> {
|
||||
|
||||
let protected_routes = Router::new()
|
||||
.route("/api/v1/register", post(register))
|
||||
.route("/api/v1/unregister", post(unregister))
|
||||
.route("/api/v1/probe", post(probe))
|
||||
.route("/api/v1/search", post(search))
|
||||
.route("/api/v1/n8n/search", post(n8n_search))
|
||||
@@ -1328,6 +1403,7 @@ pub async fn start_server(host: &str, port: u16) -> anyhow::Result<()> {
|
||||
.route("/api/v1/progress/:uuid", get(get_progress))
|
||||
.route("/api/v1/jobs", get(list_jobs))
|
||||
.route("/api/v1/jobs/:uuid", get(get_job))
|
||||
.route("/api/v1/config/cache", post(cache_toggle))
|
||||
.layer(axum::middleware::from_fn_with_state(
|
||||
state.api_state.clone(),
|
||||
api_key_validation,
|
||||
|
||||
Reference in New Issue
Block a user