fix: .view and json bugs
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Lys 2023-11-28 04:18:42 +02:00
parent 159395e35d
commit 98de70d9f0
Signed by: lyssieth
GPG key ID: C9CF3D614FAA3940
2 changed files with 40 additions and 23 deletions

View file

@ -25,23 +25,37 @@ mod get_artists;
// rest/getArtist // rest/getArtist
mod get_artist; mod get_artist;
// TODO: Fix the `.ping` issue, figure out how to make it work without the duplication.
pub fn build() -> Box<dyn Endpoint<Output = poem::Response>> { pub fn build() -> Box<dyn Endpoint<Output = poem::Response>> {
Route::new() Route::new()
.at("/ping<.view?>", ping::ping) .at("/ping", ping::ping)
.at("/getLicense<.view?>", get_license::get_license) .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( .at(
"/getMusicFolders<.view?>", "/getMusicFolders.view",
get_music_folders::get_music_folders, get_music_folders::get_music_folders,
) )
.at("/getAlbumList<.view?>", get_album_list::get_album_list) .at("/getAlbumList", get_album_list::get_album_list)
.at("/getAlbumList2<.view?>", get_album_list::get_album_list) .at("/getAlbumList.view", get_album_list::get_album_list)
.at("/getAlbum<.view?>", get_album::get_album) .at("/getAlbumList2", get_album_list::get_album_list)
.at("/stream<.view?>", stream::stream) .at("/getAlbumList2.view", get_album_list::get_album_list)
.at("/startScan<.view?>", start_scan::start_scan) .at("/getAlbum", get_album::get_album)
.at("/getScanStatus<.view?>", get_scan_status::get_scan_status) .at("/getAlbum.view", get_album::get_album)
.at("/search3<.view?>", search3::search3) .at("/stream", stream::stream)
.at("/getCoverArt<.view?>", get_cover_art::get_cover_art) .at("/stream.view", stream::stream)
.at("/getArtists<.view?>", get_artists::get_artists) .at("/startScan", start_scan::start_scan)
.at("/getArtist<.view?>", get_artist::get_artist) .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() .boxed()
} }

View file

@ -12,30 +12,26 @@ pub use types::artist::Artist;
pub use types::child::Child; pub use types::child::Child;
pub use types::music_folder::MusicFolder; pub use types::music_folder::MusicFolder;
#[derive(Debug, Clone)] #[derive(Debug, Clone, Serialize)]
pub struct SubsonicResponse { pub struct SubsonicResponse {
pub status: ResponseStatus, pub status: ResponseStatus,
pub version: VersionTriple, pub version: VersionTriple,
#[serde(skip_serializing_if = "SubResponseType::is_empty")]
pub value: Box<SubResponseType>, pub value: Box<SubResponseType>,
} }
impl From<SubsonicResponse> for SubsonicResponseJson { impl From<SubsonicResponse> for SubsonicResponseJson {
fn from(value: SubsonicResponse) -> Self { fn from(value: SubsonicResponse) -> Self {
Self { Self {
status: value.status, subsonic_response: value,
version: value.version,
value: value.value,
} }
} }
} }
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
#[serde(rename = "subsonic-response")]
pub struct SubsonicResponseJson { pub struct SubsonicResponseJson {
pub status: ResponseStatus, #[serde(rename = "subsonic-response")]
pub version: VersionTriple, pub subsonic_response: SubsonicResponse,
#[serde(flatten)]
pub value: Box<SubResponseType>,
} }
impl IntoResponse for SubsonicResponseJson { impl IntoResponse for SubsonicResponseJson {
@ -68,7 +64,7 @@ pub struct SubsonicResponseXml {
pub status: ResponseStatus, pub status: ResponseStatus,
#[serde(rename = "@version")] #[serde(rename = "@version")]
pub version: VersionTriple, pub version: VersionTriple,
#[serde(rename = "$value")] #[serde(rename = "$value", skip_serializing_if = "SubResponseType::is_empty")]
pub value: Box<SubResponseType>, pub value: Box<SubResponseType>,
} }
@ -146,6 +142,7 @@ impl SubsonicResponse {
} }
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum SubResponseType { pub enum SubResponseType {
#[serde(rename = "musicFolders")] #[serde(rename = "musicFolders")]
MusicFolders { MusicFolders {
@ -205,6 +202,12 @@ pub enum SubResponseType {
Empty, Empty,
} }
impl SubResponseType {
pub const fn is_empty(&self) -> bool {
matches!(self, Self::Empty)
}
}
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub enum ResponseStatus { pub enum ResponseStatus {
Ok, Ok,