feat: registration accepts optional content_hash from client — checksum at birth

This commit is contained in:
Accusys
2026-05-14 20:44:33 +08:00
parent 37747466e8
commit 194a3b161a

View File

@@ -254,6 +254,7 @@ struct RegisterFileRequest {
file_path: String,
pattern: Option<String>,
user_id: Option<i64>,
content_hash: Option<String>,
}
#[derive(Debug, Serialize)]
@@ -816,6 +817,7 @@ async fn register_single_file(
state: &AppState,
file_path: &str,
_user_id: Option<i64>,
provided_hash: Option<String>,
) -> RegisterFileResponse {
tracing::info!("[REGISTER] Starting registration for: {}", file_path);
@@ -870,8 +872,8 @@ async fn register_single_file(
}
};
// Step 1: Compute SHA256 of full file
let content_hash = sha256_file(&path).unwrap_or_default();
// Step 1: Compute SHA256 of full file (or use provided hash)
let content_hash = provided_hash.filter(|h| !h.is_empty()).unwrap_or_else(|| sha256_file(&path).unwrap_or_default());
// Step 2: Hash check — same content = already registered (regardless of name)
let videos_table = schema::table_name("videos");
@@ -1224,6 +1226,7 @@ async fn register_file(
&state,
&entry_path.to_string_lossy().to_string(),
req.user_id,
None,
)
.await;
if result.success {
@@ -1260,7 +1263,7 @@ async fn register_file(
}
// 單一檔案註冊
let resp = register_single_file(&state, &file_path, req.user_id).await;
let resp = register_single_file(&state, &file_path, req.user_id, req.content_hash).await;
return Ok(Json(resp));
}