add cover api

This commit is contained in:
JMARyA 2024-08-02 23:28:32 +02:00
parent b4ad40f64f
commit 4a60f12c52
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263

View file

@ -86,13 +86,12 @@ impl Track {
impl ToAPI for Track { impl ToAPI for Track {
async fn api(&self) -> serde_json::Value { async fn api(&self) -> serde_json::Value {
let album_title = if let Some(album_ref) = &self.album_id { let (cover, album_title) = if let Some(album_ref) = &self.album_id {
album_ref let album = album_ref.get::<Album>().await;
.get_partial::<Album>(json!({"title": 1}))
.await (album.get_cover().await.is_some(), album.title)
.title
} else { } else {
None (false, String::new())
}; };
let artist_title = if let Some(artist_ref) = &self.artist_id { let artist_title = if let Some(artist_ref) = &self.artist_id {
@ -111,6 +110,11 @@ impl ToAPI for Track {
"meta": serde_json::to_value(&self.meta).unwrap(), "meta": serde_json::to_value(&self.meta).unwrap(),
"album_id": self.album_id.as_ref().map(|x| x.id().to_string()), "album_id": self.album_id.as_ref().map(|x| x.id().to_string()),
"album": album_title, "album": album_title,
"cover": if cover {
Some(format!("/album/{}/cover", self._id))
} else {
None
},
"artist_id": self.artist_id.as_ref().map(|x| x.id().to_string()), "artist_id": self.artist_id.as_ref().map(|x| x.id().to_string()),
"artist": artist_title "artist": artist_title
}) })