Structure

This commit is contained in:
2023-08-14 11:27:37 +01:00
parent 0024150376
commit 41fcffb43d
12 changed files with 2032 additions and 23 deletions

View File

@ -0,0 +1,2 @@
struct NavidromeBuilder {
}

View File

@ -1,13 +1,20 @@
pub mod builder;
pub mod playlists;
pub struct Client {
trait QualifyPath {
fn path(&self, path: &str) -> String;
}
pub type MediaResult<U> = Result<U, reqwest::Error>;
pub struct Navidrome {
base: String,
http: reqwest::Client,
token: String,
}
impl Client {
fn playlists() {
const
impl QualifyPath for Navidrome {
fn path(&self, path: &str) -> String {
format!("{}/{}", self.base, path)
}
}

View File

@ -0,0 +1,43 @@
use crate::client::{MediaResult as Result, Navidrome, QualifyPath};
use crate::models::generic::Playlist;
use crate::models::navidrome::NavidromePlaylist;
use async_trait::async_trait;
#[async_trait]
pub trait Playlists {
async fn playlists(&self) -> Result<Vec<Playlist>>;
async fn playlist(&self, id: String) -> Result<Playlist>;
async fn create_playlist(&self) -> Result<Playlist>;
async fn delete_playlist(&self) -> Result<()>;
async fn update_playlists(&self) -> Result<()>;
}
#[async_trait]
impl Playlists for Navidrome {
async fn playlists(&self) -> Result<Vec<Playlist>> {
self.http
.get(self.path("api/playlist"))
.header("X-Nd-Authorization", format!("Bearer {}", self.token))
.send()
.await?
.json::<Vec<NavidromePlaylist>>()
.await
.map(|pv| pv.iter().map(|p| p.into()).collect())
}
async fn playlist(&self, id: String) -> Result<Playlist> {
todo!()
}
async fn create_playlist(&self) -> Result<Playlist> {
todo!()
}
async fn delete_playlist(&self) -> Result<()> {
todo!()
}
async fn update_playlists(&self) -> Result<()> {
todo!()
}
}

View File

@ -1,15 +0,0 @@
use serde::Deserialize;
#[derive(Deserialize)]
struct LoginResponse {
id: String, // todo should be a uuid
#[serde(rename = "isAdmin")]
is_admin: bool,
name: String,
#[serde(rename = "subsonicSalt")]
subsonic_salt: String,
#[serde(rename = "subsonicToken")]
subsonic_token: String,
token: String,
username: String,
}

View File

@ -0,0 +1,9 @@
use chrono::NaiveDateTime;
pub struct Playlist {
// items: dyn Iterator<Item = Song>,
pub name: String,
pub comment: Option<String>,
pub created_at: Option<NaiveDateTime>,
pub file: Option<String>,
}

View File

@ -0,0 +1,2 @@
pub mod generic;
pub mod navidrome;

View File

@ -0,0 +1,58 @@
use crate::models::generic::Playlist;
use chrono::NaiveDateTime;
use serde::Deserialize;
use std::iter::Iterator;
#[derive(Deserialize)]
struct LoginResponse {
id: String, // todo should be a uuid
#[serde(rename = "isAdmin")]
is_admin: bool,
name: String,
#[serde(rename = "subsonicSalt")]
subsonic_salt: String,
#[serde(rename = "subsonicToken")]
subsonic_token: String,
token: String,
username: String,
}
#[derive(Deserialize)]
pub(crate) struct NavidromePlaylist {
name: String,
comment: String,
#[serde(rename = "createdAt")]
created_at: NaiveDateTime,
path: String,
public: bool,
size: u64,
duration: f64,
#[serde(rename = "evaluatedAt")]
evaluated_at: NaiveDateTime,
id: String,
#[serde(rename = "ownerId")]
owner_id: String,
#[serde(rename = "ownerName")]
owner_name: String,
#[serde(skip)] // todo fix
rules: Option<NavidromePlaylistRule>,
#[serde(rename = "songCount")]
song_count: u64,
sync: bool,
#[serde(rename = "updatedAt")]
updated_at: NaiveDateTime,
}
impl From<&NavidromePlaylist> for Playlist {
fn from(value: &NavidromePlaylist) -> Self {
Playlist {
name: value.name.clone(),
comment: Some(value.comment.clone()),
created_at: Some(value.created_at),
file: Some(value.path.clone()),
}
}
}
#[derive(Deserialize)]
struct NavidromePlaylistRule {}