tsk-54: More refactoring
This commit is contained in:
61
src/main.rs
61
src/main.rs
@@ -3,6 +3,7 @@ pub mod auth;
|
||||
pub mod config;
|
||||
pub mod metadata;
|
||||
pub mod parser;
|
||||
pub mod queue;
|
||||
pub mod queued_item;
|
||||
pub mod util;
|
||||
|
||||
@@ -51,7 +52,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
println!("Token did not expire");
|
||||
}
|
||||
|
||||
match is_queue_empty(&app).await {
|
||||
match queue::is_queue_empty(&app).await {
|
||||
Ok((empty, song_queue_item)) => {
|
||||
if !empty {
|
||||
println!("Queue is not empty");
|
||||
@@ -62,7 +63,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
|
||||
match parser::some_work(&app, &song_queue_id, &user_id).await {
|
||||
Ok((song, coverart, _metadata, queued_song, queued_coverart)) => {
|
||||
match wipe_data_from_queues(&app, &queued_song, &queued_coverart).await
|
||||
match queue::wipe_data_from_queues(&app, &queued_song, &queued_coverart)
|
||||
.await
|
||||
{
|
||||
Ok(_) => match parser::cleanup(&song, &coverart).await {
|
||||
Ok(_) => {
|
||||
@@ -94,58 +96,3 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(SECONDS_TO_SLEEP)).await;
|
||||
}
|
||||
}
|
||||
|
||||
async fn wipe_data_from_queues(
|
||||
app: &config::App,
|
||||
queued_song: &crate::queued_item::QueuedSong,
|
||||
queued_coverart: &crate::queued_item::QueuedCoverArt,
|
||||
) -> Result<(), std::io::Error> {
|
||||
match api::wipe_data::song_queue::wipe_data(app, queued_song).await {
|
||||
Ok(response) => match response
|
||||
.json::<api::wipe_data::song_queue::response::Response>()
|
||||
.await
|
||||
{
|
||||
Ok(_resp) => {
|
||||
match api::wipe_data::coverart_queue::wipe_data(app, queued_coverart).await {
|
||||
Ok(inner_response) => match inner_response
|
||||
.json::<api::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(
|
||||
app: &config::App,
|
||||
) -> Result<(bool, api::fetch_next_queue_item::response::SongQueueItem), reqwest::Error> {
|
||||
match api::fetch_next_queue_item::fetch_next_queue_item(app).await {
|
||||
Ok(response) => {
|
||||
match response
|
||||
.json::<api::fetch_next_queue_item::response::SongQueueItem>()
|
||||
.await
|
||||
{
|
||||
Ok(response) => {
|
||||
if response.data.is_empty() {
|
||||
Ok((true, response))
|
||||
} else {
|
||||
Ok((false, response))
|
||||
}
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user