diff --git a/rave/src/rest/mod.rs b/rave/src/rest/mod.rs index f2ed40b..99d0846 100644 --- a/rave/src/rest/mod.rs +++ b/rave/src/rest/mod.rs @@ -25,23 +25,37 @@ mod get_artists; // rest/getArtist mod get_artist; +// TODO: Fix the `.ping` issue, figure out how to make it work without the duplication. pub fn build() -> Box> { Route::new() - .at("/ping<.view?>", ping::ping) - .at("/getLicense<.view?>", get_license::get_license) + .at("/ping", ping::ping) + .at("/ping.view", ping::ping) + .at("/getLicense", get_license::get_license) + .at("/getLicense.view", get_license::get_license) + .at("/getMusicFolders", get_music_folders::get_music_folders) .at( - "/getMusicFolders<.view?>", + "/getMusicFolders.view", get_music_folders::get_music_folders, ) - .at("/getAlbumList<.view?>", get_album_list::get_album_list) - .at("/getAlbumList2<.view?>", get_album_list::get_album_list) - .at("/getAlbum<.view?>", get_album::get_album) - .at("/stream<.view?>", stream::stream) - .at("/startScan<.view?>", start_scan::start_scan) - .at("/getScanStatus<.view?>", get_scan_status::get_scan_status) - .at("/search3<.view?>", search3::search3) - .at("/getCoverArt<.view?>", get_cover_art::get_cover_art) - .at("/getArtists<.view?>", get_artists::get_artists) - .at("/getArtist<.view?>", get_artist::get_artist) + .at("/getAlbumList", get_album_list::get_album_list) + .at("/getAlbumList.view", get_album_list::get_album_list) + .at("/getAlbumList2", get_album_list::get_album_list) + .at("/getAlbumList2.view", get_album_list::get_album_list) + .at("/getAlbum", get_album::get_album) + .at("/getAlbum.view", get_album::get_album) + .at("/stream", stream::stream) + .at("/stream.view", stream::stream) + .at("/startScan", start_scan::start_scan) + .at("/startScan.view", start_scan::start_scan) + .at("/getScanStatus", get_scan_status::get_scan_status) + .at("/getScanStatus.view", get_scan_status::get_scan_status) + .at("/search3", search3::search3) + .at("/search3.view", search3::search3) + .at("/getCoverArt", get_cover_art::get_cover_art) + .at("/getCoverArt.view", get_cover_art::get_cover_art) + .at("/getArtists", get_artists::get_artists) + .at("/getArtists.view", get_artists::get_artists) + .at("/getArtist", get_artist::get_artist) + .at("/getArtist.view", get_artist::get_artist) .boxed() } diff --git a/rave/src/subsonic/mod.rs b/rave/src/subsonic/mod.rs index e8b4d7c..d1728e1 100644 --- a/rave/src/subsonic/mod.rs +++ b/rave/src/subsonic/mod.rs @@ -12,30 +12,26 @@ pub use types::artist::Artist; pub use types::child::Child; pub use types::music_folder::MusicFolder; -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Serialize)] pub struct SubsonicResponse { pub status: ResponseStatus, pub version: VersionTriple, + #[serde(skip_serializing_if = "SubResponseType::is_empty")] pub value: Box, } impl From for SubsonicResponseJson { fn from(value: SubsonicResponse) -> Self { Self { - status: value.status, - version: value.version, - value: value.value, + subsonic_response: value, } } } #[derive(Debug, Clone, Serialize)] -#[serde(rename = "subsonic-response")] pub struct SubsonicResponseJson { - pub status: ResponseStatus, - pub version: VersionTriple, - #[serde(flatten)] - pub value: Box, + #[serde(rename = "subsonic-response")] + pub subsonic_response: SubsonicResponse, } impl IntoResponse for SubsonicResponseJson { @@ -68,7 +64,7 @@ pub struct SubsonicResponseXml { pub status: ResponseStatus, #[serde(rename = "@version")] pub version: VersionTriple, - #[serde(rename = "$value")] + #[serde(rename = "$value", skip_serializing_if = "SubResponseType::is_empty")] pub value: Box, } @@ -146,6 +142,7 @@ impl SubsonicResponse { } #[derive(Debug, Clone, Serialize)] +#[serde(untagged)] pub enum SubResponseType { #[serde(rename = "musicFolders")] MusicFolders { @@ -205,6 +202,12 @@ pub enum SubResponseType { Empty, } +impl SubResponseType { + pub const fn is_empty(&self) -> bool { + matches!(self, Self::Empty) + } +} + #[derive(Debug, Clone, Copy)] pub enum ResponseStatus { Ok,