fix: scan status=unregistered not shown as registered; feat: config API for auto-pipeline/watcher-auto-register

This commit is contained in:
Accusys
2026-05-19 00:37:00 +08:00
parent 05e1e807c0
commit a02a83c1c3
9 changed files with 259 additions and 35 deletions

View File

@@ -181,6 +181,30 @@ struct CacheToggleResponse {
message: String,
}
#[derive(Debug, Deserialize)]
struct AutoPipelineToggleRequest {
enabled: bool,
}
#[derive(Debug, Serialize)]
struct AutoPipelineToggleResponse {
success: bool,
auto_pipeline_enabled: bool,
message: String,
}
#[derive(Debug, Deserialize)]
struct WatcherAutoRegisterToggleRequest {
enabled: bool,
}
#[derive(Debug, Serialize)]
struct WatcherAutoRegisterToggleResponse {
success: bool,
watcher_auto_register_enabled: bool,
message: String,
}
// Missing structs added
#[derive(Debug, Deserialize)]
@@ -1692,7 +1716,8 @@ async fn register_file(
let resp = register_single_file(&state, &file_path, req.user_id, req.content_hash).await;
// Auto-trigger pipeline for newly registered video files
if resp.success && !resp.already_exists && resp.file_type.as_deref() == Some("video") {
if resp.success && !resp.already_exists && resp.file_type.as_deref() == Some("video")
&& crate::core::config::get_auto_pipeline_enabled() {
let auto_uuid = resp.file_uuid.clone();
let auto_state = state.clone();
tokio::spawn(async move {
@@ -2650,33 +2675,35 @@ fn scan_directory_recursive(
.unwrap_or_default();
// Check registration
if let Some((uuid, status, reg_time, jid)) = registered_paths.get(&abs_path)
{
files.push(ScannedFileInfo {
file_name,
relative_path: rel_path,
file_path: abs_path,
file_size: meta.len(),
modified_time,
is_registered: true,
file_uuid: Some(uuid.clone()),
status: Some(status.clone()),
registration_time: reg_time.clone(),
job_id: *jid,
});
} else {
files.push(ScannedFileInfo {
file_name,
relative_path: rel_path,
file_path: abs_path,
file_size: meta.len(),
modified_time,
is_registered: false,
file_uuid: None,
status: Some("unregistered".to_string()),
registration_time: None,
job_id: None,
});
match registered_paths.get(&abs_path) {
Some((uuid, status, reg_time, jid)) if status != "unregistered" => {
files.push(ScannedFileInfo {
file_name,
relative_path: rel_path,
file_path: abs_path,
file_size: meta.len(),
modified_time,
is_registered: true,
file_uuid: Some(uuid.clone()),
status: Some(status.clone()),
registration_time: reg_time.clone(),
job_id: *jid,
});
}
_ => {
files.push(ScannedFileInfo {
file_name,
relative_path: rel_path,
file_path: abs_path,
file_size: meta.len(),
modified_time,
is_registered: false,
file_uuid: None,
status: Some("unregistered".to_string()),
registration_time: None,
job_id: None,
});
}
}
}
}
@@ -3332,6 +3359,30 @@ async fn cache_toggle(
Ok(Json(response))
}
async fn auto_pipeline_toggle(
Json(req): Json<AutoPipelineToggleRequest>,
) -> Result<Json<AutoPipelineToggleResponse>, StatusCode> {
tracing::info!("[auto_pipeline_toggle] Setting to: {}", req.enabled);
crate::core::config::set_auto_pipeline_enabled(req.enabled);
Ok(Json(AutoPipelineToggleResponse {
success: true,
auto_pipeline_enabled: req.enabled,
message: format!("Auto-pipeline {}", if req.enabled { "enabled" } else { "disabled" }),
}))
}
async fn watcher_auto_register_toggle(
Json(req): Json<WatcherAutoRegisterToggleRequest>,
) -> Result<Json<WatcherAutoRegisterToggleResponse>, StatusCode> {
tracing::info!("[watcher_auto_register_toggle] Setting to: {}", req.enabled);
crate::core::config::set_watcher_auto_register(req.enabled);
Ok(Json(WatcherAutoRegisterToggleResponse {
success: true,
watcher_auto_register_enabled: req.enabled,
message: format!("Watcher auto-register {}", if req.enabled { "enabled" } else { "disabled" }),
}))
}
#[derive(Debug, Serialize)]
struct UnregisterResponse {
success: bool,
@@ -3682,6 +3733,8 @@ pub async fn start_server(host: &str, port: u16) -> anyhow::Result<()> {
.route("/api/v1/progress/:file_uuid", get(get_progress))
.route("/api/v1/jobs", get(list_jobs))
.route("/api/v1/config/cache", post(cache_toggle))
.route("/api/v1/config/auto-pipeline", post(auto_pipeline_toggle))
.route("/api/v1/config/watcher-auto-register", post(watcher_auto_register_toggle))
// .merge(person_identity::person_identity_routes()) // V4.0: DISABLED (person_identities table removed)
.merge(identity_binding::identity_binding_routes())
.merge(identities::identity_routes())