Compare commits
9 Commits
main
...
b5f7943938
Author | SHA1 | Date | |
---|---|---|---|
b5f7943938
|
|||
62a1f8a003
|
|||
80c4c7950b
|
|||
6fafb93aaf
|
|||
0695df3f72
|
|||
3ea008868a
|
|||
ce2e4feb02
|
|||
002de87f5e
|
|||
09a129abc8
|
@@ -1,2 +1,4 @@
|
|||||||
ROOT_DIRECTORY=/home/songparser/mydata
|
ROOT_DIRECTORY=/home/songparser/mydata
|
||||||
ICARUS_BASE_API_URL=http://localhost:3000
|
ICARUS_BASE_API_URL=http://localhost:3000
|
||||||
|
SECRET_KEY=iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH
|
||||||
|
SERVICE_PASSPHRASE=iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH
|
||||||
|
@@ -1,2 +1,4 @@
|
|||||||
ROOT_DIRECTORY=/home/songparser/mydata
|
ROOT_DIRECTORY=/home/songparser/mydata
|
||||||
ICARUS_BASE_API_URL=http://localhost:3000
|
ICARUS_BASE_API_URL=http://localhost:3000
|
||||||
|
SECRET_KEY=iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH
|
||||||
|
SERVICE_PASSPHRASE=iUOo1fxshf3y1tUGn1yU8l9raPApHCdinW0VdCHdRFEjqhR3Bf02aZzsKbLtaDFH
|
||||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,4 @@
|
|||||||
/target
|
/target
|
||||||
.env
|
.env
|
||||||
|
.env.local
|
||||||
|
.env.docker
|
||||||
|
93
Cargo.lock
generated
93
Cargo.lock
generated
@@ -17,6 +17,21 @@ version = "2.0.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
|
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "aho-corasick"
|
||||||
|
version = "1.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
|
||||||
|
dependencies = [
|
||||||
|
"memchr",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anyhow"
|
||||||
|
version = "1.0.99"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b0674a1ddeecb70197781e945de4b3b8ffb61fa939a5597bcf48503737663100"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atomic-waker"
|
name = "atomic-waker"
|
||||||
version = "1.1.2"
|
version = "1.1.2"
|
||||||
@@ -501,8 +516,8 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus_envy"
|
name = "icarus_envy"
|
||||||
version = "0.3.0"
|
version = "0.3.1"
|
||||||
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.3.0-devel-d73fba9899-006#d73fba9899372b0655a90cb426645930135152da"
|
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_envy.git?tag=v0.3.1-main-3cd42dab6b-006#3cd42dab6b2503609883f5f57ad3508755c34a2e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"const_format",
|
"const_format",
|
||||||
"dotenvy",
|
"dotenvy",
|
||||||
@@ -511,16 +526,17 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus_meta"
|
name = "icarus_meta"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_meta.git?tag=v0.3.0-devel-f4b71de969-680#f4b71de9692029a706b1ce82c39f6715c560158e"
|
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_meta.git?tag=v0.3.0#f87c049ab3139995230485b33038a0425f2e7430"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lofty",
|
"lofty",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus_models"
|
name = "icarus_models"
|
||||||
version = "0.4.5"
|
version = "0.5.5"
|
||||||
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.4.5-devel-655d05dabb-111#655d05dabbdadb9b28940564a1eb82470aa4f166"
|
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.5.5-devel-bd793db08e-111#bd793db08e06b256ffecd9f4528e55e3026fede7"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"josekit",
|
||||||
"rand",
|
"rand",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
@@ -667,6 +683,23 @@ version = "1.0.15"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "josekit"
|
||||||
|
version = "0.10.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a808e078330e6af222eb0044b71d4b1ff981bfef43e7bc8133a88234e0c86a0c"
|
||||||
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"base64",
|
||||||
|
"flate2",
|
||||||
|
"openssl",
|
||||||
|
"regex",
|
||||||
|
"serde",
|
||||||
|
"serde_json",
|
||||||
|
"thiserror",
|
||||||
|
"time",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
version = "0.3.77"
|
version = "0.3.77"
|
||||||
@@ -1009,6 +1042,35 @@ dependencies = [
|
|||||||
"bitflags",
|
"bitflags",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex"
|
||||||
|
version = "1.11.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-automata",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-automata"
|
||||||
|
version = "0.4.9"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908"
|
||||||
|
dependencies = [
|
||||||
|
"aho-corasick",
|
||||||
|
"memchr",
|
||||||
|
"regex-syntax",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "regex-syntax"
|
||||||
|
version = "0.8.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "reqwest"
|
name = "reqwest"
|
||||||
version = "0.12.20"
|
version = "0.12.20"
|
||||||
@@ -1195,6 +1257,7 @@ version = "1.0.140"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
|
checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"indexmap",
|
||||||
"itoa",
|
"itoa",
|
||||||
"memchr",
|
"memchr",
|
||||||
"ryu",
|
"ryu",
|
||||||
@@ -1347,6 +1410,26 @@ dependencies = [
|
|||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror"
|
||||||
|
version = "2.0.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b0949c3a6c842cbde3f1686d6eea5a010516deb7085f79db747562d4102f41e"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror-impl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror-impl"
|
||||||
|
version = "2.0.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "cc5b44b4ab9c2fdd0e0512e6bece8388e214c0749f5862b114cc5b7a25daf227"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "time"
|
name = "time"
|
||||||
version = "0.3.41"
|
version = "0.3.41"
|
||||||
|
@@ -13,6 +13,6 @@ serde_json = { version = "1.0.140" }
|
|||||||
time = { version = "0.3.41", features = ["macros", "serde"] }
|
time = { version = "0.3.41", features = ["macros", "serde"] }
|
||||||
uuid = { version = "1.17.0", features = ["v4", "serde"] }
|
uuid = { version = "1.17.0", features = ["v4", "serde"] }
|
||||||
rand = { version = "0.9.1" }
|
rand = { version = "0.9.1" }
|
||||||
icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.3.0-devel-f4b71de969-680" }
|
icarus_meta = { git = "ssh://git@git.kundeng.us/phoenix/icarus_meta.git", tag = "v0.3.0" }
|
||||||
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.4.5-devel-655d05dabb-111" }
|
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.5.5-devel-bd793db08e-111" }
|
||||||
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.3.0-devel-d73fba9899-006" }
|
icarus_envy = { git = "ssh://git@git.kundeng.us/phoenix/icarus_envy.git", tag = "v0.3.1-main-3cd42dab6b-006" }
|
||||||
|
55
src/api.rs
55
src/api.rs
@@ -1,8 +1,17 @@
|
|||||||
pub async fn fetch_next_queue_item(base_url: &String) -> Result<reqwest::Response, reqwest::Error> {
|
pub async fn fetch_next_queue_item(app: &crate::config::App) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let fetch_endpoint = String::from("api/v2/song/queue/next");
|
let fetch_endpoint = String::from("api/v2/song/queue/next");
|
||||||
let api_url = format!("{base_url}/{fetch_endpoint}");
|
let api_url = format!("{}/{fetch_endpoint}", app.uri);
|
||||||
client.get(api_url).send().await
|
let (key, header) = auth_header(app).await;
|
||||||
|
println!("Header: {header:?}");
|
||||||
|
client.get(api_url).header(key, header)
|
||||||
|
.send().await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn auth_header(app: &crate::config::App) -> (reqwest::header::HeaderName, reqwest::header::HeaderValue) {
|
||||||
|
let bearer = format!("Bearer {}", app.token.token);
|
||||||
|
let header_value = reqwest::header::HeaderValue::from_str(&bearer).unwrap();
|
||||||
|
(reqwest::header::AUTHORIZATION, header_value)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod parsing {
|
pub mod parsing {
|
||||||
@@ -27,24 +36,26 @@ pub mod parsing {
|
|||||||
|
|
||||||
pub mod fetch_song_queue_data {
|
pub mod fetch_song_queue_data {
|
||||||
pub async fn get_data(
|
pub async fn get_data(
|
||||||
base_url: &String,
|
// base_url: &String,
|
||||||
|
app: &crate::config::App,
|
||||||
id: &uuid::Uuid,
|
id: &uuid::Uuid,
|
||||||
) -> Result<reqwest::Response, reqwest::Error> {
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let endpoint = String::from("api/v2/song/queue");
|
let endpoint = String::from("api/v2/song/queue");
|
||||||
let api_url = format!("{base_url}/{endpoint}/{id}");
|
let api_url = format!("{}/{endpoint}/{id}", app.uri);
|
||||||
client.get(api_url).send().await
|
client.get(api_url).send().await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub mod get_metadata_queue {
|
pub mod get_metadata_queue {
|
||||||
pub async fn get(
|
pub async fn get(
|
||||||
base_url: &String,
|
// base_url: &String,
|
||||||
|
app: &crate::config::App,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
) -> Result<reqwest::Response, reqwest::Error> {
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let endpoint = String::from("api/v2/song/metadata/queue");
|
let endpoint = String::from("api/v2/song/metadata/queue");
|
||||||
let api_url = format!("{base_url}/{endpoint}");
|
let api_url = format!("{}/{endpoint}", app.uri);
|
||||||
client
|
client
|
||||||
.get(api_url)
|
.get(api_url)
|
||||||
.query(&[("song_queue_id", song_queue_id)])
|
.query(&[("song_queue_id", song_queue_id)])
|
||||||
@@ -90,12 +101,13 @@ pub mod get_metadata_queue {
|
|||||||
|
|
||||||
pub mod get_coverart_queue {
|
pub mod get_coverart_queue {
|
||||||
pub async fn get(
|
pub async fn get(
|
||||||
base_url: &String,
|
// base_url: &String,
|
||||||
|
app: &crate::config::App,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
) -> Result<reqwest::Response, reqwest::Error> {
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let endpoint = String::from("api/v2/coverart/queue");
|
let endpoint = String::from("api/v2/coverart/queue");
|
||||||
let api_url = format!("{base_url}/{endpoint}");
|
let api_url = format!("{}/{endpoint}", app.uri);
|
||||||
client
|
client
|
||||||
.get(api_url)
|
.get(api_url)
|
||||||
.query(&[("song_queue_id", song_queue_id)])
|
.query(&[("song_queue_id", song_queue_id)])
|
||||||
@@ -104,12 +116,13 @@ pub mod get_coverart_queue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_data(
|
pub async fn get_data(
|
||||||
base_url: &String,
|
// base_url: &String,
|
||||||
|
app: &crate::config::App,
|
||||||
coverart_queue_id: &uuid::Uuid,
|
coverart_queue_id: &uuid::Uuid,
|
||||||
) -> Result<reqwest::Response, reqwest::Error> {
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
let endpoint = String::from("api/v2/coverart/queue/data");
|
let endpoint = String::from("api/v2/coverart/queue/data");
|
||||||
let api_url = format!("{base_url}/{endpoint}/{coverart_queue_id}");
|
let api_url = format!("{}/{endpoint}/{coverart_queue_id}", app.uri);
|
||||||
client.get(api_url).send().await
|
client.get(api_url).send().await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,3 +142,23 @@ pub mod get_coverart_queue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub mod service_token {
|
||||||
|
pub mod response {
|
||||||
|
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<icarus_models::login_result::LoginResult>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod refresh_token {
|
||||||
|
pub mod response {
|
||||||
|
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<icarus_models::login_result::LoginResult>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
5
src/config.rs
Normal file
5
src/config.rs
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
#[derive(Default, Debug)]
|
||||||
|
pub struct App {
|
||||||
|
pub uri: String,
|
||||||
|
pub token: icarus_models::login_result::LoginResult
|
||||||
|
}
|
154
src/main.rs
154
src/main.rs
@@ -1,4 +1,5 @@
|
|||||||
pub mod api;
|
pub mod api;
|
||||||
|
pub mod config;
|
||||||
pub mod responses;
|
pub mod responses;
|
||||||
pub mod the_rest;
|
pub mod the_rest;
|
||||||
pub mod update_queued_song;
|
pub mod update_queued_song;
|
||||||
@@ -8,23 +9,64 @@ use std::io::Write;
|
|||||||
|
|
||||||
pub const SECONDS_TO_SLEEP: u64 = 5;
|
pub const SECONDS_TO_SLEEP: u64 = 5;
|
||||||
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let app_base_url = icarus_envy::environment::get_icarus_base_api_url().await;
|
// let app_base_url = icarus_envy::environment::get_icarus_base_api_url().await;
|
||||||
|
let mut app = config::App {
|
||||||
|
uri: icarus_envy::environment::get_icarus_base_api_url().await,
|
||||||
|
// token: auth::get_token(&app).await,
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
match auth::get_token(&app).await {
|
||||||
|
Ok(login_result) => {
|
||||||
|
app.token = login_result;
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
std::process::exit(-1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// let mut service_login = auth::get_token().await;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
println!("Base URL: {app_base_url}");
|
println!("Base URL: {:?}", app.uri);
|
||||||
|
|
||||||
match is_queue_empty(&app_base_url).await {
|
println!("Token: {:?}", app.token);
|
||||||
|
|
||||||
|
if auth::did_token_expire(&app.token).await {
|
||||||
|
println!("Token did expire");
|
||||||
|
app.token = match auth::get_refresh_token(&app, &app.token).await {
|
||||||
|
Ok(login_result) => {
|
||||||
|
login_result
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
tokio::time::sleep(tokio::time::Duration::from_secs(SECONDS_TO_SLEEP)).await;
|
||||||
|
println!("Token refreshed");
|
||||||
|
println!("Refreshed token: {:?}", app.token);
|
||||||
|
} else {
|
||||||
|
println!("Token did not expire");
|
||||||
|
}
|
||||||
|
tokio::time::sleep(tokio::time::Duration::from_secs(SECONDS_TO_SLEEP)).await;
|
||||||
|
|
||||||
|
|
||||||
|
match is_queue_empty(&app).await {
|
||||||
Ok((empty, song_queue_item)) => {
|
Ok((empty, song_queue_item)) => {
|
||||||
if !empty {
|
if !empty {
|
||||||
println!("Queue is not empty");
|
println!("Queue is not empty");
|
||||||
println!("SongQueueItem: {song_queue_item:?}");
|
println!("SongQueueItem: {song_queue_item:?}");
|
||||||
|
// TODO: For now, focus on making sure the token is valid before you get here
|
||||||
|
continue;
|
||||||
|
|
||||||
let song_queue_id = song_queue_item.data[0].id;
|
let song_queue_id = song_queue_item.data[0].id;
|
||||||
let user_id = song_queue_item.data[0].user_id;
|
let user_id = song_queue_item.data[0].user_id;
|
||||||
|
|
||||||
// TODO: Do something with the result later
|
// TODO: Do something with the result later
|
||||||
match some_work(&app_base_url, &song_queue_id, &user_id).await {
|
match some_work(&app, &song_queue_id, &user_id).await {
|
||||||
Ok((
|
Ok((
|
||||||
_song,
|
_song,
|
||||||
_coverart,
|
_coverart,
|
||||||
@@ -32,7 +74,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
(coverart_queue_id, coverart_queue_path),
|
(coverart_queue_id, coverart_queue_path),
|
||||||
)) => {
|
)) => {
|
||||||
match wipe_data_from_queues(
|
match wipe_data_from_queues(
|
||||||
&app_base_url,
|
&app,
|
||||||
&song_queue_id,
|
&song_queue_id,
|
||||||
&coverart_queue_id,
|
&coverart_queue_id,
|
||||||
)
|
)
|
||||||
@@ -71,18 +113,87 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
mod auth {
|
||||||
|
pub async fn get_token(app: &crate::config::App) -> Result<icarus_models::login_result::LoginResult, std::io::Error> {
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let endpoint = String::from("api/v2/service/login");
|
||||||
|
let api_url = format!("{}/{endpoint}", app.uri);
|
||||||
|
|
||||||
|
let payload = serde_json::json!({
|
||||||
|
"passphrase": icarus_envy::environment::get_service_passphrase().await,
|
||||||
|
});
|
||||||
|
|
||||||
|
match client.post(api_url).json(&payload)
|
||||||
|
.send().await {
|
||||||
|
Ok(response) => match response.json::<crate::api::service_token::response::Response>().await {
|
||||||
|
Ok(resp) => {
|
||||||
|
if resp.data.is_empty() {
|
||||||
|
Err(std::io::Error::other(String::from("No token returned")))
|
||||||
|
} else {
|
||||||
|
Ok(resp.data[0].clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
Err(std::io::Error::other(err.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
Err(std::io::Error::other(err.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Might want to put the functionality within icarus_models at some point
|
||||||
|
pub async fn did_token_expire(login_result: &icarus_models::login_result::LoginResult) -> bool {
|
||||||
|
let current_time = time::OffsetDateTime::now_utc();
|
||||||
|
let expire_time = time::OffsetDateTime::from_unix_timestamp(login_result.expiration).unwrap();
|
||||||
|
current_time > expire_time
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Refactor this to only have one function parameter
|
||||||
|
pub async fn get_refresh_token(app: &crate::config::App, login_result: &icarus_models::login_result::LoginResult) -> Result<icarus_models::login_result::LoginResult, std::io::Error> {
|
||||||
|
let client = reqwest::Client::new();
|
||||||
|
let endpoint = String::from("api/v2/token/refresh");
|
||||||
|
let api_url = format!("{}/{endpoint}", app.uri);
|
||||||
|
|
||||||
|
let payload = serde_json::json!({
|
||||||
|
"access_token": login_result.token
|
||||||
|
});
|
||||||
|
|
||||||
|
match client.post(api_url).json(&payload).send().await {
|
||||||
|
Ok(response) => match response.json::<crate::api::refresh_token::response::Response>().await {
|
||||||
|
Ok(resp) => {
|
||||||
|
if resp.data.is_empty() {
|
||||||
|
Err(std::io::Error::other(String::from("No token returned")))
|
||||||
|
} else {
|
||||||
|
Ok(resp.data[0].clone())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
Err(std::io::Error::other(err.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
Err(std::io::Error::other(err.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn wipe_data_from_queues(
|
async fn wipe_data_from_queues(
|
||||||
app_base_url: &String,
|
app: &config::App,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
coverart_queue_id: &uuid::Uuid,
|
coverart_queue_id: &uuid::Uuid,
|
||||||
) -> Result<(), std::io::Error> {
|
) -> Result<(), std::io::Error> {
|
||||||
match the_rest::wipe_data::song_queue::wipe_data(app_base_url, song_queue_id).await {
|
match the_rest::wipe_data::song_queue::wipe_data(app, song_queue_id).await {
|
||||||
Ok(response) => match response
|
Ok(response) => match response
|
||||||
.json::<the_rest::wipe_data::song_queue::response::Response>()
|
.json::<the_rest::wipe_data::song_queue::response::Response>()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(_resp) => match the_rest::wipe_data::coverart_queue::wipe_data(
|
Ok(_resp) => match the_rest::wipe_data::coverart_queue::wipe_data(
|
||||||
app_base_url,
|
// app_base_url,
|
||||||
|
app,
|
||||||
coverart_queue_id,
|
coverart_queue_id,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -124,9 +235,10 @@ async fn cleanup(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn is_queue_empty(
|
async fn is_queue_empty(
|
||||||
api_url: &String,
|
// api_url: &String,
|
||||||
|
app: &config::App,
|
||||||
) -> Result<(bool, responses::fetch_next_queue_item::SongQueueItem), reqwest::Error> {
|
) -> Result<(bool, responses::fetch_next_queue_item::SongQueueItem), reqwest::Error> {
|
||||||
match api::fetch_next_queue_item(api_url).await {
|
match api::fetch_next_queue_item(app).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
match response
|
match response
|
||||||
.json::<responses::fetch_next_queue_item::SongQueueItem>()
|
.json::<responses::fetch_next_queue_item::SongQueueItem>()
|
||||||
@@ -147,7 +259,8 @@ async fn is_queue_empty(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn some_work(
|
async fn some_work(
|
||||||
app_base_url: &String,
|
// app_base_url: &String,
|
||||||
|
app: &crate::config::App,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
user_id: &uuid::Uuid,
|
user_id: &uuid::Uuid,
|
||||||
) -> Result<
|
) -> Result<
|
||||||
@@ -159,12 +272,12 @@ async fn some_work(
|
|||||||
),
|
),
|
||||||
std::io::Error,
|
std::io::Error,
|
||||||
> {
|
> {
|
||||||
match prep_song(app_base_url, song_queue_id).await {
|
match prep_song(app, song_queue_id).await {
|
||||||
Ok((song_queue_path, coverart_queue_path, metadata, coverart_queue_id)) => {
|
Ok((song_queue_path, coverart_queue_path, metadata, coverart_queue_id)) => {
|
||||||
match apply_metadata(&song_queue_path, &coverart_queue_path, &metadata).await {
|
match apply_metadata(&song_queue_path, &coverart_queue_path, &metadata).await {
|
||||||
Ok(_applied) => {
|
Ok(_applied) => {
|
||||||
match update_queued_song::update_queued_song(
|
match update_queued_song::update_queued_song(
|
||||||
app_base_url,
|
app,
|
||||||
&song_queue_path,
|
&song_queue_path,
|
||||||
song_queue_id,
|
song_queue_id,
|
||||||
)
|
)
|
||||||
@@ -182,7 +295,7 @@ async fn some_work(
|
|||||||
let song_type = String::from("flac");
|
let song_type = String::from("flac");
|
||||||
|
|
||||||
match the_rest::create_song::create(
|
match the_rest::create_song::create(
|
||||||
app_base_url,
|
app,
|
||||||
&metadata,
|
&metadata,
|
||||||
user_id,
|
user_id,
|
||||||
&song_type,
|
&song_type,
|
||||||
@@ -197,7 +310,7 @@ async fn some_work(
|
|||||||
println!("Response: {resp:?}");
|
println!("Response: {resp:?}");
|
||||||
|
|
||||||
let song = &resp.data[0];
|
let song = &resp.data[0];
|
||||||
match the_rest::create_coverart::create(app_base_url, &song.id, &coverart_queue_id).await {
|
match the_rest::create_coverart::create(app, &song.id, &coverart_queue_id).await {
|
||||||
Ok(response) => match response.json::<the_rest::create_coverart::response::Response>().await {
|
Ok(response) => match response.json::<the_rest::create_coverart::response::Response>().await {
|
||||||
Ok(resp) => {
|
Ok(resp) => {
|
||||||
println!("CoverArt sent and successfully parsed response");
|
println!("CoverArt sent and successfully parsed response");
|
||||||
@@ -233,7 +346,8 @@ async fn some_work(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn prep_song(
|
async fn prep_song(
|
||||||
api_url: &String,
|
// api_url: &String,
|
||||||
|
app: &crate::config::App,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
) -> Result<
|
) -> Result<
|
||||||
(
|
(
|
||||||
@@ -244,7 +358,7 @@ async fn prep_song(
|
|||||||
),
|
),
|
||||||
reqwest::Error,
|
reqwest::Error,
|
||||||
> {
|
> {
|
||||||
match api::fetch_song_queue_data::get_data(api_url, song_queue_id).await {
|
match api::fetch_song_queue_data::get_data(app, song_queue_id).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
// Process data here...
|
// Process data here...
|
||||||
match api::parsing::parse_response_into_bytes(response).await {
|
match api::parsing::parse_response_into_bytes(response).await {
|
||||||
@@ -254,7 +368,7 @@ async fn prep_song(
|
|||||||
|
|
||||||
println!("Saved at: {song_queue_path:?}");
|
println!("Saved at: {song_queue_path:?}");
|
||||||
|
|
||||||
match api::get_metadata_queue::get(api_url, song_queue_id).await {
|
match api::get_metadata_queue::get(app, song_queue_id).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
match response
|
match response
|
||||||
.json::<api::get_metadata_queue::response::Response>()
|
.json::<api::get_metadata_queue::response::Response>()
|
||||||
@@ -269,7 +383,7 @@ async fn prep_song(
|
|||||||
println!("Created at: {created_at:?}");
|
println!("Created at: {created_at:?}");
|
||||||
|
|
||||||
println!("Getting coverart queue");
|
println!("Getting coverart queue");
|
||||||
match api::get_coverart_queue::get(api_url, song_queue_id).await
|
match api::get_coverart_queue::get(app, song_queue_id).await
|
||||||
{
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
match response.json::<api::get_coverart_queue::response::Response>().await {
|
match response.json::<api::get_coverart_queue::response::Response>().await {
|
||||||
@@ -277,7 +391,7 @@ async fn prep_song(
|
|||||||
let coverart_queue_id = &response.data[0].id;
|
let coverart_queue_id = &response.data[0].id;
|
||||||
println!("Coverart queue Id: {coverart_queue_id:?}");
|
println!("Coverart queue Id: {coverart_queue_id:?}");
|
||||||
|
|
||||||
match api::get_coverart_queue::get_data(api_url, coverart_queue_id).await {
|
match api::get_coverart_queue::get_data(app, coverart_queue_id).await {
|
||||||
Ok(response) => match api::parsing::parse_response_into_bytes(response).await {
|
Ok(response) => match api::parsing::parse_response_into_bytes(response).await {
|
||||||
Ok(coverart_queue_bytes) => {
|
Ok(coverart_queue_bytes) => {
|
||||||
let (directory, filename) = generate_coverart_queue_dir_and_filename().await;
|
let (directory, filename) = generate_coverart_queue_dir_and_filename().await;
|
||||||
|
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
pub mod create_song {
|
pub mod create_song {
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
base_url: &String,
|
// base_url: &String,
|
||||||
|
app: &crate::config::App,
|
||||||
metadata_queue: &crate::api::get_metadata_queue::response::Metadata,
|
metadata_queue: &crate::api::get_metadata_queue::response::Metadata,
|
||||||
user_id: &uuid::Uuid,
|
user_id: &uuid::Uuid,
|
||||||
song_type: &String,
|
song_type: &String,
|
||||||
@@ -28,7 +29,7 @@ pub mod create_song {
|
|||||||
|
|
||||||
let client = reqwest::Client::builder().build()?;
|
let client = reqwest::Client::builder().build()?;
|
||||||
|
|
||||||
let url = format!("{base_url}/api/v2/song");
|
let url = format!("{}/api/v2/song", app.uri);
|
||||||
|
|
||||||
let request = client.post(url).json(&payload);
|
let request = client.post(url).json(&payload);
|
||||||
request.send().await
|
request.send().await
|
||||||
@@ -46,12 +47,13 @@ pub mod create_song {
|
|||||||
pub mod create_coverart {
|
pub mod create_coverart {
|
||||||
|
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
base_url: &String,
|
// base_url: &String,
|
||||||
|
app: &crate::config::App,
|
||||||
song_id: &uuid::Uuid,
|
song_id: &uuid::Uuid,
|
||||||
coverart_queue_id: &uuid::Uuid,
|
coverart_queue_id: &uuid::Uuid,
|
||||||
) -> Result<reqwest::Response, reqwest::Error> {
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
let client = reqwest::Client::builder().build()?;
|
let client = reqwest::Client::builder().build()?;
|
||||||
let url = format!("{base_url}/api/v2/coverart");
|
let url = format!("{}/api/v2/coverart", app.uri);
|
||||||
let payload = get_payload(song_id, coverart_queue_id);
|
let payload = get_payload(song_id, coverart_queue_id);
|
||||||
let request = client.post(url).json(&payload);
|
let request = client.post(url).json(&payload);
|
||||||
|
|
||||||
@@ -77,11 +79,12 @@ pub mod create_coverart {
|
|||||||
pub mod wipe_data {
|
pub mod wipe_data {
|
||||||
pub mod song_queue {
|
pub mod song_queue {
|
||||||
pub async fn wipe_data(
|
pub async fn wipe_data(
|
||||||
base_url: &String,
|
// base_url: &String,
|
||||||
|
app: &crate::config::App,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
) -> Result<reqwest::Response, reqwest::Error> {
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
let client = reqwest::Client::builder().build()?;
|
let client = reqwest::Client::builder().build()?;
|
||||||
let url = format!("{base_url}/api/v2/song/queue/data/wipe");
|
let url = format!("{}/api/v2/song/queue/data/wipe", app.uri);
|
||||||
let payload = serde_json::json!({
|
let payload = serde_json::json!({
|
||||||
"song_queue_id": song_queue_id
|
"song_queue_id": song_queue_id
|
||||||
});
|
});
|
||||||
@@ -100,11 +103,12 @@ pub mod wipe_data {
|
|||||||
}
|
}
|
||||||
pub mod coverart_queue {
|
pub mod coverart_queue {
|
||||||
pub async fn wipe_data(
|
pub async fn wipe_data(
|
||||||
base_url: &String,
|
// base_url: &String,
|
||||||
|
app: &crate::config::App,
|
||||||
coverart_queue_id: &uuid::Uuid,
|
coverart_queue_id: &uuid::Uuid,
|
||||||
) -> Result<reqwest::Response, reqwest::Error> {
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
let client = reqwest::Client::builder().build()?;
|
let client = reqwest::Client::builder().build()?;
|
||||||
let url = format!("{base_url}/api/v2/coverart/queue/data/wipe");
|
let url = format!("{}/api/v2/coverart/queue/data/wipe", app.uri);
|
||||||
let payload = serde_json::json!({
|
let payload = serde_json::json!({
|
||||||
"coverart_queue_id": coverart_queue_id
|
"coverart_queue_id": coverart_queue_id
|
||||||
});
|
});
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
pub async fn update_queued_song(
|
pub async fn update_queued_song(
|
||||||
base_url: &String,
|
// base_url: &String,
|
||||||
|
app: &crate::config::App,
|
||||||
song_path: &String,
|
song_path: &String,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
) -> Result<reqwest::Response, reqwest::Error> {
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
@@ -14,7 +15,7 @@ pub async fn update_queued_song(
|
|||||||
.file_name("track01.flac"),
|
.file_name("track01.flac"),
|
||||||
);
|
);
|
||||||
|
|
||||||
let url = format!("{base_url}/api/v2/song/queue/{song_queue_id}");
|
let url = format!("{}/api/v2/song/queue/{song_queue_id}", app.uri);
|
||||||
println!("Url: {url:?}");
|
println!("Url: {url:?}");
|
||||||
|
|
||||||
let request = client.patch(url).multipart(form);
|
let request = client.patch(url).multipart(form);
|
||||||
|
Reference in New Issue
Block a user