Cargo formatting

This commit is contained in:
kdeng00
2024-05-26 20:35:55 -04:00
parent a3c0565863
commit c0dc1eb78c
10 changed files with 44 additions and 56 deletions
-1
View File
@@ -39,7 +39,6 @@ impl ActionManager {
];
}
pub fn initialize(&mut self) {
self.validate_flags();
self.validate_action();
+15 -16
View File
@@ -1,17 +1,17 @@
use std::collections::HashMap;
use std::default::Default;
use std::fs::File;
use std::io::{Read, Error};
use std::io::{Error, Read};
use tokio::runtime::Runtime;
use futures::{FutureExt, TryFutureExt};
use serde::{Deserialize, Serialize};
use crate::{exit_program, managers};
use crate::models;
use crate::parsers;
use crate::syncers;
use crate::utilities;
use crate::{exit_program, managers};
#[derive(Debug, Deserialize, Serialize)]
pub struct CommitManager {
@@ -86,7 +86,7 @@ impl CommitManager {
ActionValues::UploadSongWithMetadata => self.upload_song_with_metadata(),
_ => {
println!("Nothing good here");
},
}
}
}
@@ -142,9 +142,7 @@ impl CommitManager {
}
}
let del = syncers::delete::Delete {
api: api,
};
let del = syncers::delete::Delete { api: api };
println!("Deleting song..");
@@ -201,9 +199,11 @@ 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;
// !songPath.empty() && !metadataPath.empty() &&
let single_target = songpath.len() > 0
&& metadata_path.len() > 0
&& coverpath.len() > 0
&& track_id.len() > 0;
// !songPath.empty() && !metadataPath.empty() &&
// !coverPath.empty() && !trackID.empty() ? true : false;
let uni = self.ica_action.retrieve_flag_value(&String::from("-smca"));
@@ -213,7 +213,6 @@ impl CommitManager {
println!("Cannot upload from source and directory");
}
if single_target {
println!("Song path: {}", songpath);
println!("Track ID: {}", track_id);
@@ -417,13 +416,13 @@ impl CommitManager {
let content = self.retrieve_file_content(&path);
// let alb = serde_json::from_str(&content.unwrap());
/*
let mut file: std::fs::File = std::fs::File::open(filepath).unwrap();
let mut data = String::new();
file.read_to_string(&mut data).unwrap();
/*
let mut file: std::fs::File = std::fs::File::open(filepath).unwrap();
let mut data = String::new();
file.read_to_string(&mut data).unwrap();
return serde_json::from_str(&data).unwrap();
*/
return serde_json::from_str(&data).unwrap();
*/
// return alb.unwrap();
return serde_json::from_str(&content.unwrap()).unwrap();
+4 -8
View File
@@ -33,21 +33,17 @@ impl TokenManager {
let mut token = models::token::Token::default();
let client = reqwest::Client::new();
let response = client.post(&url)
.json(&self.user)
.send()
.await
.unwrap();
let response = client.post(&url).json(&self.user).send().await.unwrap();
match response.status() {
reqwest::StatusCode::OK => {
// on success, parse our JSON to an APIResponse
let s = response.json::<models::token::Token>().await;
match s {
//
//
Ok(parsed) => {
token = parsed;
},
token = parsed;
}
Err(_) => println!("Hm, the response didn't match the shape we expected."),
};
}
+1 -2
View File
@@ -39,8 +39,7 @@ impl Token {
Some(tok) => {
token += tok;
}
None => {
}
None => {}
}
return token;
+3 -2
View File
@@ -29,12 +29,13 @@ impl Delete {
let url = self.retrieve_url(&song);
let client = reqwest::Client::new();
let access_token = token.bearer_token();
let response = client.delete(&url)
let response = client
.delete(&url)
.header(reqwest::header::AUTHORIZATION, access_token)
.send()
.await
.unwrap();
match response.status() {
reqwest::StatusCode::OK => {
println!("Success!");
+4 -3
View File
@@ -2,7 +2,7 @@ use std::default::Default;
use crate::models;
pub struct Download{
pub struct Download {
pub api: models::api::API,
}
@@ -19,7 +19,8 @@ impl Download {
let url = self.retrieve_url(&song);
let access_token = token.bearer_token();
let client = reqwest::Client::new();
let response = client.get(&url)
let response = client
.get(&url)
.header(reqwest::header::AUTHORIZATION, &access_token)
.send()
.await
@@ -60,4 +61,4 @@ impl Download {
return url;
}
}
}
+10 -12
View File
@@ -5,12 +5,10 @@ use crate::models;
// use super::syncer_base::Result;
pub struct RetrieveRecords {
pub api: models::api::API,
}
impl Default for RetrieveRecords {
fn default() -> Self {
RetrieveRecords {
@@ -19,31 +17,31 @@ impl Default for RetrieveRecords {
}
}
impl RetrieveRecords {
pub async fn get_all_songs(&self, token: &models::token::Token)
-> Result<Vec<models::song::Song>, Error> {
pub async fn get_all_songs(
&self,
token: &models::token::Token,
) -> Result<Vec<models::song::Song>, Error> {
let mut songs: Vec<models::song::Song> = Vec::new();
let url = self.retrieve_url();
let access_token = token.bearer_token();
let client = reqwest::Client::new();
let response = client.get(&url)
let response = client
.get(&url)
.header(reqwest::header::AUTHORIZATION, access_token)
.send()
.await
.unwrap();
match response.status() {
reqwest::StatusCode::OK => {
// on success, parse our JSON to an APIResponse
let s = response.json::<Vec<models::song::Song>>().await;
match s {
//
//
Ok(parsed) => {
songs = parsed;
},
}
Err(_) => println!("Hm, the response didn't match the shape we expected."),
};
}
@@ -54,7 +52,7 @@ impl RetrieveRecords {
panic!("Uh oh! Something unexpected happened: {:?}", other);
}
}
return Ok(songs);
}
@@ -71,4 +69,4 @@ impl RetrieveRecords {
return url;
}
}
}
-2
View File
@@ -26,5 +26,3 @@ pub enum Result {
UNAUTHORIZED,
NOTFOUND,
}
+4 -4
View File
@@ -22,12 +22,13 @@ impl Upload {
let url = self.retrieve_url(&song);
let client = reqwest::Client::new();
let access_token = token.bearer_token();
let response = client.post(&url)
let response = client
.post(&url)
.header(reqwest::header::AUTHORIZATION, access_token)
.send()
.await
.unwrap();
match response.status() {
reqwest::StatusCode::OK => {
println!("Success!");
@@ -38,7 +39,6 @@ impl Upload {
}
}
fn retrieve_url(&self, song: &models::song::Song) -> String {
// let mut url: String = String::new();
let api = &self.api;
@@ -52,4 +52,4 @@ impl Upload {
return url;
}
}
}
+3 -6
View File
@@ -27,12 +27,9 @@ impl Checks {
}
// TODO: Implement
pub fn index_of_item_in_container<F>(
container: &String,
item: &char,
func: F,
) -> i32
where F: Fn(&char, &char) -> bool,
pub fn index_of_item_in_container<F>(container: &String, item: &char, func: F) -> i32
where
F: Fn(&char, &char) -> bool,
{
let mut index = -1;