This commit is contained in:
JMARyA 2024-08-16 20:42:02 +02:00
parent 636ad0bf34
commit edac4b1394
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
8 changed files with 61 additions and 18 deletions

View file

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

6
Cargo.lock generated
View file

@ -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",

View file

@ -34,7 +34,9 @@ impl Album {
}
pub async fn get_tracks_of_album(album: &str) -> Vec<Track> {
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.

View file

@ -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,11 +252,16 @@ 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)
if Track::find_partial(
doc! { "album_id": album.reference() },
json!({}),
None,
None,
)
.await
.unwrap()
.is_empty()
@ -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()

View file

@ -49,7 +49,7 @@ impl Track {
/// Transcode audio to AAC with `bitrate`
pub fn get_aac(&self, bitrate: u32) -> Option<String> {
self.transcode("aac", bitrate, "m4a")
self.transcode("aac", bitrate, "aac")
}
/// Transcode audio
@ -90,6 +90,7 @@ impl Track {
"album_id": None::<String>
},
None,
None
)
.await
.unwrap()

View file

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

View file

@ -24,6 +24,7 @@ pub async fn get_singles_route(u: User) -> FallibleApiResponse {
let singles = Track::find(
doc! { "album_id": None::<String>, "artist_id": {"$ne": None::<String> }},
None,
None
)
.await
.unwrap();

View file

@ -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/<id>")]
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"))?;