From e77b0e57faded9ada172c2761865512cd99abf18 Mon Sep 17 00:00:00 2001 From: Lyssieth Date: Tue, 28 Nov 2023 05:16:38 +0200 Subject: [PATCH] feat: a few stubs --- rave/src/rest/get_podcasts.rs | 25 ---------------- rave/src/rest/mod.rs | 55 +++++++++++++++++++++++++++++++---- rave/src/subsonic/mod.rs | 17 ----------- 3 files changed, 49 insertions(+), 48 deletions(-) delete mode 100644 rave/src/rest/get_podcasts.rs diff --git a/rave/src/rest/get_podcasts.rs b/rave/src/rest/get_podcasts.rs deleted file mode 100644 index 34f1223..0000000 --- a/rave/src/rest/get_podcasts.rs +++ /dev/null @@ -1,25 +0,0 @@ -use crate::{json_or_xml, subsonic::SubResponseType, utils::db::DbTxn}; -use poem::web::Data; -use tracing::instrument; - -use crate::{ - authentication::Authentication, - subsonic::SubsonicResponse, - utils::{self}, -}; - -#[poem::handler] -#[instrument(skip(txn, auth))] -pub async fn get_podcasts(Data(txn): Data<&DbTxn>, auth: Authentication) -> poem::Response { - let u = utils::verify_user(txn.clone(), &auth).await; - - match u { - Ok(_) => {} - Err(e) => return json_or_xml!(auth, e), - }; - - json_or_xml!( - auth, - SubsonicResponse::new(SubResponseType::Podcasts { channels: vec![] }) - ) -} diff --git a/rave/src/rest/mod.rs b/rave/src/rest/mod.rs index d2dc29d..aa60538 100644 --- a/rave/src/rest/mod.rs +++ b/rave/src/rest/mod.rs @@ -1,4 +1,4 @@ -use poem::{Endpoint, EndpointExt, Route}; +use poem::{http::StatusCode, Endpoint, EndpointExt, Response, Route}; // rest/getLicense mod get_license; @@ -24,10 +24,8 @@ mod get_cover_art; mod get_artists; // rest/getArtist mod get_artist; -// rest/getPodcasts -mod get_podcasts; -// TODO: Fix the `.ping` issue, figure out how to make it work without the duplication. +// TODO: Fix the `.view` issue, figure out how to make it work without the duplication. pub fn build() -> Box> { Route::new() .at("/ping", ping::ping) @@ -59,7 +57,52 @@ pub fn build() -> Box> { .at("/getArtists.view", get_artists::get_artists) .at("/getArtist", get_artist::get_artist) .at("/getArtist.view", get_artist::get_artist) - .at("/getPodcasts", get_podcasts::get_podcasts) - .at("/getPodcasts.view", get_podcasts::get_podcasts) + .at("/getPodcasts", stub_podcasts) + .at("/getPodcasts.view", stub_podcasts) + .at("/getIndexes", stub_indexes) + .at("/getIndexes.view", stub_indexes) + .at("/getPlaylists", stub_playlists) + .at("/getPlaylists.view", stub_playlists) + .at("/getGenres", stub_genres) + .at("/getGenres.view", stub_genres) .boxed() } + +fn stub_response(empty: Option) -> String { + empty.map_or_else( + || r#"{"status": "ok", "version": "1.16.1"}"#.to_string(), + |v| format!(r#"{{"status": "ok", "version": "1.16.1", "{v}": []}}"#), + ) +} + +#[poem::handler] +fn stub_podcasts() -> Response { + Response::builder() + .status(StatusCode::OK) + .header("Content-Type", "application/json") + .body(stub_response(Some("podcasts".to_string()))) +} + +#[poem::handler] +fn stub_indexes() -> Response { + Response::builder() + .status(StatusCode::OK) + .header("Content-Type", "application/json") + .body(stub_response(Some("indexes".to_string()))) +} + +#[poem::handler] +fn stub_playlists() -> Response { + Response::builder() + .status(StatusCode::OK) + .header("Content-Type", "application/json") + .body(stub_response(Some("playlists".to_string()))) +} + +#[poem::handler] +fn stub_genres() -> Response { + Response::builder() + .status(StatusCode::OK) + .header("Content-Type", "application/json") + .body(stub_response(Some("genres".to_string()))) +} diff --git a/rave/src/subsonic/mod.rs b/rave/src/subsonic/mod.rs index 36a0d4b..8088ad5 100644 --- a/rave/src/subsonic/mod.rs +++ b/rave/src/subsonic/mod.rs @@ -114,15 +114,6 @@ where } SubResponseType::Artists { artists } => artists.serialize(s), SubResponseType::Artist { artist } => artist.serialize(s), - SubResponseType::Podcasts { channels } => { - #[derive(Serialize)] - struct Podcasts<'a> { - #[serde(rename = "podcasts")] - channels: &'a Vec, - } - - Podcasts { channels }.serialize(s) - } SubResponseType::Empty => s.serialize_none(), } } @@ -305,16 +296,8 @@ pub enum SubResponseType { #[serde(flatten)] artist: Box, }, - #[serde(rename = "podcasts")] - Podcasts { - #[serde(rename = "podcast")] - channels: Vec, - }, Empty, } -#[derive(Debug, Clone, Serialize)] -pub struct Podcast; - impl SubResponseType { pub const fn is_empty(&self) -> bool { matches!(self, Self::Empty)