Compare commits

...

1 Commits

Author SHA1 Message Date
8a8f3c1075 tsk-45: Root directory check (#66)
All checks were successful
Rust Build / Check (push) Successful in 36s
Rust Build / Test Suite (push) Successful in 36s
Rust Build / Rustfmt (push) Successful in 29s
Rust Build / Clippy (push) Successful in 36s
Rust Build / build (push) Successful in 42s
Closes #45

Reviewed-on: #66
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-10-23 20:18:05 +00:00
4 changed files with 40 additions and 14 deletions

2
Cargo.lock generated
View File

@@ -1322,7 +1322,7 @@ dependencies = [
[[package]]
name = "songparser"
version = "0.4.8"
version = "0.4.9"
dependencies = [
"futures",
"icarus_envy",

View File

@@ -1,6 +1,6 @@
[package]
name = "songparser"
version = "0.4.8"
version = "0.4.9"
edition = "2024"
rust-version = "1.90"

View File

@@ -3,4 +3,25 @@ pub struct App {
pub uri: String,
pub auth_uri: String,
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()
}
}

View File

@@ -11,22 +11,27 @@ pub const SECONDS_TO_SLEEP: u64 = 5;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut app = config::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,
..Default::default()
};
let mut app = config::initialize_app_config().await;
println!("Base URL: {:?}", app.uri);
println!("Auth URL: {:?}", app.auth_uri);
match auth::get_token(&app).await {
Ok(login_result) => {
app.token = login_result;
if !app.does_root_directory_exists() {
eprintln!("Root directory does not exist");
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) => {
eprintln!("Error: {err:?}");
std::process::exit(-1);