Add title to LibraryNodeChildren

This commit is contained in:
Hans Mündelein 2023-05-26 16:09:48 +02:00
parent 0731f61c41
commit ffec874584
Signed by: hans
GPG Key ID: BA7B55E984CE74F4
5 changed files with 33 additions and 16 deletions

View File

@ -26,6 +26,11 @@ service CrabidyService {
rpc GetTrackUpdates(GetTrackUpdatesRequest) returns (stream GetTrackUpdatesResponse); rpc GetTrackUpdates(GetTrackUpdatesRequest) returns (stream GetTrackUpdatesResponse);
} }
message LibraryNodeChild {
string uuid = 1;
string title = 2;
}
message GetQueueRequest {} message GetQueueRequest {}
message QueueTrackResponse {} message QueueTrackResponse {}
message QueueLibraryNodeResponse {} message QueueLibraryNodeResponse {}
@ -71,8 +76,8 @@ message Track {
message LibraryNode { message LibraryNode {
// Including provider // Including provider
string uuid = 1; string uuid = 1;
string name = 2; string title = 2;
repeated string children = 3; repeated LibraryNodeChild children = 3;
optional string parent = 4; optional string parent = 4;
LibraryNodeState state = 5; LibraryNodeState state = 5;
repeated Track tracks = 6; repeated Track tracks = 6;

View File

@ -1,7 +1,7 @@
pub mod proto; pub mod proto;
use async_trait::async_trait; use async_trait::async_trait;
use proto::crabidy::{LibraryNode, LibraryNodeState, Queue, Track}; use proto::crabidy::{LibraryNode, LibraryNodeChild, LibraryNodeState, Queue, Track};
#[async_trait] #[async_trait]
pub trait ProviderClient: std::fmt::Debug + Send + Sync { pub trait ProviderClient: std::fmt::Debug + Send + Sync {
@ -35,7 +35,7 @@ impl LibraryNode {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
uuid: "/".to_string(), uuid: "/".to_string(),
name: "/".to_string(), title: "/".to_string(),
children: Vec::new(), children: Vec::new(),
parent: None, parent: None,
state: LibraryNodeState::Unspecified as i32, state: LibraryNodeState::Unspecified as i32,
@ -45,6 +45,12 @@ impl LibraryNode {
} }
} }
impl LibraryNodeChild {
pub fn new(uuid: String, title: String) -> Self {
Self { uuid, title }
}
}
pub enum QueueError { pub enum QueueError {
NotQueable, NotQueable,
} }

View File

@ -6,9 +6,9 @@ use crabidy_core::proto::crabidy::{
GetActiveTrackRequest, GetActiveTrackResponse, GetLibraryNodeRequest, GetLibraryNodeResponse, GetActiveTrackRequest, GetActiveTrackResponse, GetLibraryNodeRequest, GetLibraryNodeResponse,
GetQueueRequest, GetQueueResponse, GetQueueUpdatesRequest, GetQueueUpdatesResponse, GetQueueRequest, GetQueueResponse, GetQueueUpdatesRequest, GetQueueUpdatesResponse,
GetTrackRequest, GetTrackResponse, GetTrackUpdatesRequest, GetTrackUpdatesResponse, GetTrackRequest, GetTrackResponse, GetTrackUpdatesRequest, GetTrackUpdatesResponse,
LibraryNode, Queue, QueueLibraryNodeRequest, QueueLibraryNodeResponse, QueuePositionChange, LibraryNode, LibraryNodeChild, Queue, QueueLibraryNodeRequest, QueueLibraryNodeResponse,
QueueTrackRequest, QueueTrackResponse, RemoveTracksRequest, RemoveTracksResponse, QueuePositionChange, QueueTrackRequest, QueueTrackResponse, RemoveTracksRequest,
ReplaceWithNodeRequest, ReplaceWithNodeResponse, ReplaceWithTrackRequest, RemoveTracksResponse, ReplaceWithNodeRequest, ReplaceWithNodeResponse, ReplaceWithTrackRequest,
ReplaceWithTrackResponse, SaveQueueRequest, SaveQueueResponse, SetCurrentTrackRequest, ReplaceWithTrackResponse, SaveQueueRequest, SaveQueueResponse, SetCurrentTrackRequest,
SetCurrentTrackResponse, StopRequest, StopResponse, TogglePlayRequest, TogglePlayResponse, SetCurrentTrackResponse, StopRequest, StopResponse, TogglePlayRequest, TogglePlayResponse,
Track, Track,
@ -148,7 +148,7 @@ impl ProviderOrchestrator {
continue continue
}; };
tracks.extend(node.tracks); tracks.extend(node.tracks);
nodes_to_go.extend(node.children); nodes_to_go.extend(node.children.into_iter().map(|c| c.uuid))
} }
tracks tracks
} }
@ -191,7 +191,8 @@ impl ProviderClient for ProviderOrchestrator {
} }
fn get_lib_root(&self) -> LibraryNode { fn get_lib_root(&self) -> LibraryNode {
let mut root_node = LibraryNode::new(); let mut root_node = LibraryNode::new();
root_node.children.push("tidal".to_owned()); let child = LibraryNodeChild::new("tidal".to_owned(), "tidal".to_owned());
root_node.children.push(child);
root_node root_node
} }
async fn get_lib_node(&self, uuid: &str) -> Result<LibraryNode, ProviderError> { async fn get_lib_node(&self, uuid: &str) -> Result<LibraryNode, ProviderError> {

View File

@ -65,10 +65,13 @@ impl crabidy_core::ProviderClient for Client {
fn get_lib_root(&self) -> crabidy_core::proto::crabidy::LibraryNode { fn get_lib_root(&self) -> crabidy_core::proto::crabidy::LibraryNode {
let global_root = crabidy_core::proto::crabidy::LibraryNode::new(); let global_root = crabidy_core::proto::crabidy::LibraryNode::new();
let children = vec!["userplaylists".to_string()]; let children = vec![crabidy_core::proto::crabidy::LibraryNodeChild::new(
"userplaylists".to_string(),
"playlists".to_string(),
)];
crabidy_core::proto::crabidy::LibraryNode { crabidy_core::proto::crabidy::LibraryNode {
uuid: "tidal".to_string(), uuid: "tidal".to_string(),
name: "tidal".to_string(), title: "tidal".to_string(),
parent: Some(format!("{}", global_root.uuid)), parent: Some(format!("{}", global_root.uuid)),
state: crabidy_core::proto::crabidy::LibraryNodeState::Done as i32, state: crabidy_core::proto::crabidy::LibraryNodeState::Done as i32,
tracks: Vec::new(), tracks: Vec::new(),
@ -87,10 +90,9 @@ impl crabidy_core::ProviderClient for Client {
let (module, uuid) = split_uuid(uuid); let (module, uuid) = split_uuid(uuid);
let node = match module.as_str() { let node = match module.as_str() {
"userplaylists" => { "userplaylists" => {
let global_root = crabidy_core::proto::crabidy::LibraryNode::new();
let mut node = crabidy_core::proto::crabidy::LibraryNode { let mut node = crabidy_core::proto::crabidy::LibraryNode {
uuid: "userplaylists".to_string(), uuid: "userplaylists".to_string(),
name: "playlists".to_string(), title: "playlists".to_string(),
parent: Some("tidal".to_string()), parent: Some("tidal".to_string()),
state: crabidy_core::proto::crabidy::LibraryNodeState::Unspecified as i32, state: crabidy_core::proto::crabidy::LibraryNodeState::Unspecified as i32,
tracks: Vec::new(), tracks: Vec::new(),
@ -101,8 +103,11 @@ impl crabidy_core::ProviderClient for Client {
.get_users_playlists_and_favorite_playlists(&user_id) .get_users_playlists_and_favorite_playlists(&user_id)
.await? .await?
{ {
node.children let child = crabidy_core::proto::crabidy::LibraryNodeChild::new(
.push(format!("playlist:{}", playlist.playlist.uuid)); format!("playlist:{}", playlist.playlist.uuid),
playlist.playlist.title,
);
node.children.push(child);
} }
node node
} }

View File

@ -305,7 +305,7 @@ pub struct Playlist {
impl From<Playlist> for crabidy_core::proto::crabidy::LibraryNode { impl From<Playlist> for crabidy_core::proto::crabidy::LibraryNode {
fn from(a: Playlist) -> Self { fn from(a: Playlist) -> Self {
crabidy_core::proto::crabidy::LibraryNode { crabidy_core::proto::crabidy::LibraryNode {
name: a.title, title: a.title,
uuid: format!("playlist:{}", a.uuid), uuid: format!("playlist:{}", a.uuid),
tracks: Vec::new(), tracks: Vec::new(),
parent: None, parent: None,