Remove crabidy, graphql from cbd-tui
This commit is contained in:
parent
0b9e6ceebe
commit
596a97c99d
|
|
@ -2,18 +2,6 @@
|
||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 3
|
version = 3
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "Inflector"
|
|
||||||
version = "0.11.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "aliasable"
|
|
||||||
version = "0.1.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "250f629c0161ad8107cf89319e990051fae62832fd343083bea452d93e2205fd"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "android_system_properties"
|
name = "android_system_properties"
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
|
|
@ -29,12 +17,6 @@ version = "1.0.71"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
|
checksum = "9c7d0618f0e0b7e8ff11427422b64564d5fb0be1940354bfe2e0529b18a9d9b8"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ascii"
|
|
||||||
version = "0.9.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "eab1c04a571841102f5345a8fc0f6bb3d31c315dec879b5c6e42e40ce7ffa34e"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "async-trait"
|
name = "async-trait"
|
||||||
version = "0.1.68"
|
version = "0.1.68"
|
||||||
|
|
@ -130,12 +112,6 @@ version = "3.12.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3c6ed94e98ecff0c12dd1b04c15ec0d7d9458ca8fe806cea6f12954efe74c63b"
|
checksum = "3c6ed94e98ecff0c12dd1b04c15ec0d7d9458ca8fe806cea6f12954efe74c63b"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "byteorder"
|
|
||||||
version = "1.4.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bytes"
|
name = "bytes"
|
||||||
version = "1.4.0"
|
version = "1.4.0"
|
||||||
|
|
@ -152,12 +128,12 @@ checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53"
|
||||||
name = "cbd-tui"
|
name = "cbd-tui"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"crabidy-core",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
"cynic",
|
|
||||||
"flume",
|
"flume",
|
||||||
"ratatui",
|
"ratatui",
|
||||||
"reqwest",
|
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tonic",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
@ -197,19 +173,6 @@ dependencies = [
|
||||||
"winapi",
|
"winapi",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "combine"
|
|
||||||
version = "3.8.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "da3da6baa321ec19e1cc41d31bf599f00c783d0517095cdaf0332e3fe8d20680"
|
|
||||||
dependencies = [
|
|
||||||
"ascii",
|
|
||||||
"byteorder",
|
|
||||||
"either",
|
|
||||||
"memchr",
|
|
||||||
"unreachable",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "confique"
|
name = "confique"
|
||||||
version = "0.2.3"
|
version = "0.2.3"
|
||||||
|
|
@ -251,15 +214,6 @@ version = "0.8.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
|
checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "counter"
|
|
||||||
version = "0.5.7"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2d458e66999348f56fd3ffcfbb7f7951542075ca8359687c703de6500c1ddccd"
|
|
||||||
dependencies = [
|
|
||||||
"num-traits",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cpufeatures"
|
name = "cpufeatures"
|
||||||
version = "0.2.7"
|
version = "0.2.7"
|
||||||
|
|
@ -269,16 +223,6 @@ dependencies = [
|
||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "crabidy"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"crabidy-core",
|
|
||||||
"tokio",
|
|
||||||
"tokio-stream",
|
|
||||||
"tonic",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "crabidy-core"
|
name = "crabidy-core"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
|
|
@ -344,83 +288,6 @@ dependencies = [
|
||||||
"typenum",
|
"typenum",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cynic"
|
|
||||||
version = "3.0.0-beta.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2155e722fd76f4fa51635811279242e78cf312de1165e53cec4316425fd97c4d"
|
|
||||||
dependencies = [
|
|
||||||
"cynic-proc-macros",
|
|
||||||
"reqwest",
|
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
"static_assertions",
|
|
||||||
"thiserror",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cynic-codegen"
|
|
||||||
version = "3.0.0-beta.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "2454afe901e4de5b4cbdf45a18453fff9d6dfe3bb096babd6a62882995a5138c"
|
|
||||||
dependencies = [
|
|
||||||
"counter",
|
|
||||||
"darling",
|
|
||||||
"graphql-parser",
|
|
||||||
"once_cell",
|
|
||||||
"ouroboros",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"strsim",
|
|
||||||
"syn 1.0.109",
|
|
||||||
"thiserror",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "cynic-proc-macros"
|
|
||||||
version = "3.0.0-beta.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6fd3ce67a4faeea7002a853acefe43938bc897d593f11abd76039dfb7ec445f0"
|
|
||||||
dependencies = [
|
|
||||||
"cynic-codegen",
|
|
||||||
"syn 1.0.109",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "darling"
|
|
||||||
version = "0.14.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "7b750cb3417fd1b327431a470f388520309479ab0bf5e323505daf0290cd3850"
|
|
||||||
dependencies = [
|
|
||||||
"darling_core",
|
|
||||||
"darling_macro",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "darling_core"
|
|
||||||
version = "0.14.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "109c1ca6e6b7f82cc233a97004ea8ed7ca123a9af07a8230878fcfda9b158bf0"
|
|
||||||
dependencies = [
|
|
||||||
"fnv",
|
|
||||||
"ident_case",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"strsim",
|
|
||||||
"syn 1.0.109",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "darling_macro"
|
|
||||||
version = "0.14.4"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a4aab4dbc9f7611d8b55048a3a16d2d010c2c8334e46304b40ac1cc14bf3b48e"
|
|
||||||
dependencies = [
|
|
||||||
"darling_core",
|
|
||||||
"quote",
|
|
||||||
"syn 1.0.109",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "digest"
|
name = "digest"
|
||||||
version = "0.10.7"
|
version = "0.10.7"
|
||||||
|
|
@ -709,16 +576,6 @@ dependencies = [
|
||||||
"system-deps",
|
"system-deps",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "graphql-parser"
|
|
||||||
version = "0.4.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "d2ebc8013b4426d5b81a4364c419a95ed0b404af2b82e2457de52d9348f0e474"
|
|
||||||
dependencies = [
|
|
||||||
"combine",
|
|
||||||
"thiserror",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gstreamer"
|
name = "gstreamer"
|
||||||
version = "0.20.5"
|
version = "0.20.5"
|
||||||
|
|
@ -1005,12 +862,6 @@ dependencies = [
|
||||||
"cc",
|
"cc",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ident_case"
|
|
||||||
version = "1.0.1"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "idna"
|
name = "idna"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
|
@ -1297,29 +1148,6 @@ dependencies = [
|
||||||
"paste",
|
"paste",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ouroboros"
|
|
||||||
version = "0.15.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "e1358bd1558bd2a083fed428ffeda486fbfb323e698cdda7794259d592ca72db"
|
|
||||||
dependencies = [
|
|
||||||
"aliasable",
|
|
||||||
"ouroboros_macro",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "ouroboros_macro"
|
|
||||||
version = "0.15.6"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "5f7d21ccd03305a674437ee1248f3ab5d4b1db095cf1caf49f1713ddf61956b7"
|
|
||||||
dependencies = [
|
|
||||||
"Inflector",
|
|
||||||
"proc-macro-error",
|
|
||||||
"proc-macro2",
|
|
||||||
"quote",
|
|
||||||
"syn 1.0.109",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "parking_lot"
|
name = "parking_lot"
|
||||||
version = "0.12.1"
|
version = "0.12.1"
|
||||||
|
|
@ -1956,18 +1784,6 @@ dependencies = [
|
||||||
"lock_api",
|
"lock_api",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "static_assertions"
|
|
||||||
version = "1.1.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "strsim"
|
|
||||||
version = "0.10.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "1.0.109"
|
version = "1.0.109"
|
||||||
|
|
@ -2367,15 +2183,6 @@ version = "0.1.10"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
|
checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "unreachable"
|
|
||||||
version = "1.0.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
|
|
||||||
dependencies = [
|
|
||||||
"void",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "unsafe-libyaml"
|
name = "unsafe-libyaml"
|
||||||
version = "0.2.8"
|
version = "0.2.8"
|
||||||
|
|
@ -2417,12 +2224,6 @@ version = "0.9.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "void"
|
|
||||||
version = "1.0.2"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "want"
|
name = "want"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,2 @@
|
||||||
[workspace]
|
[workspace]
|
||||||
members = ["cbd-tui", "crabidy-core", "crabidy-server", "crabidy", "tidaldy"]
|
members = ["cbd-tui", "crabidy-core", "crabidy-server", "tidaldy"]
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
crossterm = "0.26.1"
|
crossterm = "0.26.1"
|
||||||
cynic = { version = "3.0.0-beta.3", features = ["http-reqwest"] }
|
crabidy-core = { path = "../crabidy-core" }
|
||||||
flume = "0.10.14"
|
flume = "0.10.14"
|
||||||
ratatui = "0.20.1"
|
ratatui = "0.20.1"
|
||||||
reqwest = { version = "0.11", features = ["json"] }
|
|
||||||
tokio = { version = "1", features = ["full"] }
|
tokio = { version = "1", features = ["full"] }
|
||||||
|
tonic = "0.9"
|
||||||
|
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
#[cynic::schema_for_derives(file = r#"schema.graphql"#, module = "schema")]
|
|
||||||
pub mod queries {
|
|
||||||
use super::schema;
|
|
||||||
|
|
||||||
#[derive(cynic::QueryFragment, Debug)]
|
|
||||||
#[cynic(graphql_type = "Root")]
|
|
||||||
pub struct AllFilmsQuery {
|
|
||||||
pub all_films: Option<FilmsConnection>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(cynic::QueryFragment, Debug)]
|
|
||||||
pub struct FilmsConnection {
|
|
||||||
pub films: Option<Vec<Option<Film>>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(cynic::QueryFragment, Debug)]
|
|
||||||
pub struct Film {
|
|
||||||
pub id: cynic::Id,
|
|
||||||
pub title: Option<String>,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(non_snake_case, non_camel_case_types)]
|
|
||||||
mod schema {
|
|
||||||
cynic::use_schema!(r#"schema.graphql"#);
|
|
||||||
}
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
mod graphql;
|
use crabidy_core::proto::crabidy::{
|
||||||
|
crabidy_service_client::CrabidyServiceClient, GetLibraryNodeRequest,
|
||||||
|
};
|
||||||
|
|
||||||
use crossterm::{
|
use crossterm::{
|
||||||
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind},
|
event::{self, DisableMouseCapture, EnableMouseCapture, Event, KeyCode, KeyEventKind},
|
||||||
|
|
@ -20,8 +22,8 @@ use std::{
|
||||||
time::{Duration, Instant},
|
time::{Duration, Instant},
|
||||||
vec,
|
vec,
|
||||||
};
|
};
|
||||||
|
use tonic::Request;
|
||||||
|
|
||||||
use cynic::{http::ReqwestExt, QueryBuilder};
|
|
||||||
use tokio::task;
|
use tokio::task;
|
||||||
|
|
||||||
struct StatefulList<T> {
|
struct StatefulList<T> {
|
||||||
|
|
@ -141,7 +143,7 @@ enum Message {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let (ui_tx, rx): (Sender<Message>, Receiver<Message>) = flume::unbounded();
|
let (ui_tx, rx): (Sender<Message>, Receiver<Message>) = flume::unbounded();
|
||||||
let (tx, ui_rx): (Sender<Message>, Receiver<Message>) = flume::unbounded();
|
let (tx, ui_rx): (Sender<Message>, Receiver<Message>) = flume::unbounded();
|
||||||
|
|
||||||
|
|
@ -149,31 +151,19 @@ async fn main() {
|
||||||
run_ui(ui_tx, ui_rx);
|
run_ui(ui_tx, ui_rx);
|
||||||
});
|
});
|
||||||
|
|
||||||
// FIXME: move into some request function
|
let mut client = CrabidyServiceClient::connect("http://[::1]:50051").await?;
|
||||||
let operation = graphql::queries::AllFilmsQuery::build(());
|
|
||||||
|
|
||||||
let client = reqwest::Client::new();
|
let request = Request::new(GetLibraryNodeRequest {
|
||||||
|
uuid: "/".to_string(),
|
||||||
|
});
|
||||||
|
|
||||||
let response = client
|
let response = client.get_library_node(request).await?;
|
||||||
.post("https://swapi-graphql.netlify.app/.netlify/functions/index")
|
|
||||||
.run_graphql(operation)
|
|
||||||
.await
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
if let Some(data) = response.data {
|
if let Some(node) = response.into_inner().node {
|
||||||
if let Some(films) = data.all_films {
|
node.children.iter().for_each(|c| {
|
||||||
if let Some(list) = films.films {
|
tx.send(Message::LibraryData(c.to_string()));
|
||||||
// FIXME: Collect into array/vector instead and send it all over at once
|
|
||||||
list.iter().for_each(|mut f| {
|
|
||||||
if let Some(film) = f {
|
|
||||||
if let Some(title) = &film.title {
|
|
||||||
tx.send(Message::LibraryData(title.to_string()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match rx.recv() {
|
match rx.recv() {
|
||||||
|
|
@ -183,6 +173,8 @@ async fn main() {
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_ui(tx: Sender<Message>, rx: Receiver<Message>) {
|
fn run_ui(tx: Sender<Message>, rx: Receiver<Message>) {
|
||||||
|
|
|
||||||
|
|
@ -1,12 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "crabidy"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2021"
|
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
crabidy-core = { path = "../crabidy-core" }
|
|
||||||
tonic = "0.9"
|
|
||||||
tokio = { version = "1", features = ["full"] }
|
|
||||||
tokio-stream = "0.1"
|
|
||||||
|
|
@ -1,203 +0,0 @@
|
||||||
use std::{pin::Pin, vec};
|
|
||||||
|
|
||||||
use crabidy_core::proto::crabidy::{
|
|
||||||
crabidy_service_server::{CrabidyService, CrabidyServiceServer},
|
|
||||||
AppendNodeRequest, AppendTrackRequest, EmptyRequest, EmptyResponse, GetActiveTrackResponse,
|
|
||||||
GetLibraryNodeRequest, GetLibraryNodeResponse, GetQueueResponse, GetQueueUpdatesRequest,
|
|
||||||
GetQueueUpdatesResponse, GetTrackRequest, GetTrackResponse, GetTrackUpdatesRequest,
|
|
||||||
GetTrackUpdatesResponse, LibraryNode, LibraryNodeState, QueueLibraryNodeRequest,
|
|
||||||
QueueTrackRequest, RemoveTracksRequest, ReplaceWithNodeRequest, ReplaceWithTrackRequest,
|
|
||||||
SaveQueueRequest, SetCurrentTrackRequest,
|
|
||||||
};
|
|
||||||
use tokio::sync::mpsc;
|
|
||||||
use tokio_stream::wrappers::ReceiverStream;
|
|
||||||
use tonic::{codegen::futures_core::Stream, transport::Server, Request, Response, Status};
|
|
||||||
|
|
||||||
type GetQueueUpdatesStream =
|
|
||||||
Pin<Box<dyn Stream<Item = Result<GetQueueUpdatesResponse, Status>> + Send>>;
|
|
||||||
type GetTrackUpdatesStream =
|
|
||||||
Pin<Box<dyn Stream<Item = Result<GetTrackUpdatesResponse, Status>> + Send>>;
|
|
||||||
|
|
||||||
#[derive(Debug, Default)]
|
|
||||||
pub struct Service {}
|
|
||||||
|
|
||||||
#[tonic::async_trait]
|
|
||||||
impl CrabidyService for Service {
|
|
||||||
type GetQueueUpdatesStream = GetQueueUpdatesStream;
|
|
||||||
type GetTrackUpdatesStream = GetTrackUpdatesStream;
|
|
||||||
|
|
||||||
async fn get_library_node(
|
|
||||||
&self,
|
|
||||||
request: Request<GetLibraryNodeRequest>,
|
|
||||||
) -> Result<Response<GetLibraryNodeResponse>, Status> {
|
|
||||||
println!("Got a library node request: {:?}", request);
|
|
||||||
|
|
||||||
let req = request.into_inner();
|
|
||||||
|
|
||||||
let reply = GetLibraryNodeResponse {
|
|
||||||
node: Some(LibraryNode {
|
|
||||||
uuid: "1".to_owned(),
|
|
||||||
name: "Tidal".to_owned(),
|
|
||||||
children: vec![
|
|
||||||
"Berlin, Texas".to_owned(),
|
|
||||||
"Spacefarer".to_owned(),
|
|
||||||
"Italo Disco".to_owned(),
|
|
||||||
],
|
|
||||||
parent: None,
|
|
||||||
tracks: vec![],
|
|
||||||
state: LibraryNodeState::Unspecified.into(),
|
|
||||||
is_queable: true,
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
Ok(Response::new(reply))
|
|
||||||
}
|
|
||||||
async fn get_track(
|
|
||||||
&self,
|
|
||||||
request: Request<GetTrackRequest>,
|
|
||||||
) -> Result<Response<GetTrackResponse>, Status> {
|
|
||||||
println!("Got a track request: {:?}", request);
|
|
||||||
|
|
||||||
let req = request.into_inner();
|
|
||||||
|
|
||||||
let reply = GetTrackResponse { track: None };
|
|
||||||
Ok(Response::new(reply))
|
|
||||||
}
|
|
||||||
async fn queue_track(
|
|
||||||
&self,
|
|
||||||
request: Request<QueueTrackRequest>,
|
|
||||||
) -> Result<Response<EmptyResponse>, Status> {
|
|
||||||
let reply = EmptyResponse {};
|
|
||||||
Ok(Response::new(reply))
|
|
||||||
}
|
|
||||||
async fn queue_library_node(
|
|
||||||
&self,
|
|
||||||
request: Request<QueueLibraryNodeRequest>,
|
|
||||||
) -> Result<Response<EmptyResponse>, Status> {
|
|
||||||
let reply = EmptyResponse {};
|
|
||||||
Ok(Response::new(reply))
|
|
||||||
}
|
|
||||||
async fn replace_with_track(
|
|
||||||
&self,
|
|
||||||
request: Request<ReplaceWithTrackRequest>,
|
|
||||||
) -> Result<Response<EmptyResponse>, Status> {
|
|
||||||
let reply = EmptyResponse {};
|
|
||||||
Ok(Response::new(reply))
|
|
||||||
}
|
|
||||||
async fn replace_with_node(
|
|
||||||
&self,
|
|
||||||
request: Request<ReplaceWithNodeRequest>,
|
|
||||||
) -> Result<Response<EmptyResponse>, Status> {
|
|
||||||
let reply = EmptyResponse {};
|
|
||||||
Ok(Response::new(reply))
|
|
||||||
}
|
|
||||||
async fn append_track(
|
|
||||||
&self,
|
|
||||||
request: Request<AppendTrackRequest>,
|
|
||||||
) -> Result<Response<EmptyResponse>, Status> {
|
|
||||||
let reply = EmptyResponse {};
|
|
||||||
Ok(Response::new(reply))
|
|
||||||
}
|
|
||||||
async fn append_node(
|
|
||||||
&self,
|
|
||||||
request: Request<AppendNodeRequest>,
|
|
||||||
) -> Result<Response<EmptyResponse>, Status> {
|
|
||||||
let reply = EmptyResponse {};
|
|
||||||
Ok(Response::new(reply))
|
|
||||||
}
|
|
||||||
async fn remove_tracks(
|
|
||||||
&self,
|
|
||||||
request: Request<RemoveTracksRequest>,
|
|
||||||
) -> Result<Response<EmptyResponse>, Status> {
|
|
||||||
let reply = EmptyResponse {};
|
|
||||||
Ok(Response::new(reply))
|
|
||||||
}
|
|
||||||
async fn set_current_track(
|
|
||||||
&self,
|
|
||||||
request: Request<SetCurrentTrackRequest>,
|
|
||||||
) -> Result<Response<EmptyResponse>, Status> {
|
|
||||||
let reply = EmptyResponse {};
|
|
||||||
Ok(Response::new(reply))
|
|
||||||
}
|
|
||||||
async fn get_queue_updates(
|
|
||||||
&self,
|
|
||||||
request: Request<GetQueueUpdatesRequest>,
|
|
||||||
) -> Result<Response<Self::GetQueueUpdatesStream>, Status> {
|
|
||||||
let reply = GetQueueUpdatesResponse {
|
|
||||||
queue_update_result: None,
|
|
||||||
};
|
|
||||||
// https://giphy.com/gifs/dog-mechanic-i-have-no-idea-what-im-doing-VXCPgZwEP7f1e
|
|
||||||
let (tx, rx) = mpsc::channel(128);
|
|
||||||
let output_stream = ReceiverStream::new(rx);
|
|
||||||
Ok(Response::new(
|
|
||||||
Box::pin(output_stream) as Self::GetQueueUpdatesStream
|
|
||||||
))
|
|
||||||
}
|
|
||||||
async fn get_queue(
|
|
||||||
&self,
|
|
||||||
request: Request<EmptyRequest>,
|
|
||||||
) -> Result<Response<GetQueueResponse>, Status> {
|
|
||||||
let reply = GetQueueResponse { queue: None };
|
|
||||||
Ok(Response::new(reply))
|
|
||||||
}
|
|
||||||
async fn save_queue(
|
|
||||||
&self,
|
|
||||||
request: Request<SaveQueueRequest>,
|
|
||||||
) -> Result<Response<EmptyResponse>, Status> {
|
|
||||||
let reply = EmptyResponse {};
|
|
||||||
Ok(Response::new(reply))
|
|
||||||
}
|
|
||||||
async fn toggle_play(
|
|
||||||
&self,
|
|
||||||
request: Request<EmptyRequest>,
|
|
||||||
) -> Result<Response<EmptyResponse>, Status> {
|
|
||||||
let reply = EmptyResponse {};
|
|
||||||
Ok(Response::new(reply))
|
|
||||||
}
|
|
||||||
async fn stop(
|
|
||||||
&self,
|
|
||||||
request: Request<EmptyRequest>,
|
|
||||||
) -> Result<Response<EmptyResponse>, Status> {
|
|
||||||
let reply = EmptyResponse {};
|
|
||||||
Ok(Response::new(reply))
|
|
||||||
}
|
|
||||||
async fn get_active_track(
|
|
||||||
&self,
|
|
||||||
request: Request<EmptyRequest>,
|
|
||||||
) -> Result<Response<GetActiveTrackResponse>, Status> {
|
|
||||||
let reply = GetActiveTrackResponse {
|
|
||||||
track: None,
|
|
||||||
play_state: 0,
|
|
||||||
completion: 0,
|
|
||||||
};
|
|
||||||
Ok(Response::new(reply))
|
|
||||||
}
|
|
||||||
async fn get_track_updates(
|
|
||||||
&self,
|
|
||||||
request: Request<GetTrackUpdatesRequest>,
|
|
||||||
) -> Result<Response<Self::GetTrackUpdatesStream>, Status> {
|
|
||||||
let reply = GetTrackUpdatesResponse {
|
|
||||||
track: None,
|
|
||||||
play_state: 0,
|
|
||||||
completion: 0,
|
|
||||||
};
|
|
||||||
// https://giphy.com/gifs/dog-mechanic-i-have-no-idea-what-im-doing-VXCPgZwEP7f1e
|
|
||||||
let (tx, rx) = mpsc::channel(128);
|
|
||||||
let output_stream = ReceiverStream::new(rx);
|
|
||||||
Ok(Response::new(
|
|
||||||
Box::pin(output_stream) as Self::GetTrackUpdatesStream
|
|
||||||
))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
let addr = "[::1]:50051".parse()?;
|
|
||||||
let crabidy_service = Service::default();
|
|
||||||
|
|
||||||
Server::builder()
|
|
||||||
.add_service(CrabidyServiceServer::new(crabidy_service))
|
|
||||||
.serve(addr)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue