Warning fixes

This commit is contained in:
kdeng00
2025-07-01 22:23:37 -04:00
parent cf95caef50
commit 3e96bea7be
9 changed files with 57 additions and 51 deletions
+1 -1
View File
@@ -32,5 +32,5 @@ pub fn print_help() {
-D song id"#, -D song id"#,
); );
println!("{}", msg); println!("{msg}");
} }
+2 -2
View File
@@ -16,7 +16,7 @@ fn main() {
utilities::checks::exit_program(-1); utilities::checks::exit_program(-1);
} }
println!("Argument count: {}", args_len); println!("Argument count: {args_len}");
let mut act_mgr = managers::action_managers::ActionManager::default(); let mut act_mgr = managers::action_managers::ActionManager::default();
act_mgr.set_params(&args); act_mgr.set_params(&args);
@@ -41,7 +41,7 @@ mod tests {
let meta_path = String::from("tests/sample2_tracks/album.json"); let meta_path = String::from("tests/sample2_tracks/album.json");
if !std::path::Path::new(&meta_path).exists() { if !std::path::Path::new(&meta_path).exists() {
assert!(false, "File does not exists: {:?}", meta_path); assert!(false, "File does not exists: {:meta_path?}");
} }
match icarus_models::album::collection::parse_album(&meta_path) { match icarus_models::album::collection::parse_album(&meta_path) {
+10 -4
View File
@@ -2,13 +2,14 @@ use crate::models;
pub fn retrieve_url(api: &models::api::API, with_id: bool, id: &uuid::Uuid) -> String { pub fn retrieve_url(api: &models::api::API, with_id: bool, id: &uuid::Uuid) -> String {
if with_id { if with_id {
retrieve_url_with_id(&api, id) retrieve_url_with_id(api, id)
} else { } else {
retrieve_url_reg(&api) retrieve_url_reg(api)
} }
} }
fn retrieve_url_reg(api: &models::api::API) -> String { fn retrieve_url_reg(api: &models::api::API) -> String {
/*
let mut url: String = String::from(&api.url); let mut url: String = String::from(&api.url);
url += &String::from("/"); url += &String::from("/");
url += &String::from("api/"); url += &String::from("api/");
@@ -16,11 +17,14 @@ fn retrieve_url_reg(api: &models::api::API) -> String {
url += &String::from("/"); url += &String::from("/");
url += &String::from(&api.endpoint); url += &String::from(&api.endpoint);
url += &String::from("/"); url += &String::from("/");
*/
let url = format!("{}/api/{}/{}/", api.url, api.version, api.endpoint);
return url; url
} }
fn retrieve_url_with_id(api: &models::api::API, id: &uuid::Uuid) -> String { fn retrieve_url_with_id(api: &models::api::API, id: &uuid::Uuid) -> String {
/*
let mut url: String = String::from(&api.url); let mut url: String = String::from(&api.url);
url += &String::from("api/"); url += &String::from("api/");
url += &String::from(&api.version); url += &String::from(&api.version);
@@ -28,6 +32,8 @@ fn retrieve_url_with_id(api: &models::api::API, id: &uuid::Uuid) -> String {
url += &String::from(&api.endpoint); url += &String::from(&api.endpoint);
url += &String::from("/"); url += &String::from("/");
url += &id.to_string(); url += &id.to_string();
*/
let url = format!("{}/api/{}/{}/{}", api.url, api.version, api.endpoint, id);
return url; url
} }
+5 -5
View File
@@ -5,11 +5,12 @@ use reqwest;
use crate::models; use crate::models;
use crate::syncers; use crate::syncers;
#[derive(Clone, Debug)] #[derive(Clone, Debug, Default)]
pub struct Delete { pub struct Delete {
pub api: models::api::API, pub api: models::api::API,
} }
/*
impl Default for Delete { impl Default for Delete {
fn default() -> Self { fn default() -> Self {
Delete { Delete {
@@ -17,6 +18,7 @@ impl Default for Delete {
} }
} }
} }
*/
impl Delete { impl Delete {
pub async fn delete_song( pub async fn delete_song(
@@ -41,14 +43,12 @@ impl Delete {
match response.json::<icarus_models::song::Song>().await { match response.json::<icarus_models::song::Song>().await {
Ok(sng) => Ok(sng), Ok(sng) => Ok(sng),
Err(er) => Err(std::io::Error::new( Err(er) => Err(std::io::Error::other(
std::io::ErrorKind::Other,
er.to_string(), er.to_string(),
)), )),
} }
} }
other => Err(std::io::Error::new( other => Err(std::io::Error::other(
std::io::ErrorKind::Other,
other.to_string(), other.to_string(),
)), )),
} }
+9 -6
View File
@@ -3,10 +3,12 @@ use std::default::Default;
use crate::models; use crate::models;
use crate::syncers; use crate::syncers;
#[derive(Default)]
pub struct Download { pub struct Download {
pub api: models::api::API, pub api: models::api::API,
} }
/*
impl Default for Download { impl Default for Download {
fn default() -> Self { fn default() -> Self {
Download { Download {
@@ -14,6 +16,7 @@ impl Default for Download {
} }
} }
} }
*/
#[derive(Debug)] #[derive(Debug)]
pub enum MyError { pub enum MyError {
@@ -31,7 +34,7 @@ impl Download {
let url = syncers::common::retrieve_url(&self.api, true, &song.id); let url = syncers::common::retrieve_url(&self.api, true, &song.id);
let access_token = token.bearer_token(); let access_token = token.bearer_token();
println!("Url: {:?}", url); println!("Url: {url:?}");
let client = reqwest::Client::builder().build().unwrap(); let client = reqwest::Client::builder().build().unwrap();
@@ -46,22 +49,22 @@ impl Download {
let data = rep.text(); let data = rep.text();
match data.await { match data.await {
Ok(e) => { Ok(e) => {
return Ok(e); Ok(e)
} }
Err(er) => { Err(er) => {
return Err(MyError::Other(er.to_string())); Err(MyError::Other(er.to_string()))
} }
} }
} }
reqwest::StatusCode::UNAUTHORIZED => { reqwest::StatusCode::UNAUTHORIZED => {
return Err(MyError::Other(String::from("Need to grab a new token"))); Err(MyError::Other(String::from("Need to grab a new token")))
} }
other => { other => {
return Err(MyError::Other(other.to_string())); Err(MyError::Other(other.to_string()))
} }
}, },
Err(er) => { Err(er) => {
return Err(MyError::Request(er)); Err(MyError::Request(er))
} }
} }
} }
+9 -9
View File
@@ -4,10 +4,12 @@ use std::io::Error;
use crate::models; use crate::models;
use crate::syncers; use crate::syncers;
#[derive(Default)]
pub struct RetrieveRecords { pub struct RetrieveRecords {
pub api: models::api::API, pub api: models::api::API,
} }
/*
impl Default for RetrieveRecords { impl Default for RetrieveRecords {
fn default() -> Self { fn default() -> Self {
RetrieveRecords { RetrieveRecords {
@@ -15,6 +17,7 @@ impl Default for RetrieveRecords {
} }
} }
} }
*/
impl RetrieveRecords { impl RetrieveRecords {
pub async fn get_all_songs( pub async fn get_all_songs(
@@ -39,24 +42,21 @@ impl RetrieveRecords {
match response.json::<Vec<icarus_models::song::Song>>().await { match response.json::<Vec<icarus_models::song::Song>>().await {
Ok(parsed) => Ok(parsed), Ok(parsed) => Ok(parsed),
Err(err) => { Err(err) => {
return Err(std::io::Error::new( Err(std::io::Error::other(
std::io::ErrorKind::Other,
err.to_string(), err.to_string(),
)); ))
} }
} }
} }
reqwest::StatusCode::UNAUTHORIZED => { reqwest::StatusCode::UNAUTHORIZED => {
return Err(std::io::Error::new( Err(std::io::Error::other(
std::io::ErrorKind::Other,
"Need to grab a new token", "Need to grab a new token",
)); ))
} }
other => { other => {
return Err(std::io::Error::new( Err(std::io::Error::other(
std::io::ErrorKind::Other,
other.to_string(), other.to_string(),
)); ))
} }
} }
} }
+18 -20
View File
@@ -6,10 +6,12 @@ use reqwest;
use crate::models; use crate::models;
use crate::syncers; use crate::syncers;
#[derive(Default)]
pub struct Upload { pub struct Upload {
pub api: models::api::API, pub api: models::api::API,
} }
/*
impl Default for Upload { impl Default for Upload {
fn default() -> Self { fn default() -> Self {
Upload { Upload {
@@ -17,6 +19,7 @@ impl Default for Upload {
} }
} }
} }
*/
impl Upload { impl Upload {
pub async fn upload_song_with_metadata( pub async fn upload_song_with_metadata(
@@ -33,8 +36,8 @@ impl Upload {
println!("Url is empty"); println!("Url is empty");
} }
println!("Url: {}", url); println!("Url: {url}");
println!("Token: {}", access_token); println!("Token: {access_token}");
println!("Path: {:?}", song.song_path()); println!("Path: {:?}", song.song_path());
let mut headers = reqwest::header::HeaderMap::new(); let mut headers = reqwest::header::HeaderMap::new();
@@ -44,7 +47,7 @@ impl Upload {
); );
headers.insert(reqwest::header::ACCEPT, HeaderValue::from_static("*/*")); headers.insert(reqwest::header::ACCEPT, HeaderValue::from_static("*/*"));
let form = self.init_form(&song, &cover); let form = self.init_form(song, cover);
let client = reqwest::Client::builder().build().unwrap(); let client = reqwest::Client::builder().build().unwrap();
match client match client
.post(url) .post(url)
@@ -54,10 +57,10 @@ impl Upload {
.await .await
{ {
Ok(r) => { Ok(r) => {
return Ok(r); Ok(r)
} }
Err(err) => { Err(err) => {
return Err(err); Err(err)
} }
} }
} }
@@ -67,25 +70,24 @@ impl Upload {
song: &icarus_models::song::Song, song: &icarus_models::song::Song,
cover: &icarus_models::coverart::CoverArt, cover: &icarus_models::coverart::CoverArt,
) -> reqwest::multipart::Form { ) -> reqwest::multipart::Form {
let songpath = match song.song_path() { let songpath = song.song_path().unwrap_or_default();
Ok(s) => s,
Err(_) => String::new(),
};
let coverpath = cover.path.clone(); let coverpath = cover.path.clone();
println!("Cover path: {:?}", coverpath); println!("Cover path: {coverpath:?}");
let song_detail = match song.to_metadata_json(true) { let song_detail = song.to_metadata_json(true).unwrap_or_default();
/*{
Ok(s) => s, Ok(s) => s,
Err(_) => String::new(), Err(_) => String::new(),
}; };
*/
println!("\n{}\n", song_detail); println!("\n{song_detail}\n");
let mut song_filename = String::from("audio"); let mut song_filename = String::from("audio");
song_filename += icarus_models::constants::file_extensions::audio::DEFAULTMUSICEXTENSION; song_filename += icarus_models::constants::file_extensions::audio::DEFAULTMUSICEXTENSION;
let mut cover_filename = String::from("cover"); let mut cover_filename = String::from("cover");
cover_filename += icarus_models::constants::file_extensions::image::JPGEXTENSION; cover_filename += icarus_models::constants::file_extensions::image::JPGEXTENSION;
let form = reqwest::multipart::Form::new() reqwest::multipart::Form::new()
.part( .part(
"file", "file",
reqwest::multipart::Part::bytes(std::fs::read(songpath).unwrap()) reqwest::multipart::Part::bytes(std::fs::read(songpath).unwrap())
@@ -96,15 +98,11 @@ impl Upload {
reqwest::multipart::Part::bytes(std::fs::read(coverpath).unwrap()) reqwest::multipart::Part::bytes(std::fs::read(coverpath).unwrap())
.file_name(cover_filename), .file_name(cover_filename),
) )
.text("metadata", song_detail); .text("metadata", song_detail)
return form;
} }
pub fn set_api(&mut self, host: &String) { pub fn set_api(&mut self, host: &str) {
let mut api = models::api::API::default(); let api = models::api::API { url: host.to_owned(), version: String::from("v1"), endpoint: String::new() };
api.url = host.clone();
api.version = String::from("v1");
self.api = api; self.api = api;
} }
} }
+2 -2
View File
@@ -4,11 +4,11 @@ use serde::{Deserialize, Serialize};
pub struct Checks {} pub struct Checks {}
impl Checks { impl Checks {
pub fn _is_numeric(text: &String) -> bool { pub fn _is_numeric(text: &str) -> bool {
text.parse::<f64>().is_ok() text.parse::<f64>().is_ok()
} }
pub fn _index_of_item_in_container<F>(container: &String, item: &char, func: F) -> i32 pub fn _index_of_item_in_container<F>(container: &str, item: &char, func: F) -> i32
where where
F: Fn(&char, &char) -> bool, F: Fn(&char, &char) -> bool,
{ {
+1 -2
View File
@@ -1,8 +1,7 @@
pub fn o_to_string(val: &std::ffi::OsString) -> Result<std::string::String, std::io::Error> { pub fn o_to_string(val: &std::ffi::OsString) -> Result<std::string::String, std::io::Error> {
match val.clone().into_string() { match val.clone().into_string() {
Ok(value) => Ok(value), Ok(value) => Ok(value),
Err(_) => Err(std::io::Error::new( Err(_) => Err(std::io::Error::other(
std::io::ErrorKind::Other,
String::from("Error"), String::from("Error"),
)), )),
} }