From 5f9ddd2d02eb3ed8834fa8e89539060013408bc3 Mon Sep 17 00:00:00 2001 From: Accusys Date: Mon, 28 Sep 2026 20:20:41 +0800 Subject: [PATCH] fix: change async_mode default to false for register API MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 問題: - Library 卡片 register 不成功 - 前端未傳遞 async_mode 參數 - API 默認異步模式,返回警告 - file_uuid 為空,前端無法使用 根本原因: 1. 前端調用 API 時未指定 async_mode 2. API 默認 async_mode=true (異步) 3. 異步模式返回空 file_uuid 4. Worker health key 未更新,顯示警告 解決方案: - 修改 async_mode 默認值從 true 改為 false - 前端現在默認使用同步模式 - 立即返回完整信息(file_uuid, duration, etc.) 測試結果: - ✅ 同步模式 (默認): 立即返回 UUID 和元數據 - ✅ 異步模式 (明確指定): 正常排隊處理 影響: - Studio (LibraryView): 現使用同步模式 - Portal (client.ts): 現使用同步模式 優勢: - ✅ 快速響應 (~1秒) - ✅ 完整信息返回 - ✅ 無警告 - ✅ 開發測試友好 注意: - ⚠️ 行為變更: 默認從異步改為同步 - ⚠️ 生產環境建議明確指定 async_mode=true 待解決: - Worker health key 更新問題 文檔: - docs_v1.0/M4_workspace/2026-09-28_register_issue_analysis.md 狀態: ✅ 已修復 --- .../2026-09-28_register_issue_analysis.md | 240 ++++++++++++++++++ src/api/files.rs | 6 +- 2 files changed, 241 insertions(+), 5 deletions(-) create mode 100644 docs_v1.0/M4_workspace/2026-09-28_register_issue_analysis.md diff --git a/docs_v1.0/M4_workspace/2026-09-28_register_issue_analysis.md b/docs_v1.0/M4_workspace/2026-09-28_register_issue_analysis.md new file mode 100644 index 00000000..7d436a0b --- /dev/null +++ b/docs_v1.0/M4_workspace/2026-09-28_register_issue_analysis.md @@ -0,0 +1,240 @@ +--- +title: Register 失败问题分析与修复 +version: 1.0 +date: 2026-09-28 +author: OpenCode +status: fixed +--- + +## 問題描述 + +**用戶報告**: "Library 卡片下 register 不成功" + +--- + +## 問題分析 + +### 1. 前端調用方式 + +**LibraryView.vue** (line 1594): +```typescript +const result: any = await apiCall('register_file', { filePath }) +``` + +**API 端點**: +``` +POST /api/v1/files/register +Body: { "file_path": "/path/to/file.mp4" } +``` + +--- + +### 2. API 默認行為 + +**原配置**: +```rust +#[serde(default = "default_true")] +async_mode: bool, // 默認 true +``` + +**問題**: +- 前端沒有傳遞 `async_mode` 參數 +- API 默認使用異步模式 (`async_mode=true`) +- 異步模式返回警告:"Worker is not running" +- 前端可能將警告顯示為失敗 + +--- + +### 3. Worker Health Key 問題 + +**現象**: +- Worker 正在運行 (PID: 67623) +- 但 Redis `momentry:health` key 不存在 (TTL = -2) +- API 誤判 Worker 未運行 + +**影響**: +- 異步模式返回警告 +- 前端可能認為註冊失敗 + +--- + +### 4. 返回數據缺失 + +**異步模式返回**: +```json +{ + "success": true, + "file_uuid": "", + "file_name": "", + "duration": 0.0, + "message": "Register queued (command_id=...)", + "warning": "Worker is not running..." +} +``` + +**問題**: +- `file_uuid` 為空 +- `file_name` 為空 +- 前端無法立即獲取文件信息 + +--- + +## 解決方案 + +### 修改默認值 + +**修改**: `/Users/accusys/momentry_core/src/api/files.rs` + +```rust +// 修改前 +#[serde(default = "default_true")] +async_mode: bool, // 默認 true + +// 修改後 +#[serde(default)] +async_mode: bool, // 默認 false +``` + +--- + +## 修復效果 + +### 同步模式(默認) + +**測試**: 不傳遞 `async_mode` 參數 + +```bash +curl -X POST "http://localhost:3002/api/v1/files/register?api_key=..." \ + -H "Content-Type: application/json" \ + -d '{"file_path": "/Users/accusys/momentry/var/sftpgo/data/demo/003.mp4"}' +``` + +**響應**: +```json +{ + "success": true, + "file_uuid": "c02eea5b8294962ea84af1739d44806b", + "file_name": "003.mp4", + "duration": 10.08, + "message": "Registration completed (sync mode)" +} +``` + +**優勢**: +- ✅ 立即返回完整信息 +- ✅ 無警告 +- ✅ 前端可立即使用 `file_uuid` +- ✅ 快速響應 (~1秒) + +--- + +### 異步模式(明確指定) + +**測試**: 傳遞 `async_mode=true` + +```bash +curl -X POST "http://localhost:3002/api/v1/files/register?api_key=..." \ + -H "Content-Type: application/json" \ + -d '{"file_path": "/Users/accusys/momentry/var/sftpgo/data/demo/004.mp4", "async_mode": true}' +``` + +**響應**: +```json +{ + "success": true, + "message": "Register queued (command_id=...)", + "command_id": "...", + "warning": "Worker is not running..." +} +``` + +**注意**: 異步模式仍有 Worker health key 問題,需要後續修復。 + +--- + +## 影響範圍 + +### 受影響的前端 + +1. **Studio** (LibraryView) + - 現在使用同步模式 + - 立即獲取 `file_uuid` + +2. **Portal** (client.ts) + - 現在使用同步模式 + - 立即獲取 `file_uuid` + +--- + +### 向後兼容性 + +**⚠️ 行為變更**: +- 之前: 默認異步模式 +- 現在: 默認同步模式 + +**建議**: +- 開發/測試: 使用同步模式(更快) +- 生產環境: 明確指定 `async_mode=true`(可處理大文件) + +--- + +## 測試結果 + +### ✅ 同步模式測試 + +| 文件 | 狀態 | UUID | Duration | +|------|------|------|----------| +| 003.mp4 | ✅ 成功 | c02eea5b... | 10.08s | + +--- + +### ✅ 異步模式測試 + +| 文件 | 狀態 | Command ID | 警告 | +|------|------|------------|------| +| 004.mp4 | ✅ 排隊 | 047cfae... | Worker not running | + +--- + +## 待解決問題 + +### Worker Health Key 更新 + +**問題**: +- Worker 運行中,但未更新 Redis health key + +**影響**: +- 異步模式顯示錯誤警告 + +**解決方案**: +- 修改 Worker 代碼,定期更新 health key +- 或者修改 API,使用進程檢測代替 Redis + +--- + +## Git Commit + +即將提交: +- fix: change async_mode default to false for register API + +--- + +## 總結 + +### ✅ 問題已解決 + +1. **前端 register 現在使用同步模式** +2. **立即返回完整信息** +3. **無警告信息** +4. **快速響應** + +### ⚠️ 需後續處理 + +1. **Worker health key 更新** +2. **異步模式警告處理** + +--- + +**修復日期**: 2026-09-28 + +**狀態**: ✅ **已修復,前端 register 現可正常工作** diff --git a/src/api/files.rs b/src/api/files.rs index 22512b7d..51a8940c 100644 --- a/src/api/files.rs +++ b/src/api/files.rs @@ -31,7 +31,7 @@ struct RegisterFileRequest { face_settings: Option, #[serde(default = "default_force")] force: bool, - #[serde(default = "default_true")] + #[serde(default)] async_mode: bool, } @@ -39,10 +39,6 @@ fn default_force() -> bool { true } -fn default_true() -> bool { - true -} - #[derive(Debug, Deserialize, Serialize)] struct FileLookupMatch { file_uuid: String,