This commit is contained in:
parent
5dac029b4e
commit
e77b0e57fa
3 changed files with 49 additions and 48 deletions
|
|
@ -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![] })
|
||||
)
|
||||
}
|
||||
|
|
@ -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<dyn Endpoint<Output = poem::Response>> {
|
||||
Route::new()
|
||||
.at("/ping", ping::ping)
|
||||
|
|
@ -59,7 +57,52 @@ pub fn build() -> Box<dyn Endpoint<Output = poem::Response>> {
|
|||
.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>) -> 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())))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Podcast>,
|
||||
}
|
||||
|
||||
Podcasts { channels }.serialize(s)
|
||||
}
|
||||
SubResponseType::Empty => s.serialize_none(),
|
||||
}
|
||||
}
|
||||
|
|
@ -305,16 +296,8 @@ pub enum SubResponseType {
|
|||
#[serde(flatten)]
|
||||
artist: Box<Artist>,
|
||||
},
|
||||
#[serde(rename = "podcasts")]
|
||||
Podcasts {
|
||||
#[serde(rename = "podcast")]
|
||||
channels: Vec<Podcast>,
|
||||
},
|
||||
Empty,
|
||||
}
|
||||
#[derive(Debug, Clone, Serialize)]
|
||||
pub struct Podcast;
|
||||
|
||||
impl SubResponseType {
|
||||
pub const fn is_empty(&self) -> bool {
|
||||
matches!(self, Self::Empty)
|
||||
|
|
|
|||
Loading…
Reference in a new issue