commands: implement response parser for lsinfo

This commit is contained in:
2025-11-21 16:13:09 +09:00
parent 06e24f0ce0
commit c6a123a6e1

View File

@@ -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<String>;
pub type LsInfoResponse = Vec<LsInfoResponseEntry>;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct LsInfoResponseEntry {
playlist: String,
last_modified: Option<String>,
}
impl Command for LsInfo {
type Response = LsInfoResponse;
@@ -29,6 +36,30 @@ impl Command for LsInfo {
fn parse_response(
parts: ResponseAttributes<'_>,
) -> Result<Self::Response, ResponseParserError<'_>> {
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)
}
}