Warning fixes (#54)

* More warning fixes

* Should be the last of the warning fixes

* Code cleanup

* Code formatting
This commit was merged in pull request #54.
This commit is contained in:
KD
2025-07-02 19:25:08 -04:00
committed by GitHub
parent 8b2b2f82e9
commit dbcfcfa109
14 changed files with 135 additions and 217 deletions
+17 -22
View File
@@ -23,14 +23,14 @@ impl Default for ActionManager {
impl ActionManager {
pub fn retrieve_icarus_action(&self) -> models::icarus_action::IcarusAction {
return models::icarus_action::IcarusAction {
models::icarus_action::IcarusAction {
flags: self.flags.clone(),
action: String::from(&self.action),
};
}
}
fn supported_flags(&self) -> Vec<String> {
return vec![
vec![
String::from("-u"),
String::from("-p"),
String::from("-t"),
@@ -47,7 +47,7 @@ impl ActionManager {
String::from("-ca"),
String::from("-smca"),
String::from("-t"),
];
]
}
pub fn initialize(&mut self) {
@@ -56,8 +56,8 @@ impl ActionManager {
self.action = self.action.to_lowercase();
}
pub fn set_params(&mut self, args: &Vec<String>) {
self.params = args.clone();
pub fn set_params(&mut self, args: &[String]) {
self.params = args.to_owned();
self.param_count = self.params.len() as i32;
}
@@ -71,7 +71,7 @@ impl ActionManager {
while i < flag_vals.len() {
let flag = &flag_vals[i];
println!("Index: {} | Value: {}", i, flag);
println!("Index: {i} | Value: {flag}");
let mut flg = models::flags::Flags::default();
@@ -80,17 +80,16 @@ impl ActionManager {
flg.flag = String::from(flag);
flg.value = String::from(&flag_vals[i + 1]);
i = i + 1;
i += 1;
} else if self.is_valid_flag(flag) {
println!("Flag does not have a value");
flg.flag = String::from(flag);
} else {
println!("Flag {} is not valid", flag);
println!("Flag {flag} is not valid");
utilities::checks::exit_program(-1);
}
self.flags.push(flg);
println!("");
i += 1;
}
}
@@ -113,34 +112,30 @@ impl ActionManager {
}
}
return found;
found
}
fn does_flag_have_value(&self, flag: &String) -> bool {
let flags_tmp = self.parsed_flags();
let mut i_found: i32 = -1;
for i in 0..flags_tmp.len() {
let flg = &flags_tmp[i];
if flg == flag {
for (i, item) in flags_tmp.iter().enumerate() {
let flg = &item;
if *flg == flag {
i_found = i as i32;
break;
}
}
if i_found >= 0 {
if (i_found + 1) < flags_tmp.len().try_into().unwrap() {
return true;
(i_found + 1) < flags_tmp.len().try_into().unwrap()
} else {
return false;
}
} else {
return false;
false
}
}
fn _print_action(&self) {
if self.action.len() == 0 {
if self.action.is_empty() {
println!("Action is empty");
} else {
println!("Action is {}", self.action);
@@ -163,6 +158,6 @@ impl ActionManager {
parsed.push(flag);
}
return parsed;
parsed
}
}
+84 -113
View File
@@ -40,8 +40,8 @@ pub fn retrieve_song(
album: &icarus_models::album::collection::Album,
track: i32,
disc: i32,
directory: &String,
filename: &String,
directory: &str,
filename: &str,
) -> Result<icarus_models::song::Song> {
let mut found = false;
let mut song = icarus_models::song::Song::default();
@@ -55,16 +55,16 @@ pub fn retrieve_song(
song.audio_type = String::from(
icarus_models::constants::file_extensions::audio::DEFAULTMUSICEXTENSION,
);
song.disc = track.disc.clone();
song.disc_count = album.disc_count.clone();
song.disc = track.disc;
song.disc_count = album.disc_count;
song.duration = track.duration as i32;
song.genre = album.genre.clone();
song.title = track.title.clone();
song.year = album.year.clone();
song.track = track.track.clone();
song.track_count = album.track_count.clone();
song.directory = directory.clone();
song.filename = filename.clone();
song.year = album.year;
song.track = track.track;
song.track_count = album.track_count;
song.directory = directory.to_owned();
song.filename = filename.to_owned();
found = true;
break;
@@ -72,24 +72,21 @@ pub fn retrieve_song(
}
if found {
return Ok(song);
Ok(song)
} else {
Err(std::io::Error::other("Song not found"))
}
return Err(std::io::Error::new(
std::io::ErrorKind::NotFound,
"Song not found",
));
}
impl CommitManager {
pub fn commit_action(&mut self) {
let action = &self.ica_action.action;
println!("Committing {} action", action);
println!("Committing {action} action");
let mapped_actions = &self.map_actions();
let mapped_action = self.find_mapped_action(&mapped_actions, action);
let mapped_action = self.find_mapped_action(mapped_actions, action);
println!("{:?}", mapped_action);
println!("{mapped_action:?}");
match mapped_action {
ActionValues::DeleteAct => self.delete_song(),
@@ -114,7 +111,7 @@ impl CommitManager {
}
}
return ActionValues::None;
ActionValues::None
}
fn map_actions(&self) -> HashMap<String, ActionValues> {
@@ -130,13 +127,13 @@ impl CommitManager {
("delete".to_string(), ActionValues::DeleteAct),
]);
return actions;
actions
}
fn delete_song(&self) {
let mut prsr = parsers::api_parser::APIParser {
ica_act: self.ica_action.clone(),
api: models::api::API::default(),
api: models::api::Api::default(),
};
prsr.parse_api();
let api = prsr.retrieve_api();
@@ -167,7 +164,7 @@ impl CommitManager {
println!("Song (Id {:?}) has been successfully deleted", o.id);
}
Err(er) => {
println!("Error {:?}", er);
println!("Error {er:?}");
}
}
}
@@ -175,10 +172,10 @@ impl CommitManager {
fn download_song(&self) {
println!("Deleting song");
let dwn = self.ica_action.retrieve_flag_value(&String::from("-b"));
let id = uuid::Uuid::from_str(dwn.as_str()).unwrap();
let song_id = uuid::Uuid::from_str(dwn.as_str()).unwrap();
let mut prsr = parsers::api_parser::APIParser {
api: models::api::API::default(),
api: models::api::Api::default(),
ica_act: self.ica_action.clone(),
};
prsr.parse_api();
@@ -188,8 +185,10 @@ impl CommitManager {
println!("Message: {}", token.message);
let mut dwn_loader = syncers::download::Download { api: api.clone() };
let mut song = icarus_models::song::Song::default();
song.id = id;
let song = icarus_models::song::Song {
id: song_id,
..Default::default()
};
let result_fut = dwn_loader.download_song(&token, &song);
match Runtime::new().unwrap().block_on(result_fut) {
Ok(o) => {
@@ -198,17 +197,17 @@ impl CommitManager {
+ icarus_models::constants::file_extensions::audio::DEFAULTMUSICEXTENSION;
let data = o.as_bytes();
let mut file = std::fs::File::create(filename).expect("Failed to save");
file.write_all(&data)
file.write_all(data)
.expect("Failed to save downloaded song");
}
Err(er) => {
println!("Error {:?}", er);
println!("Error {er:?}");
match er {
syncers::download::MyError::Request(error) => {
println!("Error: {:?}", error);
println!("Error: {error:?}");
}
syncers::download::MyError::Other(ss) => {
println!("Error: {:?}", ss);
println!("Error: {ss:?}");
}
}
}
@@ -220,11 +219,11 @@ impl CommitManager {
let rt = self.ica_action.retrieve_flag_value(&String::from("-rt"));
if rt != "songs" {
panic!("Unsupported -rt: {}", rt);
panic!("Unsupported -rt: {rt}");
}
let mut prsr = parsers::api_parser::APIParser {
api: models::api::API::default(),
api: models::api::Api::default(),
ica_act: self.ica_action.clone(),
};
prsr.parse_api();
@@ -244,7 +243,7 @@ impl CommitManager {
}
}
Err(er) => {
println!("Error: {:?}", er);
println!("Error: {er:?}");
}
}
}
@@ -254,7 +253,7 @@ impl CommitManager {
panic!("Not supported");
}
fn parse_token(&self, api: &models::api::API) -> icarus_models::token::AccessToken {
fn parse_token(&self, api: &models::api::Api) -> icarus_models::token::AccessToken {
println!("Fetching token");
let mut usr_mgr: managers::user_manager::UserManager =
@@ -273,7 +272,7 @@ impl CommitManager {
let token = Runtime::new().unwrap().block_on(tok_mgr.request_token());
return token.unwrap();
token.unwrap()
}
fn upload_song_with_metadata(&mut self) {
@@ -284,13 +283,13 @@ impl CommitManager {
let coverpath = self.ica_action.retrieve_flag_value(&String::from("-ca"));
let track_id = self.ica_action.retrieve_flag_value(&String::from("-t"));
let single_target = songpath.len() > 0
&& metadata_path.len() > 0
&& coverpath.len() > 0
&& track_id.len() > 0;
let single_target = !songpath.is_empty()
&& !metadata_path.is_empty()
&& !coverpath.is_empty()
&& !track_id.is_empty();
let uni = self.ica_action.retrieve_flag_value(&String::from("-smca"));
let multitarget = uni.len() > 0;
let multitarget = !uni.is_empty();
if single_target && multitarget {
println!("Cannot upload from source and directory");
@@ -298,10 +297,10 @@ impl CommitManager {
}
if single_target {
println!("Song path: {}", songpath);
println!("Track ID: {}", track_id);
println!("metadata path: {}", metadata_path);
println!("cover art path: {}", coverpath);
println!("Song path: {songpath}");
println!("Track ID: {track_id}");
println!("metadata path: {metadata_path}");
println!("cover art path: {coverpath}");
let _ = self.sing_target_upload(&songpath, &track_id, &metadata_path, &coverpath);
} else if multitarget {
@@ -314,12 +313,12 @@ impl CommitManager {
fn sing_target_upload(
&mut self,
songpath: &String,
track_id: &String,
track_id: &str,
meta_path: &String,
cover_path: &String,
cover_path: &str,
) -> Result<()> {
let mut prsr = parsers::api_parser::APIParser {
api: models::api::API::default(),
api: models::api::Api::default(),
ica_act: self.ica_action.clone(),
};
prsr.parse_api();
@@ -339,7 +338,7 @@ impl CommitManager {
let mut cover_art = icarus_models::coverart::CoverArt {
id: uuid::Uuid::nil(),
title: String::new(),
path: cover_path.clone(),
path: cover_path.to_owned(),
data: Vec::new(),
};
let file_name = std::ffi::OsString::from(&song_file.file_name().unwrap());
@@ -347,9 +346,9 @@ impl CommitManager {
match self.find_file_extension(&file_name) {
En::SongFile => match utilities::string::o_to_string(&file_name) {
Ok(s) => {
println!("file name: {:?}", file_name);
println!("file name: {file_name:?}");
match icarus_models::album::collection::parse_album(&meta_path) {
match icarus_models::album::collection::parse_album(meta_path) {
Ok(album) => {
let filename = s.clone();
let directory = song_file.parent().unwrap().display().to_string();
@@ -371,55 +370,41 @@ impl CommitManager {
match Runtime::new().unwrap().block_on(res) {
Ok(o) => {
println!("Successfully sent {:?}", o);
println!("Successfully sent {o:?}");
Ok(())
}
Err(er) => {
println!("Some error {:?}", er);
Err(std::io::Error::new(
std::io::ErrorKind::Other,
er.to_string(),
))
println!("Some error {er:?}");
Err(std::io::Error::other(er.to_string()))
}
}
}
Err(err) => {
println!("Error: {:?}", err);
Err(std::io::Error::new(
std::io::ErrorKind::Other,
err.to_string(),
))
println!("Error: {err:?}");
Err(std::io::Error::other(err.to_string()))
}
}
}
Err(er) => {
println!("Error: {:?}", er);
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
er.to_string(),
));
println!("Error: {er:?}");
Err(std::io::Error::other(er.to_string()))
}
},
_ => {
return Err(std::io::Error::new(
std::io::ErrorKind::Other,
"No sutitable file found".to_owned(),
));
}
_ => Err(std::io::Error::other("No sutitable file found".to_owned())),
}
}
fn get_songs(
&self,
metadata_path: &String,
source_directory: &String,
source_directory: &str,
) -> Result<Vec<icarus_models::song::Song>> {
match icarus_models::album::collection::parse_album(metadata_path) {
Ok(albums) => {
let mut songs: Vec<icarus_models::song::Song> = Vec::new();
for track in &albums.tracks {
let filename = if track.track < 10 {
let song_filename = if track.track < 10 {
"track0".to_owned()
+ &track.track.to_string()
+ icarus_models::constants::file_extensions::audio::DEFAULTMUSICEXTENSION
@@ -433,18 +418,18 @@ impl CommitManager {
id: uuid::Uuid::nil(),
title: track.title.clone(),
artist: track.artist.clone(),
disc: track.disc.clone(),
track: track.track.clone(),
duration: track.duration.clone() as i32,
year: albums.year.clone(),
disc: track.disc,
track: track.track,
duration: track.duration as i32,
year: albums.year,
album_artist: albums.artist.clone(),
genre: albums.genre.clone(),
disc_count: albums.disc_count.clone(),
track_count: albums.track_count.clone(),
disc_count: albums.disc_count,
track_count: albums.track_count,
album: albums.title.clone(),
audio_type: String::from("FLAC"),
directory: source_directory.clone(),
filename: filename,
directory: source_directory.to_owned(),
filename: song_filename,
user_id: uuid::Uuid::nil(),
data: Vec::new(),
date_created: String::new(),
@@ -458,7 +443,7 @@ impl CommitManager {
fn multi_target_upload(&mut self, sourcepath: &String) -> std::io::Result<()> {
let mut prsr = parsers::api_parser::APIParser {
api: models::api::API::default(),
api: models::api::Api::default(),
ica_act: self.ica_action.clone(),
};
prsr.parse_api();
@@ -471,16 +456,10 @@ impl CommitManager {
panic!("Directory does not exist");
}
let coverart_path = match self.get_cover_art_path(&sourcepath) {
Ok(path) => path,
Err(_) => String::new(),
};
let coverart_path = self.get_cover_art_path(sourcepath).unwrap_or_default();
let mut cover_art =
icarus_models::coverart::init::init_coverart_only_path(coverart_path.clone());
let metadatapath = match self.get_metadata_path(&sourcepath) {
Ok(o) => o,
Err(_) => String::new(),
};
let metadatapath = self.get_metadata_path(sourcepath).unwrap_or_default();
let mut up = syncers::upload::Upload::default();
let host = self.ica_action.retrieve_flag_value(&String::from("-h"));
@@ -488,9 +467,7 @@ impl CommitManager {
cover_art.data = cover_art.to_data().unwrap();
println!("");
match self.get_songs(&metadatapath, &sourcepath) {
match self.get_songs(&metadatapath, sourcepath) {
Ok(sngs) => {
for song in sngs {
match Runtime::new()
@@ -498,16 +475,16 @@ impl CommitManager {
.block_on(up.upload_song_with_metadata(&token, &song, &cover_art))
{
Ok(o) => {
println!("Response: {:?}", o);
println!("Response: {o:?}");
}
Err(err) => {
println!("Error: {:?}", err);
println!("Error: {err:?}");
}
};
}
}
Err(error) => {
println!("Error: {:?}", error);
println!("Error: {error:?}");
}
}
@@ -521,18 +498,15 @@ impl CommitManager {
let file_type = entry.file_type();
let file_name = entry.file_name();
println!("file type: {:?}", file_type);
println!("file name: {:?}", file_name);
println!("file type: {file_type:?}");
println!("file name: {file_name:?}");
match self.find_file_extension(&file_name) {
En::ImageFile => {
if let En::ImageFile = self.find_file_extension(&file_name) {
let directory_part = directory_path.clone();
let fname = utilities::string::o_to_string(&file_name);
let fullpath = directory_part + "/" + &fname.unwrap();
let fullpath = format!("{}/{}", directory_part, &fname.unwrap());
return Ok(fullpath);
}
_ => {}
}
}
Ok(String::new())
@@ -583,7 +557,7 @@ impl CommitManager {
}
}
return En::Other;
En::Other
}
fn get_metadata_path(&self, directory_path: &String) -> Result<String> {
@@ -593,16 +567,13 @@ impl CommitManager {
let file_type = entry.file_type();
let file_name = entry.file_name();
println!("file type: {:?}", file_type);
println!("file name: {:?}", file_name);
println!("file type: {file_type:?}");
println!("file name: {file_name:?}");
match self.find_file_extension(&file_name) {
En::MetadataFile => {
if let En::MetadataFile = self.find_file_extension(&file_name) {
let directory_part = directory_path.clone();
let fname = utilities::string::o_to_string(&file_name);
return Ok(directory_part + "/" + &fname.unwrap());
}
_ => {}
return Ok(format!("{}/{}", directory_part, &fname.unwrap()));
}
}
@@ -615,6 +586,6 @@ impl CommitManager {
return true;
}
}
return false;
false
}
}
+9 -11
View File
@@ -4,19 +4,19 @@ use crate::models;
pub struct TokenManager {
pub user: icarus_models::user::User,
pub api: models::api::API,
pub api: models::api::Api,
}
impl Default for TokenManager {
fn default() -> Self {
let mut token = TokenManager {
user: icarus_models::user::User::default(),
api: models::api::API::default(),
api: models::api::Api::default(),
};
token.init();
return token;
token
}
}
@@ -26,7 +26,7 @@ impl TokenManager {
let url = self.retrieve_url();
println!("URL: {}", url);
println!("URL: {url}");
let mut token = icarus_models::token::AccessToken {
user_id: uuid::Uuid::nil(),
@@ -43,9 +43,7 @@ impl TokenManager {
match response.status() {
reqwest::StatusCode::OK => {
// on success, parse our JSON to an APIResponse
let s = response.json::<icarus_models::token::AccessToken>().await;
match s {
//
match response.json::<icarus_models::token::AccessToken>().await {
Ok(parsed) => {
token = parsed;
}
@@ -56,17 +54,17 @@ impl TokenManager {
println!("Need to grab a new token");
}
other => {
panic!("Uh oh! Something unexpected happened: {:?}", other);
panic!("Uh oh! Something unexpected happened: {other:?}");
}
}
return Ok(token);
Ok(token)
}
pub fn init(&mut self) {
let api = &mut self.api;
api.version = String::from("v1");
api.endpoint = String::from(format!("api/{}/login", api.version));
api.endpoint = format!("api/{}/login", api.version);
}
pub fn retrieve_url(&self) -> String {
@@ -74,6 +72,6 @@ impl TokenManager {
let mut url = String::from(&api.url);
url += &String::from(&api.endpoint);
return url;
url
}
}
+2 -11
View File
@@ -4,24 +4,15 @@ use serde::{Deserialize, Serialize};
use crate::models::{self};
#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct UserManager {
pub user: icarus_models::user::User,
pub ica_action: models::icarus_action::IcarusAction,
}
impl Default for UserManager {
fn default() -> Self {
UserManager {
user: icarus_models::user::User::default(),
ica_action: models::icarus_action::IcarusAction::default(),
}
}
}
impl UserManager {
pub fn retrieve_user(&self) -> icarus_models::user::User {
return self.user.clone();
self.user.clone()
}
pub fn parse_user_from_actions(&mut self) {
+2 -12
View File
@@ -2,19 +2,9 @@ use std::default::Default;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct API {
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct Api {
pub url: String,
pub endpoint: String,
pub version: String,
}
impl Default for API {
fn default() -> Self {
API {
url: String::new(),
endpoint: String::new(),
version: String::new(),
}
}
}
+1 -10
View File
@@ -2,17 +2,8 @@ use std::default::Default;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct Flags {
pub flag: String,
pub value: String,
}
impl Default for Flags {
fn default() -> Self {
Flags {
flag: String::new(),
value: String::new(),
}
}
}
+2 -11
View File
@@ -4,21 +4,12 @@ use serde::{Deserialize, Serialize};
use crate::models;
#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct IcarusAction {
pub action: String,
pub flags: Vec<models::flags::Flags>,
}
impl Default for IcarusAction {
fn default() -> Self {
IcarusAction {
action: String::new(),
flags: Vec::new(),
}
}
}
impl IcarusAction {
pub fn retrieve_flag_value(&self, flag: &String) -> String {
let mut val: String = String::new();
@@ -30,7 +21,7 @@ impl IcarusAction {
}
}
return val;
val
}
pub fn print_action_and_flags(&self) {
+1 -10
View File
@@ -2,17 +2,8 @@ use std::default::Default;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
#[derive(Debug, Default, Deserialize, Serialize)]
pub struct UploadForm {
pub url: Option<String>,
pub filepath: Option<String>,
}
impl Default for UploadForm {
fn default() -> Self {
UploadForm {
url: None,
filepath: None,
}
}
}
+3 -3
View File
@@ -2,13 +2,13 @@ use crate::models;
#[derive(Clone, Debug)]
pub struct APIParser {
pub api: models::api::API,
pub api: models::api::Api,
pub ica_act: models::icarus_action::IcarusAction,
}
impl APIParser {
pub fn retrieve_api(&self) -> models::api::API {
return self.api.clone();
pub fn retrieve_api(&self) -> models::api::Api {
self.api.clone()
}
pub fn parse_api(&mut self) {
+3 -3
View File
@@ -1,6 +1,6 @@
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 {
retrieve_url_with_id(api, id)
} else {
@@ -8,13 +8,13 @@ pub fn retrieve_url(api: &models::api::API, with_id: bool, id: &uuid::Uuid) -> S
}
}
fn retrieve_url_reg(api: &models::api::API) -> String {
fn retrieve_url_reg(api: &models::api::Api) -> String {
let url = format!("{}/api/{}/{}/", api.url, api.version, api.endpoint);
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 url = format!("{}/api/{}/{}/{}", api.url, api.version, api.endpoint, id);
url
+1 -1
View File
@@ -7,7 +7,7 @@ use crate::syncers;
#[derive(Clone, Debug, Default)]
pub struct Delete {
pub api: models::api::API,
pub api: models::api::Api,
}
impl Delete {
+1 -1
View File
@@ -5,7 +5,7 @@ use crate::syncers;
#[derive(Default)]
pub struct Download {
pub api: models::api::API,
pub api: models::api::Api,
}
#[derive(Debug)]
+1 -1
View File
@@ -6,7 +6,7 @@ use crate::syncers;
#[derive(Default)]
pub struct RetrieveRecords {
pub api: models::api::API,
pub api: models::api::Api,
}
impl RetrieveRecords {
+2 -2
View File
@@ -8,7 +8,7 @@ use crate::syncers;
#[derive(Default)]
pub struct Upload {
pub api: models::api::API,
pub api: models::api::Api,
}
impl Upload {
@@ -83,7 +83,7 @@ impl Upload {
}
pub fn set_api(&mut self, host: &str) {
let api = models::api::API {
let api = models::api::Api {
url: host.to_owned(),
version: String::from("v1"),
endpoint: String::new(),