feat: registration accepts optional content_hash from client — checksum at birth
This commit is contained in:
@@ -254,6 +254,7 @@ struct RegisterFileRequest {
|
|||||||
file_path: String,
|
file_path: String,
|
||||||
pattern: Option<String>,
|
pattern: Option<String>,
|
||||||
user_id: Option<i64>,
|
user_id: Option<i64>,
|
||||||
|
content_hash: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
@@ -816,6 +817,7 @@ async fn register_single_file(
|
|||||||
state: &AppState,
|
state: &AppState,
|
||||||
file_path: &str,
|
file_path: &str,
|
||||||
_user_id: Option<i64>,
|
_user_id: Option<i64>,
|
||||||
|
provided_hash: Option<String>,
|
||||||
) -> RegisterFileResponse {
|
) -> RegisterFileResponse {
|
||||||
tracing::info!("[REGISTER] Starting registration for: {}", file_path);
|
tracing::info!("[REGISTER] Starting registration for: {}", file_path);
|
||||||
|
|
||||||
@@ -870,8 +872,8 @@ async fn register_single_file(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Step 1: Compute SHA256 of full file
|
// Step 1: Compute SHA256 of full file (or use provided hash)
|
||||||
let content_hash = sha256_file(&path).unwrap_or_default();
|
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)
|
// Step 2: Hash check — same content = already registered (regardless of name)
|
||||||
let videos_table = schema::table_name("videos");
|
let videos_table = schema::table_name("videos");
|
||||||
@@ -1224,6 +1226,7 @@ async fn register_file(
|
|||||||
&state,
|
&state,
|
||||||
&entry_path.to_string_lossy().to_string(),
|
&entry_path.to_string_lossy().to_string(),
|
||||||
req.user_id,
|
req.user_id,
|
||||||
|
None,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
if result.success {
|
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));
|
return Ok(Json(resp));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user