From 53ca7702cf02dee6896d3d6159a689462ad7e1bc Mon Sep 17 00:00:00 2001 From: kdeng00 Date: Wed, 2 Jul 2025 12:24:10 -0400 Subject: [PATCH] Code cleanup and formatting --- src/syncers/common.rs | 18 ------------------ src/syncers/delete.rs | 18 ++---------------- src/syncers/download.rs | 26 ++++---------------------- src/syncers/retrieve_records.rs | 26 +++----------------------- src/syncers/upload.rs | 29 +++++++---------------------- src/utilities/string.rs | 4 +--- 6 files changed, 17 insertions(+), 104 deletions(-) diff --git a/src/syncers/common.rs b/src/syncers/common.rs index 9d632a6..fe3b362 100644 --- a/src/syncers/common.rs +++ b/src/syncers/common.rs @@ -9,30 +9,12 @@ pub fn retrieve_url(api: &models::api::API, with_id: bool, id: &uuid::Uuid) -> S } fn retrieve_url_reg(api: &models::api::API) -> String { - /* - let mut url: String = String::from(&api.url); - url += &String::from("/"); - url += &String::from("api/"); - url += &String::from(&api.version); - url += &String::from("/"); - url += &String::from(&api.endpoint); - url += &String::from("/"); - */ let url = format!("{}/api/{}/{}/", api.url, api.version, api.endpoint); url } fn retrieve_url_with_id(api: &models::api::API, id: &uuid::Uuid) -> String { - /* - let mut url: String = String::from(&api.url); - url += &String::from("api/"); - url += &String::from(&api.version); - url += &String::from("/"); - url += &String::from(&api.endpoint); - url += &String::from("/"); - url += &id.to_string(); - */ let url = format!("{}/api/{}/{}/{}", api.url, api.version, api.endpoint, id); url diff --git a/src/syncers/delete.rs b/src/syncers/delete.rs index ba94ae6..1420101 100644 --- a/src/syncers/delete.rs +++ b/src/syncers/delete.rs @@ -10,16 +10,6 @@ pub struct Delete { pub api: models::api::API, } -/* -impl Default for Delete { - fn default() -> Self { - Delete { - api: models::api::API::default(), - } - } -} -*/ - impl Delete { pub async fn delete_song( &mut self, @@ -43,14 +33,10 @@ impl Delete { match response.json::().await { Ok(sng) => Ok(sng), - Err(er) => Err(std::io::Error::other( - er.to_string(), - )), + Err(er) => Err(std::io::Error::other(er.to_string())), } } - other => Err(std::io::Error::other( - other.to_string(), - )), + other => Err(std::io::Error::other(other.to_string())), } } } diff --git a/src/syncers/download.rs b/src/syncers/download.rs index 07abad8..4009ccc 100644 --- a/src/syncers/download.rs +++ b/src/syncers/download.rs @@ -8,16 +8,6 @@ pub struct Download { pub api: models::api::API, } -/* -impl Default for Download { - fn default() -> Self { - Download { - api: models::api::API::default(), - } - } -} -*/ - #[derive(Debug)] pub enum MyError { Request(reqwest::Error), @@ -48,24 +38,16 @@ impl Download { reqwest::StatusCode::OK => { let data = rep.text(); match data.await { - Ok(e) => { - Ok(e) - } - Err(er) => { - Err(MyError::Other(er.to_string())) - } + Ok(e) => Ok(e), + Err(er) => Err(MyError::Other(er.to_string())), } } reqwest::StatusCode::UNAUTHORIZED => { Err(MyError::Other(String::from("Need to grab a new token"))) } - other => { - Err(MyError::Other(other.to_string())) - } + other => Err(MyError::Other(other.to_string())), }, - Err(er) => { - Err(MyError::Request(er)) - } + Err(er) => Err(MyError::Request(er)), } } } diff --git a/src/syncers/retrieve_records.rs b/src/syncers/retrieve_records.rs index 5cf4fed..59b58c4 100644 --- a/src/syncers/retrieve_records.rs +++ b/src/syncers/retrieve_records.rs @@ -9,16 +9,6 @@ pub struct RetrieveRecords { pub api: models::api::API, } -/* -impl Default for RetrieveRecords { - fn default() -> Self { - RetrieveRecords { - api: models::api::API::default(), - } - } -} -*/ - impl RetrieveRecords { pub async fn get_all_songs( &mut self, @@ -41,23 +31,13 @@ impl RetrieveRecords { // on success, parse our JSON to an APIResponse match response.json::>().await { Ok(parsed) => Ok(parsed), - Err(err) => { - Err(std::io::Error::other( - err.to_string(), - )) - } + Err(err) => Err(std::io::Error::other(err.to_string())), } } reqwest::StatusCode::UNAUTHORIZED => { - Err(std::io::Error::other( - "Need to grab a new token", - )) - } - other => { - Err(std::io::Error::other( - other.to_string(), - )) + Err(std::io::Error::other("Need to grab a new token")) } + other => Err(std::io::Error::other(other.to_string())), } } } diff --git a/src/syncers/upload.rs b/src/syncers/upload.rs index 4bd759a..ca8b7ff 100644 --- a/src/syncers/upload.rs +++ b/src/syncers/upload.rs @@ -11,16 +11,6 @@ pub struct Upload { pub api: models::api::API, } -/* -impl Default for Upload { - fn default() -> Self { - Upload { - api: models::api::API::default(), - } - } -} -*/ - impl Upload { pub async fn upload_song_with_metadata( &mut self, @@ -56,12 +46,8 @@ impl Upload { .send() .await { - Ok(r) => { - Ok(r) - } - Err(err) => { - Err(err) - } + Ok(r) => Ok(r), + Err(err) => Err(err), } } @@ -74,11 +60,6 @@ impl Upload { let coverpath = cover.path.clone(); println!("Cover path: {coverpath:?}"); let song_detail = song.to_metadata_json(true).unwrap_or_default(); - /*{ - Ok(s) => s, - Err(_) => String::new(), - }; - */ println!("\n{song_detail}\n"); @@ -102,7 +83,11 @@ impl Upload { } pub fn set_api(&mut self, host: &str) { - let api = models::api::API { url: host.to_owned(), version: String::from("v1"), endpoint: String::new() }; + let api = models::api::API { + url: host.to_owned(), + version: String::from("v1"), + endpoint: String::new(), + }; self.api = api; } } diff --git a/src/utilities/string.rs b/src/utilities/string.rs index 41e42ed..4a2bb63 100644 --- a/src/utilities/string.rs +++ b/src/utilities/string.rs @@ -1,8 +1,6 @@ pub fn o_to_string(val: &std::ffi::OsString) -> Result { match val.clone().into_string() { Ok(value) => Ok(value), - Err(_) => Err(std::io::Error::other( - String::from("Error"), - )), + Err(_) => Err(std::io::Error::other(String::from("Error"))), } }