feat: add trace profile API path parameter support
- Add TraceProfilePath struct for path parameters - Refactor get_trace_profile_handler to support both formats: - Query parameters: /api/v1/trace-profile?file_uuid=...&trace_id=... - Path parameters: /api/v1/trace-profile/:file_uuid/:trace_id - Maintain backward compatibility with existing query parameter format - Fix 404 error when Studio calls trace profile API with path format Fixes: Studio right-click key frame trace profile error Deployment: Released to production (3002) on 2026-10-17
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
---
|
||||
title: Trace Profile API 路徑參數支持
|
||||
version: 1.0
|
||||
date: 2026-10-17
|
||||
author: OpenCode
|
||||
status: completed
|
||||
---
|
||||
|
||||
## 問題
|
||||
|
||||
前端調用 API 時使用了路徑參數格式:
|
||||
```
|
||||
GET /api/v1/trace-profile/{file_uuid}/{trace_id}
|
||||
```
|
||||
|
||||
但後端只支持查詢參數格式:
|
||||
```
|
||||
GET /api/v1/trace-profile?file_uuid=...&trace_id=...
|
||||
```
|
||||
|
||||
導致返回 404 Not Found 錯誤。
|
||||
|
||||
## 解決方案
|
||||
|
||||
在後端添加新的路由支持路徑參數格式,保持向後兼容。
|
||||
|
||||
## 實現
|
||||
|
||||
### 1. 添加新的結構體
|
||||
|
||||
```rust
|
||||
#[derive(Deserialize)]
|
||||
pub struct TraceProfilePath {
|
||||
pub file_uuid: String,
|
||||
pub trace_id: i32,
|
||||
}
|
||||
```
|
||||
|
||||
### 2. 重構 Handler
|
||||
|
||||
將原有的 handler 拆分為:
|
||||
- `get_trace_profile_handler`: 查詢參數格式
|
||||
- `get_trace_profile_by_path_handler`: 路徑參數格式
|
||||
- `get_trace_profile_impl`: 共享實現邏輯
|
||||
|
||||
### 3. 添加新路由
|
||||
|
||||
```rust
|
||||
.route("/api/v1/trace-profile", get(get_trace_profile_handler))
|
||||
.route(
|
||||
"/api/v1/trace-profile/:file_uuid/:trace_id",
|
||||
get(get_trace_profile_by_path_handler),
|
||||
)
|
||||
```
|
||||
|
||||
## 測試結果
|
||||
|
||||
### ✅ 路徑參數格式(新增)
|
||||
```bash
|
||||
GET /api/v1/trace-profile/b496a68800f90770aa7246c877f38985/5
|
||||
返回: 200 OK
|
||||
{
|
||||
"trace_id": 5,
|
||||
"name": "Person_1",
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
### ✅ 查詢參數格式(原有)
|
||||
```bash
|
||||
GET /api/v1/trace-profile?file_uuid=b496a688...&trace_id=3
|
||||
返回: 200 OK
|
||||
{
|
||||
"trace_id": 3,
|
||||
"name": "...",
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
### ✅ 其他 traces 測試
|
||||
```bash
|
||||
GET /api/v1/trace-profile/b496a688.../0
|
||||
返回: 200 OK
|
||||
{
|
||||
"trace_id": 0,
|
||||
"name": "...",
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
## 影響範圍
|
||||
|
||||
- **後端**: `/Users/accusys/momentry_core/src/api/profile.rs`
|
||||
- **API 端點**: 新增 `/api/v1/trace-profile/:file_uuid/:trace_id`
|
||||
- **向後兼容**: 原有查詢參數格式仍然可用
|
||||
|
||||
## 好處
|
||||
|
||||
1. **前端無需修改** - 現有調用格式立即可用
|
||||
2. **API 更靈活** - 支持兩種格式
|
||||
3. **向後兼容** - 不影響現有功能
|
||||
|
||||
---
|
||||
|
||||
**OpenCode**
|
||||
2026-10-17
|
||||
Reference in New Issue
Block a user