实现 /api/playlist 快照语义,返回 playlist 和 current_index
- 新增 PlaylistSnapshot 结构体,包含 playlist 和 current_index - 修改 playlist_route 从 HttpState 获取 player_status.current_index - 与旧版 hologram_player_rust 行为一致 - cargo check 零 warning
This commit is contained in:
@@ -57,6 +57,12 @@ struct BleStatusResponse {
|
||||
device_name: String,
|
||||
}
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct PlaylistSnapshot {
|
||||
playlist: Vec<crate::core::config::VideoItem>,
|
||||
current_index: usize,
|
||||
}
|
||||
|
||||
pub(crate) fn build_routes(
|
||||
tx: mpsc::Sender<Envelope>,
|
||||
state: Arc<HttpState>,
|
||||
@@ -212,7 +218,12 @@ fn playlist_route(
|
||||
.and(with_state(state))
|
||||
.and_then(|state: Arc<HttpState>| 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))
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user