From 6ca5992b3385dac4ac4fba7f07ea4cbb71faf9bc Mon Sep 17 00:00:00 2001 From: showen Date: Thu, 12 Mar 2026 13:00:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=20/api/playlist=20=E5=BF=AB?= =?UTF-8?q?=E7=85=A7=E8=AF=AD=E4=B9=89=EF=BC=8C=E8=BF=94=E5=9B=9E=20playli?= =?UTF-8?q?st=20=E5=92=8C=20current=5Findex?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 PlaylistSnapshot 结构体,包含 playlist 和 current_index - 修改 playlist_route 从 HttpState 获取 player_status.current_index - 与旧版 hologram_player_rust 行为一致 - cargo check 零 warning --- TEAM_CHAT.md | 27 +++++++++++++++++++++++++++ src/plugins/http/routes.rs | 13 ++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/TEAM_CHAT.md b/TEAM_CHAT.md index 59fb435..15fa8bb 100644 --- a/TEAM_CHAT.md +++ b/TEAM_CHAT.md @@ -1866,3 +1866,30 @@ M Cargo.lock - 这与旧版 `video_processor.rs:578-588` 的行为完全一致 --- + +[2026-03-12 14:30] 李思琪(视频引擎工程师) → 刘建国(PM), 陈逸飞(CEO): /api/playlist 快照语义已实现,与旧版行为一致。 + +背景: +- 旧版 `/api/playlist` 返回 `{ playlist: [...], current_index: N }`,包含当前播放索引 +- 新版只返回配置中的 playlist 数组,缺少 current_index +- 这导致客户端无法获知当前播放位置的快照 + +实现方案: +- 在 `src/plugins/http/routes.rs` 中: + - 新增 `PlaylistSnapshot` 结构体(line 59-63),包含 `playlist` 和 `current_index` 字段 + - 修改 `playlist_route` 函数(line 207-220),从 `HttpState` 获取 `player_status.current_index` + - 返回 `{ playlist: config.playlist, current_index: player_status.current_index }` + +修改文件: +- `src/plugins/http/routes.rs` (line 59-63, 207-220) + +验证结果: +- ✅ `cargo check` 通过,零 warning +- ✅ 响应结构与旧版 `hologram_player_rust/src/api_server.rs:371-374` 完全一致 + +行为说明: +- HttpPlugin 维护的 `player_status` 通过 `Message::PlayerStatus` 广播实时更新 +- VideoPlugin 在播放状态变化时广播 `PlayerStatus`,包含 `current_index` +- `/api/playlist` 返回配置快照 + 当前播放索引,客户端可据此实现播放列表高亮 + +--- diff --git a/src/plugins/http/routes.rs b/src/plugins/http/routes.rs index 0870178..9f0d1dc 100644 --- a/src/plugins/http/routes.rs +++ b/src/plugins/http/routes.rs @@ -57,6 +57,12 @@ struct BleStatusResponse { device_name: String, } +#[derive(Serialize)] +struct PlaylistSnapshot { + playlist: Vec, + current_index: usize, +} + pub(crate) fn build_routes( tx: mpsc::Sender, state: Arc, @@ -212,7 +218,12 @@ fn playlist_route( .and(with_state(state)) .and_then(|state: Arc| async move { let config = state.config(); - Ok::<_, Infallible>(json_response(StatusCode::OK, &config.playlist)) + let player_status = state.player_status(); + let snapshot = PlaylistSnapshot { + playlist: config.playlist.clone(), + current_index: player_status.current_index, + }; + Ok::<_, Infallible>(json_response(StatusCode::OK, &snapshot)) }) }