tsk-45: Root directory check (#66)
Closes #45 Reviewed-on: #66 Co-authored-by: phoenix <kundeng00@pm.me> Co-committed-by: phoenix <kundeng00@pm.me>
This commit was merged in pull request #66.
This commit is contained in:
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1322,7 +1322,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "songparser"
|
name = "songparser"
|
||||||
version = "0.4.8"
|
version = "0.4.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"futures",
|
"futures",
|
||||||
"icarus_envy",
|
"icarus_envy",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "songparser"
|
name = "songparser"
|
||||||
version = "0.4.8"
|
version = "0.4.9"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
rust-version = "1.90"
|
rust-version = "1.90"
|
||||||
|
|
||||||
|
|||||||
@@ -3,4 +3,25 @@ pub struct App {
|
|||||||
pub uri: String,
|
pub uri: String,
|
||||||
pub auth_uri: String,
|
pub auth_uri: String,
|
||||||
pub token: icarus_models::login_result::LoginResult,
|
pub token: icarus_models::login_result::LoginResult,
|
||||||
|
pub root_directory: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl App {
|
||||||
|
pub fn does_root_directory_exists(&self) -> bool {
|
||||||
|
let path = std::path::Path::new(&self.root_directory);
|
||||||
|
if path.exists() { path.is_dir() } else { false }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn initialize_app_config() -> App {
|
||||||
|
App {
|
||||||
|
uri: icarus_envy::environment::get_icarus_base_api_url()
|
||||||
|
.await
|
||||||
|
.value,
|
||||||
|
auth_uri: icarus_envy::environment::get_icarus_auth_base_api_url()
|
||||||
|
.await
|
||||||
|
.value,
|
||||||
|
root_directory: icarus_envy::environment::get_root_directory().await.value,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
29
src/main.rs
29
src/main.rs
@@ -11,22 +11,27 @@ pub const SECONDS_TO_SLEEP: u64 = 5;
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let mut app = config::App {
|
let mut app = config::initialize_app_config().await;
|
||||||
uri: icarus_envy::environment::get_icarus_base_api_url()
|
|
||||||
.await
|
|
||||||
.value,
|
|
||||||
auth_uri: icarus_envy::environment::get_icarus_auth_base_api_url()
|
|
||||||
.await
|
|
||||||
.value,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
println!("Base URL: {:?}", app.uri);
|
println!("Base URL: {:?}", app.uri);
|
||||||
println!("Auth URL: {:?}", app.auth_uri);
|
println!("Auth URL: {:?}", app.auth_uri);
|
||||||
|
|
||||||
match auth::get_token(&app).await {
|
if !app.does_root_directory_exists() {
|
||||||
Ok(login_result) => {
|
eprintln!("Root directory does not exist");
|
||||||
app.token = login_result;
|
println!("Attempting to create directory");
|
||||||
|
let path = std::path::Path::new(&app.root_directory);
|
||||||
|
match std::fs::create_dir(path) {
|
||||||
|
Ok(_) => {
|
||||||
|
println!("Directory created");
|
||||||
}
|
}
|
||||||
|
Err(err) => {
|
||||||
|
eprintln!("Error creating directory: {err:?}");
|
||||||
|
std::process::exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
app.token = match auth::get_token(&app).await {
|
||||||
|
Ok(login_result) => login_result,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {err:?}");
|
eprintln!("Error: {err:?}");
|
||||||
std::process::exit(-1);
|
std::process::exit(-1);
|
||||||
|
|||||||
Reference in New Issue
Block a user