add cover api
This commit is contained in:
parent
b4ad40f64f
commit
4a60f12c52
1 changed files with 10 additions and 6 deletions
|
@ -86,13 +86,12 @@ impl Track {
|
|||
|
||||
impl ToAPI for Track {
|
||||
async fn api(&self) -> serde_json::Value {
|
||||
let album_title = if let Some(album_ref) = &self.album_id {
|
||||
album_ref
|
||||
.get_partial::<Album>(json!({"title": 1}))
|
||||
.await
|
||||
.title
|
||||
let (cover, album_title) = if let Some(album_ref) = &self.album_id {
|
||||
let album = album_ref.get::<Album>().await;
|
||||
|
||||
(album.get_cover().await.is_some(), album.title)
|
||||
} else {
|
||||
None
|
||||
(false, String::new())
|
||||
};
|
||||
|
||||
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(),
|
||||
"album_id": self.album_id.as_ref().map(|x| x.id().to_string()),
|
||||
"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": artist_title
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue