Compare commits
4 Commits
v0.2.0-dev
...
v0.2.3-dev
Author | SHA1 | Date | |
---|---|---|---|
99bb72ffb2 | |||
111d16515f | |||
47bf24180b | |||
c16ad062d4 |
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -518,8 +518,8 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "icarus_models"
|
name = "icarus_models"
|
||||||
version = "0.5.0"
|
version = "0.4.5"
|
||||||
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.5.0-devel-7958b89abc-111#7958b89abc56bc9262015b3e201ea2906cc8a9ff"
|
source = "git+ssh://git@git.kundeng.us/phoenix/icarus_models.git?tag=v0.4.5-devel-655d05dabb-111#655d05dabbdadb9b28940564a1eb82470aa4f166"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"rand",
|
"rand",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -1255,7 +1255,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "songparser"
|
name = "songparser"
|
||||||
version = "0.2.0"
|
version = "0.2.3"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"icarus_envy",
|
"icarus_envy",
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "songparser"
|
name = "songparser"
|
||||||
version = "0.2.0"
|
version = "0.2.3"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.88"
|
rust-version = "1.88"
|
||||||
|
|
||||||
@@ -14,5 +14,5 @@ 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-devel-f4b71de969-680" }
|
||||||
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.5.0-devel-7958b89abc-111" }
|
icarus_models = { git = "ssh://git@git.kundeng.us/phoenix/icarus_models.git", tag = "v0.4.5-devel-655d05dabb-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.0-devel-d73fba9899-006" }
|
||||||
|
104
src/main.rs
104
src/main.rs
@@ -21,10 +21,32 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
println!("Queue is not empty");
|
println!("Queue is not empty");
|
||||||
println!("SongQueueItem: {song_queue_item:?}");
|
println!("SongQueueItem: {song_queue_item:?}");
|
||||||
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;
|
||||||
|
|
||||||
// TODO: Do something with the result later
|
// TODO: Do something with the result later
|
||||||
match some_work(&app_base_url, &song_queue_id).await {
|
match some_work(&app_base_url, &song_queue_id, &user_id).await {
|
||||||
Ok(_) => {}
|
Ok((
|
||||||
|
_song,
|
||||||
|
_coverart,
|
||||||
|
(song_queue_id, song_queue_path),
|
||||||
|
(coverart_queue_id, coverart_queue_path),
|
||||||
|
)) => {
|
||||||
|
// TODO: Wipe data from song and coverart queues
|
||||||
|
match wipe_data_from_queues(
|
||||||
|
&app_base_url,
|
||||||
|
&song_queue_id,
|
||||||
|
&coverart_queue_id,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_) => {
|
||||||
|
// TODO: Cleanup files in local filesystem
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error: {err:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {err:?}");
|
eprintln!("Error: {err:?}");
|
||||||
}
|
}
|
||||||
@@ -43,6 +65,41 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn wipe_data_from_queues(
|
||||||
|
app_base_url: &String,
|
||||||
|
song_queue_id: &uuid::Uuid,
|
||||||
|
coverart_queue_id: &uuid::Uuid,
|
||||||
|
) -> Result<(), std::io::Error> {
|
||||||
|
match the_rest::wipe_data::song_queue::wipe_data(app_base_url, song_queue_id).await {
|
||||||
|
Ok(response) => match response
|
||||||
|
.json::<the_rest::wipe_data::song_queue::response::Response>()
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_resp) => match the_rest::wipe_data::coverart_queue::wipe_data(
|
||||||
|
app_base_url,
|
||||||
|
coverart_queue_id,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(inner_response) => match inner_response
|
||||||
|
.json::<the_rest::wipe_data::coverart_queue::response::Response>()
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_inner_resp) => {
|
||||||
|
println!("Wiped data from CoverArt queue");
|
||||||
|
println!("Resp: {_inner_resp:?}");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
|
},
|
||||||
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
|
},
|
||||||
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
|
},
|
||||||
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async fn is_queue_empty(
|
async fn is_queue_empty(
|
||||||
api_url: &String,
|
api_url: &String,
|
||||||
) -> Result<(bool, responses::fetch_next_queue_item::SongQueueItem), reqwest::Error> {
|
) -> Result<(bool, responses::fetch_next_queue_item::SongQueueItem), reqwest::Error> {
|
||||||
@@ -69,7 +126,16 @@ async fn is_queue_empty(
|
|||||||
async fn some_work(
|
async fn some_work(
|
||||||
app_base_url: &String,
|
app_base_url: &String,
|
||||||
song_queue_id: &uuid::Uuid,
|
song_queue_id: &uuid::Uuid,
|
||||||
) -> Result<(), std::io::Error> {
|
user_id: &uuid::Uuid,
|
||||||
|
) -> Result<
|
||||||
|
(
|
||||||
|
icarus_models::song::Song,
|
||||||
|
icarus_models::coverart::CoverArt,
|
||||||
|
(uuid::Uuid, String),
|
||||||
|
(uuid::Uuid, String),
|
||||||
|
),
|
||||||
|
std::io::Error,
|
||||||
|
> {
|
||||||
match prep_song(app_base_url, song_queue_id).await {
|
match prep_song(app_base_url, 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 {
|
||||||
@@ -89,16 +155,13 @@ async fn some_work(
|
|||||||
Ok(_inner_response) => {
|
Ok(_inner_response) => {
|
||||||
println!("Response: {_inner_response:?}");
|
println!("Response: {_inner_response:?}");
|
||||||
|
|
||||||
// TODO: Do not hard code this. Check if one of the existing
|
|
||||||
// endpoints already have the user_id
|
|
||||||
let user_id = uuid::Uuid::new_v4();
|
|
||||||
// TODO: Place this somewhere else
|
// TODO: Place this somewhere else
|
||||||
let song_type = String::from("flac");
|
let song_type = String::from("flac");
|
||||||
// Err(std::io::Error::other(err.to_string()))
|
|
||||||
match the_rest::create_song::create(
|
match the_rest::create_song::create(
|
||||||
app_base_url,
|
app_base_url,
|
||||||
&metadata,
|
&metadata,
|
||||||
&user_id,
|
user_id,
|
||||||
&song_type,
|
&song_type,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -111,15 +174,22 @@ async fn some_work(
|
|||||||
println!("Response: {resp:?}");
|
println!("Response: {resp:?}");
|
||||||
|
|
||||||
let song = &resp.data[0];
|
let song = &resp.data[0];
|
||||||
let url = format!("{app_base_url}/api/v2/coverart");
|
match the_rest::create_coverart::create(app_base_url, &song.id, &coverart_queue_id).await {
|
||||||
let payload = serde_json::json!({
|
Ok(response) => match response.json::<the_rest::create_coverart::response::Response>().await {
|
||||||
"song_id": &song.id,
|
Ok(resp) => {
|
||||||
"coverart_queue_id": &coverart_queue_id,
|
println!("CoverArt sent and successfully parsed response");
|
||||||
});
|
println!("json: {resp:?}");
|
||||||
println!("Payload: {payload:?}");
|
let coverart = &resp.data[0];
|
||||||
println!("Url: {url:?}");
|
Ok((song.clone(), coverart.clone(), (metadata.song_queue_id, song_queue_path), (coverart_queue_id, coverart_queue_path)))
|
||||||
// println!("Response json: {:?}", response.text().await);
|
}
|
||||||
Ok(())
|
Err(err) => {
|
||||||
|
Err(std::io::Error::other(err.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
Err(std::io::Error::other(err.to_string()))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Err(err) => Err(std::io::Error::other(err.to_string())),
|
Err(err) => Err(std::io::Error::other(err.to_string())),
|
||||||
},
|
},
|
||||||
|
@@ -6,6 +6,7 @@ pub mod fetch_next_queue_item {
|
|||||||
pub id: uuid::Uuid,
|
pub id: uuid::Uuid,
|
||||||
pub filename: String,
|
pub filename: String,
|
||||||
pub status: String,
|
pub status: String,
|
||||||
|
pub user_id: uuid::Uuid,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize)]
|
#[derive(Debug, Deserialize, Serialize)]
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
// TODO: Refactor this file when this app is functional
|
// TODO: Refactor this file when this app is functional
|
||||||
|
|
||||||
// TODO: Create song
|
|
||||||
pub mod create_song {
|
pub mod create_song {
|
||||||
pub async fn create(
|
pub async fn create(
|
||||||
base_url: &String,
|
base_url: &String,
|
||||||
@@ -44,6 +43,83 @@ pub mod create_song {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Create coverart
|
pub mod create_coverart {
|
||||||
// TODO: Wipe data from queued song
|
|
||||||
|
pub async fn create(
|
||||||
|
base_url: &String,
|
||||||
|
song_id: &uuid::Uuid,
|
||||||
|
coverart_queue_id: &uuid::Uuid,
|
||||||
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
|
let client = reqwest::Client::builder().build()?;
|
||||||
|
let url = format!("{base_url}/api/v2/coverart");
|
||||||
|
let payload = get_payload(song_id, coverart_queue_id);
|
||||||
|
let request = client.post(url).json(&payload);
|
||||||
|
|
||||||
|
request.send().await
|
||||||
|
}
|
||||||
|
|
||||||
|
fn get_payload(song_id: &uuid::Uuid, coverart_queue_id: &uuid::Uuid) -> serde_json::Value {
|
||||||
|
serde_json::json!({
|
||||||
|
"song_id": &song_id,
|
||||||
|
"coverart_queue_id": &coverart_queue_id,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod response {
|
||||||
|
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<icarus_models::coverart::CoverArt>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod wipe_data {
|
||||||
|
pub mod song_queue {
|
||||||
|
pub async fn wipe_data(
|
||||||
|
base_url: &String,
|
||||||
|
song_queue_id: &uuid::Uuid,
|
||||||
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
|
let client = reqwest::Client::builder().build()?;
|
||||||
|
let url = format!("{base_url}/api/v2/song/queue/data/wipe");
|
||||||
|
let payload = serde_json::json!({
|
||||||
|
"song_queue_id": song_queue_id
|
||||||
|
});
|
||||||
|
let request = client.patch(url).json(&payload);
|
||||||
|
|
||||||
|
request.send().await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod response {
|
||||||
|
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<uuid::Uuid>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// TODO: Wipe data from queued coverart
|
// TODO: Wipe data from queued coverart
|
||||||
|
pub mod coverart_queue {
|
||||||
|
pub async fn wipe_data(
|
||||||
|
base_url: &String,
|
||||||
|
coverart_queue_id: &uuid::Uuid,
|
||||||
|
) -> Result<reqwest::Response, reqwest::Error> {
|
||||||
|
let client = reqwest::Client::builder().build()?;
|
||||||
|
let url = format!("{base_url}/api/v2/coverart/queue/data/wipe");
|
||||||
|
let payload = serde_json::json!({
|
||||||
|
"coverart_queue_id": coverart_queue_id
|
||||||
|
});
|
||||||
|
let request = client.patch(url).json(&payload);
|
||||||
|
|
||||||
|
request.send().await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub mod response {
|
||||||
|
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||||
|
pub struct Response {
|
||||||
|
pub message: String,
|
||||||
|
pub data: Vec<uuid::Uuid>,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user