update playlists

This commit is contained in:
JMARyA 2024-08-12 03:43:08 +02:00
parent 82c330cc13
commit 87ad77907b
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
5 changed files with 39 additions and 2 deletions

9
docs/Library.md Normal file
View file

@ -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.

View file

@ -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() {

View file

@ -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::<Vec<_>>()
})

View file

@ -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)

View file

@ -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/<id>/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::<User>().await.username
{
return Err(api_error("Forbidden"));
}
let mut tracks: Vec<Track> = 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,