Update dependencies #53

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