update playlists
This commit is contained in:
parent
82c330cc13
commit
87ad77907b
5 changed files with 39 additions and 2 deletions
9
docs/Library.md
Normal file
9
docs/Library.md
Normal 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.
|
|
@ -37,7 +37,7 @@ impl Artist {
|
||||||
|
|
||||||
let artist_path = track_path.parent()?.parent()?;
|
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}"));
|
let cover_file = artist_path.join(format!("artist.{ext}"));
|
||||||
|
|
||||||
if cover_file.exists() {
|
if cover_file.exists() {
|
||||||
|
|
|
@ -65,6 +65,7 @@ impl ToAPI for Playlist {
|
||||||
serde_json::json!({
|
serde_json::json!({
|
||||||
"id": self._id,
|
"id": self._id,
|
||||||
"owner": self.owner.id(),
|
"owner": self.owner.id(),
|
||||||
|
"visibility": serde_json::to_value(&self.visibility).unwrap(),
|
||||||
"title": self.title,
|
"title": self.title,
|
||||||
"tracks": self.tracks.iter().map(|x| x.id()).collect::<Vec<_>>()
|
"tracks": self.tracks.iter().map(|x| x.id()).collect::<Vec<_>>()
|
||||||
})
|
})
|
||||||
|
|
|
@ -63,7 +63,8 @@ async fn rocket() -> _ {
|
||||||
route::playlist::playlists_route,
|
route::playlist::playlists_route,
|
||||||
route::playlist::playlist_route,
|
route::playlist::playlist_route,
|
||||||
route::playlist::playlist_add_route,
|
route::playlist::playlist_add_route,
|
||||||
route::playlist::playlist_edit_route
|
route::playlist::playlist_edit_route,
|
||||||
|
route::playlist::playlist_tracks_route
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.manage(lib)
|
.manage(lib)
|
||||||
|
|
|
@ -14,6 +14,7 @@ use crate::library::playlist::Visibility;
|
||||||
use crate::route::FallibleApiResponse;
|
use crate::route::FallibleApiResponse;
|
||||||
|
|
||||||
use super::api_error;
|
use super::api_error;
|
||||||
|
use super::to_api;
|
||||||
use super::ToAPI;
|
use super::ToAPI;
|
||||||
|
|
||||||
#[get("/playlists")]
|
#[get("/playlists")]
|
||||||
|
@ -53,6 +54,31 @@ pub async fn playlist_route(id: &str, u: User) -> FallibleApiResponse {
|
||||||
Ok(playlist.api().await)
|
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)]
|
#[derive(rocket::serde::Deserialize)]
|
||||||
pub struct PlaylistData {
|
pub struct PlaylistData {
|
||||||
pub title: String,
|
pub title: String,
|
||||||
|
|
Loading…
Reference in a new issue