docs: summarize Re-scan API implementation status
實現狀態: - ✅ API 結構體已實現 - ✅ API 端點已添加 - ✅ Worker 支持已添加 - ❌ Monitor Job 未自動創建 已知問題: - register_single_file 在 force unregister 後仍返回 already_exists=true - 導致 auto-pipeline 條件判斷失敗 解決方案: - 方案 A: 修改 register_single_file(推薦) - 方案 B: 在 process_register_command 中添加標志 下一步: 1. 實現方案 A 2. 重新測試 3. 更新文檔
This commit is contained in:
@@ -0,0 +1,200 @@
|
|||||||
|
---
|
||||||
|
title: Re-scan API 實現總結
|
||||||
|
version: 1.0
|
||||||
|
date: 2026-09-27
|
||||||
|
author: OpenCode
|
||||||
|
status: partial_implementation
|
||||||
|
---
|
||||||
|
|
||||||
|
## 實現狀態
|
||||||
|
|
||||||
|
### ✅ 已完成
|
||||||
|
|
||||||
|
#### 1. API 結構體
|
||||||
|
|
||||||
|
**位置**: `src/api/files.rs`
|
||||||
|
|
||||||
|
```rust
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
struct ReScanRequest {
|
||||||
|
file_uuid: String,
|
||||||
|
processors: Option<Vec<String>>,
|
||||||
|
face_settings: Option<FaceSettings>,
|
||||||
|
trigger_source: Option<String>,
|
||||||
|
reason: Option<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
struct ReScanResponse {
|
||||||
|
success: bool,
|
||||||
|
message: String,
|
||||||
|
file_uuid: String,
|
||||||
|
unregister_command_id: Option<String>,
|
||||||
|
register_command_id: Option<String>,
|
||||||
|
process_command_id: Option<String>,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### 2. API 端點
|
||||||
|
|
||||||
|
**路由**: `POST /api/v1/re-scan`
|
||||||
|
|
||||||
|
**功能**:
|
||||||
|
- 接收 file_uuid
|
||||||
|
- 創建 register command (force=true, auto_pipeline=true)
|
||||||
|
- 返回 command_id
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
#### 3. Worker 支持
|
||||||
|
|
||||||
|
**位置**: `src/worker/job_worker.rs`
|
||||||
|
|
||||||
|
**新增**:
|
||||||
|
- `auto_pipeline_override` 標志支持
|
||||||
|
- 修改 auto-pipeline 條件:`(auto_pipeline_override || (force || !already_exists))`
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### ❌ 未完成
|
||||||
|
|
||||||
|
#### 1. Monitor Job 未自動創建
|
||||||
|
|
||||||
|
**問題**:
|
||||||
|
- register_single_file 在檢測到 content hash collision 後返回 `already_exists=true`
|
||||||
|
- 即使執行了 force unregister,這個標志也不會改變
|
||||||
|
- 導致 auto-pipeline 條件判斷失敗
|
||||||
|
|
||||||
|
**原因**:
|
||||||
|
```rust
|
||||||
|
// register_single_file 函數中的邏輯
|
||||||
|
if let Ok(Some(existing_uuid)) = sqlx::query_scalar(...).await {
|
||||||
|
if force {
|
||||||
|
// 執行 unregister
|
||||||
|
unregister_internal(...).await;
|
||||||
|
// 繼續執行 register
|
||||||
|
} else {
|
||||||
|
// 返回 already_exists=true
|
||||||
|
return RegisterFileResponse {
|
||||||
|
already_exists: true,
|
||||||
|
...
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 但是在 force 模式下,最終返回的 response 中
|
||||||
|
// already_exists 標志仍然是 true(因為上面已經檢測到了 collision)
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 測試結果
|
||||||
|
|
||||||
|
### ✅ 成功的部分
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl -X POST http://localhost:3002/api/v1/re-scan \
|
||||||
|
-d '{"file_uuid": "a1a1618c504475777ddc4135ea244051"}'
|
||||||
|
|
||||||
|
# 響應:
|
||||||
|
{
|
||||||
|
"success": true,
|
||||||
|
"message": "Re-scan queued: register=c4f3b491232b4aa8bc4e9d5d8fb31ae7",
|
||||||
|
"file_uuid": "a1a1618c504475777ddc4135ea244051",
|
||||||
|
"register_command_id": "c4f3b491232b4aa8bc4e9d5d8fb31ae7"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### ❌ 失敗的部分
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# 數據庫查詢
|
||||||
|
SELECT * FROM monitor_jobs WHERE uuid = '...';
|
||||||
|
# 結果: 0 rows
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Worker 日誌分析
|
||||||
|
|
||||||
|
```
|
||||||
|
[COMMAND_QUEUE] Registering file: test-3.mp4 (force=true, auto_pipeline_override=true)
|
||||||
|
[REGISTER] Content hash collision → already registered
|
||||||
|
[REGISTER] Force mode: async unregistering existing file
|
||||||
|
[UNREGISTER] Deleted all data for ...
|
||||||
|
[REGISTER] Force unregister completed
|
||||||
|
[REGISTER] CUT completed
|
||||||
|
```
|
||||||
|
|
||||||
|
**問題**:
|
||||||
|
- `already_exists=true` 被設置
|
||||||
|
- 導致 auto-pipeline 條件失敗
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 解決方案
|
||||||
|
|
||||||
|
### 方案 A: 修改 register_single_file(推薦)
|
||||||
|
|
||||||
|
**位置**: `src/api/files.rs` 的 `register_single_file` 函數
|
||||||
|
|
||||||
|
**修改**:
|
||||||
|
```rust
|
||||||
|
// 在 force unregister 後,將 already_exists 設置為 false
|
||||||
|
if force {
|
||||||
|
unregister_internal(...).await?;
|
||||||
|
already_exists = false; // ← 添加這行
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**優點**:
|
||||||
|
- 徹底解決問題
|
||||||
|
- 邏輯清晰
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 方案 B: 在 process_register_command 中添加標志
|
||||||
|
|
||||||
|
**位置**: `src/worker/job_worker.rs`
|
||||||
|
|
||||||
|
**修改**:
|
||||||
|
```rust
|
||||||
|
// 在 process_register_command 中
|
||||||
|
let force_unregister_executed = ...; // 從 register_single_file 返回
|
||||||
|
|
||||||
|
if (auto_pipeline_override || force_unregister_executed || ...)
|
||||||
|
&& ...
|
||||||
|
{
|
||||||
|
// 創建 monitor_job
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
**缺點**:
|
||||||
|
- 需要修改 register_single_file 的返回類型
|
||||||
|
- 邏輯更複雜
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 下一步
|
||||||
|
|
||||||
|
1. **實現方案 A**(修改 register_single_file)
|
||||||
|
2. **重新測試** Re-scan API
|
||||||
|
3. **確認** Monitor Job 正確創建
|
||||||
|
4. **更新** API 文檔
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 相關文件
|
||||||
|
|
||||||
|
- `/Users/accusys/momentry_core/src/api/files.rs` - Re-scan API 實現
|
||||||
|
- `/Users/accusys/momentry_core/src/worker/job_worker.rs` - Worker 處理邏輯
|
||||||
|
- `/Users/accusys/momentry_core/docs_v1.0/M4_workspace/2026-09-27_rescan_final_test_report.md` - 測試報告
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 提交記錄
|
||||||
|
|
||||||
|
- `ecb2096`: feat: implement Re-scan API (partial)
|
||||||
Reference in New Issue
Block a user