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 config;
|
||||||
pub mod metadata;
|
pub mod metadata;
|
||||||
pub mod parser;
|
pub mod parser;
|
||||||
|
pub mod queue;
|
||||||
pub mod queued_item;
|
pub mod queued_item;
|
||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
@@ -51,7 +52,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
println!("Token did not expire");
|
println!("Token did not expire");
|
||||||
}
|
}
|
||||||
|
|
||||||
match is_queue_empty(&app).await {
|
match queue::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");
|
||||||
@@ -62,7 +63,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
match parser::some_work(&app, &song_queue_id, &user_id).await {
|
match parser::some_work(&app, &song_queue_id, &user_id).await {
|
||||||
Ok((song, coverart, _metadata, queued_song, queued_coverart)) => {
|
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(_) => match parser::cleanup(&song, &coverart).await {
|
||||||
Ok(_) => {
|
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;
|
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),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -18,7 +18,9 @@ pub async fn some_work(
|
|||||||
|
|
||||||
match crate::metadata::apply_metadata(&queued_song, &queued_coverart, &metadata).await {
|
match crate::metadata::apply_metadata(&queued_song, &queued_coverart, &metadata).await {
|
||||||
Ok(_applied) => {
|
Ok(_applied) => {
|
||||||
match crate::api::update_queued_song::update_queued_song(app, &queued_song).await {
|
match crate::api::update_queued_song::update_queued_song(app, &queued_song)
|
||||||
|
.await
|
||||||
|
{
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
match response
|
match response
|
||||||
.json::<crate::api::update_queued_song::response::Response>()
|
.json::<crate::api::update_queued_song::response::Response>()
|
||||||
|
60
src/queue/mod.rs
Normal file
60
src/queue/mod.rs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
pub async fn wipe_data_from_queues(
|
||||||
|
app: &crate::config::App,
|
||||||
|
queued_song: &crate::queued_item::QueuedSong,
|
||||||
|
queued_coverart: &crate::queued_item::QueuedCoverArt,
|
||||||
|
) -> Result<(), std::io::Error> {
|
||||||
|
match crate::api::wipe_data::song_queue::wipe_data(app, queued_song).await {
|
||||||
|
Ok(response) => match response
|
||||||
|
.json::<crate::api::wipe_data::song_queue::response::Response>()
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(_resp) => {
|
||||||
|
match crate::api::wipe_data::coverart_queue::wipe_data(app, queued_coverart).await {
|
||||||
|
Ok(inner_response) => match inner_response
|
||||||
|
.json::<crate::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())),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn is_queue_empty(
|
||||||
|
app: &crate::config::App,
|
||||||
|
) -> Result<
|
||||||
|
(
|
||||||
|
bool,
|
||||||
|
crate::api::fetch_next_queue_item::response::SongQueueItem,
|
||||||
|
),
|
||||||
|
reqwest::Error,
|
||||||
|
> {
|
||||||
|
match crate::api::fetch_next_queue_item::fetch_next_queue_item(app).await {
|
||||||
|
Ok(response) => {
|
||||||
|
match response
|
||||||
|
.json::<crate::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