From edac4b13944e4a007f10c91b241cb231af669748 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Fri, 16 Aug 2024 20:42:02 +0200 Subject: [PATCH] update --- .forgejo/workflows/deploy.yml | 3 ++- Cargo.lock | 6 +++--- src/library/album.rs | 4 +++- src/library/mod.rs | 25 ++++++++++++++++--------- src/library/track.rs | 3 ++- src/main.rs | 2 +- src/route/admin.rs | 1 + src/route/playlist.rs | 35 +++++++++++++++++++++++++++++++++-- 8 files changed, 61 insertions(+), 18 deletions(-) diff --git a/.forgejo/workflows/deploy.yml b/.forgejo/workflows/deploy.yml index 5ce3bfd..415b365 100644 --- a/.forgejo/workflows/deploy.yml +++ b/.forgejo/workflows/deploy.yml @@ -30,6 +30,7 @@ jobs: uses: docker/build-push-action@v4 with: context: . - platforms: linux/amd64,linux/arm64 +# platforms: linux/amd64,linux/arm64 + platforms: linux/amd64 push: true tags: git.hydrar.de/synthwrld/synthwave:latest diff --git a/Cargo.lock b/Cargo.lock index 22c111c..361d58d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1150,8 +1150,8 @@ dependencies = [ [[package]] name = "mongod" -version = "0.2.0" -source = "git+https://git.hydrar.de/jmarya/mongod#37cca40192d6e08e122c1e3c23f674d01e260ab3" +version = "0.2.1" +source = "git+https://git.hydrar.de/jmarya/mongod#228f113dbf04b04396f504685c7590b9a239e5a9" dependencies = [ "chrono", "futures", @@ -1167,7 +1167,7 @@ dependencies = [ [[package]] name = "mongod_derive" version = "0.1.0" -source = "git+https://git.hydrar.de/jmarya/mongod#37cca40192d6e08e122c1e3c23f674d01e260ab3" +source = "git+https://git.hydrar.de/jmarya/mongod#228f113dbf04b04396f504685c7590b9a239e5a9" dependencies = [ "case", "proc-macro2", diff --git a/src/library/album.rs b/src/library/album.rs index b5a4468..c8ee4b5 100644 --- a/src/library/album.rs +++ b/src/library/album.rs @@ -34,7 +34,9 @@ impl Album { } pub async fn get_tracks_of_album(album: &str) -> Vec { - Track::find(doc! { "album_id": album}, None).await.unwrap() + Track::find(doc! { "album_id": album}, None, None) + .await + .unwrap() } /// Returns the cover image of an album, or `None` if it doesn't exist. diff --git a/src/library/mod.rs b/src/library/mod.rs index 02af76b..fe90f3a 100644 --- a/src/library/mod.rs +++ b/src/library/mod.rs @@ -141,6 +141,7 @@ impl Libary { Album::find( doc! { "artist_id": reference_of!(Artist, artist).unwrap()}, None, + None, ) .await .unwrap() @@ -153,6 +154,7 @@ impl Libary { "artist_id": reference_of!(Artist, artist).unwrap() }, None, + None, ) .await .unwrap() @@ -240,7 +242,7 @@ impl Libary { pub async fn clean_lost_files(&self) { // tracks - for track in Track::find_partial(doc! {}, json!({"path": 1}), None) + for track in Track::find_partial(doc! {}, json!({"path": 1}), None, None) .await .unwrap() { @@ -250,14 +252,19 @@ impl Libary { } } // albums - for album in Album::find_partial(doc! {}, json!({"title": 1}), None) + for album in Album::find_partial(doc! {}, json!({"title": 1}), None, None) .await .unwrap() { - if Track::find_partial(doc! { "album_id": album.reference() }, json!({}), None) - .await - .unwrap() - .is_empty() + if Track::find_partial( + doc! { "album_id": album.reference() }, + json!({}), + None, + None, + ) + .await + .unwrap() + .is_empty() { log::info!( "Cleaning album {} with no tracks", @@ -267,15 +274,15 @@ impl Libary { } } // artists - for artist in Artist::find_partial(doc! {}, json!({"name": 1}), None) + for artist in Artist::find_partial(doc! {}, json!({"name": 1}), None, None) .await .unwrap() { - if Track::find_partial(doc! { "artist_id": artist.reference()}, json!({}), None) + if Track::find_partial(doc! { "artist_id": artist.reference()}, json!({}), None, None) .await .unwrap() .is_empty() - && Album::find_partial(doc! { "artist_id": artist.reference()}, json!({}), None) + && Album::find_partial(doc! { "artist_id": artist.reference()}, json!({}), None, None) .await .unwrap() .is_empty() diff --git a/src/library/track.rs b/src/library/track.rs index f37735f..e4f16d7 100644 --- a/src/library/track.rs +++ b/src/library/track.rs @@ -49,7 +49,7 @@ impl Track { /// Transcode audio to AAC with `bitrate` pub fn get_aac(&self, bitrate: u32) -> Option { - self.transcode("aac", bitrate, "m4a") + self.transcode("aac", bitrate, "aac") } /// Transcode audio @@ -90,6 +90,7 @@ impl Track { "album_id": None:: }, None, + None ) .await .unwrap() diff --git a/src/main.rs b/src/main.rs index 61ef708..ddd6eac 100644 --- a/src/main.rs +++ b/src/main.rs @@ -33,7 +33,7 @@ async fn rocket() -> _ { lib.rescan(&cache).await; // create initial admin user - if User::find(doc! { "username": "admin" }, None) + if User::find(doc! { "username": "admin" }, None, None) .await .is_none() { diff --git a/src/route/admin.rs b/src/route/admin.rs index f2dc35f..2c0f70c 100644 --- a/src/route/admin.rs +++ b/src/route/admin.rs @@ -24,6 +24,7 @@ pub async fn get_singles_route(u: User) -> FallibleApiResponse { let singles = Track::find( doc! { "album_id": None::, "artist_id": {"$ne": None:: }}, None, + None ) .await .unwrap(); diff --git a/src/route/playlist.rs b/src/route/playlist.rs index ffb78e3..8a205bd 100644 --- a/src/route/playlist.rs +++ b/src/route/playlist.rs @@ -21,7 +21,7 @@ use super::ToAPI; pub async fn playlists_route(u: User) -> FallibleApiResponse { let mut playlists = vec![json!({"id": "recent", "name": "Recently Played"})]; - let own_playlists = Playlist::find(doc! { "owner": u.reference()}, None) + let own_playlists = Playlist::find(doc! { "owner": u.reference()}, None, None) .await .unwrap(); @@ -35,10 +35,37 @@ pub async fn playlists_route(u: User) -> FallibleApiResponse { Ok(json!(playlists)) } +pub async fn recently_added_playlist() -> FallibleApiResponse { + let tracks = Track::find(doc! {}, Some(90), Some(doc! { "added": 1 })) + .await + .unwrap(); + Ok(json!(to_api(&tracks).await)) +} + #[get("/playlist/")] pub async fn playlist_route(id: &str, u: User) -> FallibleApiResponse { if id == "recents" { - // todo : recently played + return Ok(Playlist { + _id: "recents".to_string(), + owner: u.reference(), + title: "Recently Played".to_string(), + visibility: Visibility::Public, + tracks: vec![], + } + .api() + .await); + } + + if id == "recentlyAdded" { + return Ok(Playlist { + _id: "recentlyAdded".to_string(), + owner: u.reference(), + title: "Recently Added".to_string(), + visibility: Visibility::Public, + tracks: vec![], + } + .api() + .await); } let playlist = Playlist::get(id) @@ -60,6 +87,10 @@ pub async fn playlist_tracks_route(id: &str, u: User) -> FallibleApiResponse { // todo : recently played } + if id == "recentlyAdded" { + return recently_added_playlist().await; + } + let playlist = Playlist::get(id) .await .ok_or_else(|| api_error("No playlist with that ID found"))?;