From 87ad77907ba0d9e32c171327f0d5530d74628224 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Mon, 12 Aug 2024 03:43:08 +0200 Subject: [PATCH] update playlists --- docs/Library.md | 9 +++++++++ src/library/artist.rs | 2 +- src/library/playlist.rs | 1 + src/main.rs | 3 ++- src/route/playlist.rs | 26 ++++++++++++++++++++++++++ 5 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 docs/Library.md diff --git a/docs/Library.md b/docs/Library.md new file mode 100644 index 0000000..de4d63a --- /dev/null +++ b/docs/Library.md @@ -0,0 +1,9 @@ +# Library +Synthwave searches for music files inside of the `./media` directory. +The general structure should be like `Artist/Album/Track`. + +## Artist Image +The artists image is an image file named `artist` in the artists presumed directory, which is derived from the folder structure. This image can have animation. + +## Album Cover +The album cover is an image file named `cover` inside the albums directory. This image can have animation. diff --git a/src/library/artist.rs b/src/library/artist.rs index 0c5e49e..3412979 100644 --- a/src/library/artist.rs +++ b/src/library/artist.rs @@ -37,7 +37,7 @@ impl Artist { let artist_path = track_path.parent()?.parent()?; - for ext in ["png", "jpg", "jpeg", "avif"] { + for ext in ["png", "jpg", "jpeg", "avif", "webp"] { let cover_file = artist_path.join(format!("artist.{ext}")); if cover_file.exists() { diff --git a/src/library/playlist.rs b/src/library/playlist.rs index 0c7147b..1485def 100644 --- a/src/library/playlist.rs +++ b/src/library/playlist.rs @@ -65,6 +65,7 @@ impl ToAPI for Playlist { serde_json::json!({ "id": self._id, "owner": self.owner.id(), + "visibility": serde_json::to_value(&self.visibility).unwrap(), "title": self.title, "tracks": self.tracks.iter().map(|x| x.id()).collect::>() }) diff --git a/src/main.rs b/src/main.rs index 3792cc1..3eeca8d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,7 +63,8 @@ async fn rocket() -> _ { route::playlist::playlists_route, route::playlist::playlist_route, route::playlist::playlist_add_route, - route::playlist::playlist_edit_route + route::playlist::playlist_edit_route, + route::playlist::playlist_tracks_route ], ) .manage(lib) diff --git a/src/route/playlist.rs b/src/route/playlist.rs index 68a147c..ffb78e3 100644 --- a/src/route/playlist.rs +++ b/src/route/playlist.rs @@ -14,6 +14,7 @@ use crate::library::playlist::Visibility; use crate::route::FallibleApiResponse; use super::api_error; +use super::to_api; use super::ToAPI; #[get("/playlists")] @@ -53,6 +54,31 @@ pub async fn playlist_route(id: &str, u: User) -> FallibleApiResponse { Ok(playlist.api().await) } +#[get("/playlist//tracks")] +pub async fn playlist_tracks_route(id: &str, u: User) -> FallibleApiResponse { + if id == "recents" { + // todo : recently played + } + + let playlist = Playlist::get(id) + .await + .ok_or_else(|| api_error("No playlist with that ID found"))?; + + if matches!(playlist.visibility, Visibility::Private) + && u.username != playlist.owner.get::().await.username + { + return Err(api_error("Forbidden")); + } + + let mut tracks: Vec = vec![]; + + for track in playlist.tracks { + tracks.push(track.get().await); + } + + Ok(json!(to_api(&tracks).await)) +} + #[derive(rocket::serde::Deserialize)] pub struct PlaylistData { pub title: String,