From fccb32ad6daf7f167c221eaf2658fa2d4a2e5add Mon Sep 17 00:00:00 2001 From: h7x4 Date: Fri, 21 Nov 2025 16:13:09 +0900 Subject: [PATCH] commands: implement response parser for `lsinfo` --- src/commands/music_database/lsinfo.rs | 39 ++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/src/commands/music_database/lsinfo.rs b/src/commands/music_database/lsinfo.rs index b1a55d9e..601d5488 100644 --- a/src/commands/music_database/lsinfo.rs +++ b/src/commands/music_database/lsinfo.rs @@ -1,12 +1,19 @@ +use serde::{Deserialize, Serialize}; + use crate::commands::{ Command, Request, RequestParserError, RequestParserResult, ResponseAttributes, - ResponseParserError, + ResponseParserError, expect_property_type, }; pub struct LsInfo; -// TODO: fix this type -pub type LsInfoResponse = Vec; +pub type LsInfoResponse = Vec; + +#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] +pub struct LsInfoResponseEntry { + playlist: String, + last_modified: Option, +} impl Command for LsInfo { type Response = LsInfoResponse; @@ -29,6 +36,30 @@ impl Command for LsInfo { fn parse_response( parts: ResponseAttributes<'_>, ) -> Result> { - unimplemented!() + let parts: Vec<_> = parts.into(); + let mut playlists = Vec::new(); + + for (key, value) in parts { + match key { + "playlist" => { + playlists.push(LsInfoResponseEntry { + playlist: expect_property_type!(Some(value), "playlist", Text).to_string(), + last_modified: None, + }); + } + "Last-Modified" => { + if let Some(last) = playlists.last_mut() { + last.last_modified = Some( + expect_property_type!(Some(value), "Last-Modified", Text).to_string(), + ); + } else { + return Err(ResponseParserError::UnexpectedProperty("Last-Modified")); + } + } + _ => return Err(ResponseParserError::UnexpectedProperty(key)), + } + } + + Ok(playlists) } }