Making functions async
This commit is contained in:
+3
-2
@@ -7,7 +7,8 @@ mod utilities;
|
||||
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
let args_len = args.len() as i32;
|
||||
|
||||
@@ -29,7 +30,7 @@ fn main() {
|
||||
ica_action: chosen_act,
|
||||
};
|
||||
|
||||
cmt_mgr.commit_action();
|
||||
cmt_mgr.commit_action().await;
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -79,7 +79,7 @@ pub fn retrieve_song(
|
||||
}
|
||||
|
||||
impl CommitManager {
|
||||
pub fn commit_action(&mut self) {
|
||||
pub async fn commit_action(&mut self) {
|
||||
let action = &self.ica_action.action;
|
||||
println!("Committing {action} action");
|
||||
|
||||
@@ -91,11 +91,11 @@ impl CommitManager {
|
||||
// TODO: Move code to get token here and then pass it to the respective functions
|
||||
|
||||
match mapped_action {
|
||||
ActionValues::DeleteAct => self.delete_song(),
|
||||
ActionValues::DownloadAct => self.download_song(),
|
||||
ActionValues::RetrieveAct => self.retrieve_object(),
|
||||
ActionValues::DeleteAct => self.delete_song().await,
|
||||
ActionValues::DownloadAct => self.download_song().await,
|
||||
ActionValues::RetrieveAct => self.retrieve_object().await,
|
||||
ActionValues::UploadAct => self.upload_song(),
|
||||
ActionValues::UploadSongWithMetadata => self.upload_song_with_metadata(),
|
||||
ActionValues::UploadSongWithMetadata => self.upload_song_with_metadata().await,
|
||||
_ => {
|
||||
println!("Nothing good here");
|
||||
}
|
||||
@@ -132,7 +132,7 @@ impl CommitManager {
|
||||
actions
|
||||
}
|
||||
|
||||
fn delete_song(&self) {
|
||||
async fn delete_song(&self) {
|
||||
let mut prsr = parsers::api_parser::APIParser {
|
||||
apis: vec![models::api::Api::default(), models::api::Api::default()],
|
||||
ica_act: self.ica_action.clone(),
|
||||
@@ -141,7 +141,7 @@ impl CommitManager {
|
||||
prsr.parse_api(parsers::api_parser::APIType::Auth);
|
||||
let auth_api = prsr.retrieve_api(parsers::api_parser::APIType::Auth);
|
||||
|
||||
let token = self.parse_token(&auth_api);
|
||||
let token = self.parse_token(&auth_api).await;
|
||||
|
||||
println!("Deleting song");
|
||||
|
||||
@@ -173,7 +173,7 @@ impl CommitManager {
|
||||
}
|
||||
}
|
||||
|
||||
fn download_song(&self) {
|
||||
async fn download_song(&self) {
|
||||
println!("Deleting song");
|
||||
let dwn = self.ica_action.retrieve_flag_value(&String::from("-b"));
|
||||
let song_id = uuid::Uuid::from_str(dwn.as_str()).unwrap();
|
||||
@@ -186,7 +186,7 @@ impl CommitManager {
|
||||
prsr.parse_api(parsers::api_parser::APIType::Auth);
|
||||
|
||||
let auth_api = prsr.retrieve_api(parsers::api_parser::APIType::Auth);
|
||||
let token = self.parse_token(&auth_api);
|
||||
let token = self.parse_token(&auth_api).await;
|
||||
println!("Message: {}", token.message);
|
||||
let api = prsr.retrieve_api(parsers::api_parser::APIType::Main);
|
||||
|
||||
@@ -220,7 +220,7 @@ impl CommitManager {
|
||||
}
|
||||
}
|
||||
|
||||
fn retrieve_object(&self) {
|
||||
async fn retrieve_object(&self) {
|
||||
println!("Retrieving song");
|
||||
let rt = self.ica_action.retrieve_flag_value(&String::from("-rt"));
|
||||
|
||||
@@ -236,7 +236,7 @@ impl CommitManager {
|
||||
prsr.parse_api(parsers::api_parser::APIType::Auth);
|
||||
|
||||
let auth_api = prsr.retrieve_api(parsers::api_parser::APIType::Auth);
|
||||
let token = self.parse_token(&auth_api);
|
||||
let token = self.parse_token(&auth_api).await;
|
||||
println!("Token {token:?}");
|
||||
|
||||
let api = prsr.retrieve_api(parsers::api_parser::APIType::Main);
|
||||
@@ -265,7 +265,7 @@ impl CommitManager {
|
||||
panic!("Not supported");
|
||||
}
|
||||
|
||||
fn parse_token(&self, api: &models::api::Api) -> icarus_models::token::AccessToken {
|
||||
async fn parse_token(&self, api: &models::api::Api) -> icarus_models::token::AccessToken {
|
||||
println!("Fetching token");
|
||||
|
||||
let mut usr_mgr: managers::user_manager::UserManager =
|
||||
@@ -287,7 +287,7 @@ impl CommitManager {
|
||||
token.unwrap()
|
||||
}
|
||||
|
||||
fn upload_song_with_metadata(&mut self) {
|
||||
async fn upload_song_with_metadata(&mut self) {
|
||||
println!("Uplodaring song with metadara");
|
||||
|
||||
let songpath = self.ica_action.retrieve_flag_value(&String::from("-s"));
|
||||
@@ -314,15 +314,15 @@ impl CommitManager {
|
||||
println!("metadata path: {metadata_path}");
|
||||
println!("cover art path: {coverpath}");
|
||||
|
||||
let _ = self.sing_target_upload(&songpath, &track_id, &metadata_path, &coverpath);
|
||||
let _ = self.sing_target_upload(&songpath, &track_id, &metadata_path, &coverpath).await;
|
||||
} else if multitarget {
|
||||
let _ = self.multi_target_upload(&uni);
|
||||
let _ = self.multi_target_upload(&uni).await;
|
||||
} else {
|
||||
println!("Single or Multi target has not been chosen");
|
||||
}
|
||||
}
|
||||
|
||||
fn sing_target_upload(
|
||||
async fn sing_target_upload(
|
||||
&mut self,
|
||||
songpath: &String,
|
||||
track_id: &str,
|
||||
@@ -337,7 +337,7 @@ impl CommitManager {
|
||||
prsr.parse_api(parsers::api_parser::APIType::Auth);
|
||||
|
||||
let auth_api = prsr.retrieve_api(parsers::api_parser::APIType::Auth);
|
||||
let token = self.parse_token(&auth_api);
|
||||
let token = self.parse_token(&auth_api).await;
|
||||
|
||||
println!("Token: {:?}", token.token);
|
||||
|
||||
@@ -455,7 +455,7 @@ impl CommitManager {
|
||||
}
|
||||
}
|
||||
|
||||
fn multi_target_upload(&mut self, sourcepath: &String) -> std::io::Result<()> {
|
||||
async fn multi_target_upload(&mut self, sourcepath: &String) -> std::io::Result<()> {
|
||||
let mut prsr = parsers::api_parser::APIParser {
|
||||
apis: vec![models::api::Api::default(), models::api::Api::default()],
|
||||
ica_act: self.ica_action.clone(),
|
||||
@@ -463,7 +463,7 @@ impl CommitManager {
|
||||
prsr.parse_api(parsers::api_parser::APIType::Main);
|
||||
prsr.parse_api(parsers::api_parser::APIType::Auth);
|
||||
let auth_api = prsr.retrieve_api(parsers::api_parser::APIType::Auth);
|
||||
let token = self.parse_token(&auth_api);
|
||||
let token = self.parse_token(&auth_api).await;
|
||||
|
||||
let directory_path = std::path::Path::new(&sourcepath);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user