From 7a6f5d3ad35cfbd539e597e32ed72de812931fcd Mon Sep 17 00:00:00 2001 From: Maix0 Date: Thu, 27 Jun 2024 14:15:50 +0200 Subject: [PATCH] Update to add git pull --- .gitignore | 1 + src/main.rs | 68 ++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 55 insertions(+), 14 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ea8c4bf --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/target diff --git a/src/main.rs b/src/main.rs index 3c27967..a90bd49 100644 --- a/src/main.rs +++ b/src/main.rs @@ -359,7 +359,7 @@ async fn oauth2_callback( cookie.set_expires(Some(now)); cookie.set_same_site(SameSite::None); cookie.set_secure(true); - // cookie.set_domain("localhost:3000"); + // cookie.set_domain("localhost:3000"); cookie.set_path("/"); //cookie.set_http_only(Some(false)); state.users.write().unwrap().insert( @@ -483,17 +483,25 @@ async fn stop(_user: UserLoggedIn) -> Redirect { #[derive(Serialize, Deserialize)] struct BotConfig { piscine: Vec, + pc_tut: Vec, + id_server: String, + id_channel_alerte: String, + id_rote: String, + mois: String, + annee: String, } async fn get_config(_user: UserLoggedIn) -> Result, (StatusCode, String)> { info!("Requested config"); - let Ok(mut file) = tokio::fs::File::open(std::env::var("CONFIG_PATH").map_err(|e| { - error!("Failed to open config file: {e}"); - ( - StatusCode::INTERNAL_SERVER_ERROR, - "please set env CONFIG_PATH".to_string(), - ) - })?) + let Ok(mut file) = tokio::fs::File::open( + std::env::var("BOTLOC_DIR").map_err(|e| { + error!("Failed to open config file: {e}"); + ( + StatusCode::INTERNAL_SERVER_ERROR, + "please set env CONFIG_PATH".to_string(), + ) + })? + "/config.json", + ) .await .map_err(|e| { error!("Failed to open config file: {e}"); @@ -502,8 +510,8 @@ async fn get_config(_user: UserLoggedIn) -> Result, (StatusCode, return Err(( StatusCode::INTERNAL_SERVER_ERROR, format!( - "failed to open config file: {}", - std::env::var("CONFIG_PATH").unwrap() + "failed to open config file: {}/config.json", + std::env::var("BOTLOC_DIR").unwrap() ), )); }; @@ -521,8 +529,8 @@ async fn get_config(_user: UserLoggedIn) -> Result, (StatusCode, return Err(( StatusCode::INTERNAL_SERVER_ERROR, format!( - "Failed to read config file at {}", - std::env::var("CONFIG_PATH").unwrap() + "Failed to read config file at {}/config.json", + std::env::var("BOTLOC_DIR").unwrap() ), )); }; @@ -533,8 +541,8 @@ async fn get_config(_user: UserLoggedIn) -> Result, (StatusCode, return Err(( StatusCode::INTERNAL_SERVER_ERROR, format!( - "Failed to read config file as json at {}", - std::env::var("CONFIG_PATH").unwrap() + "Failed to read config file as json at {}/config.json", + std::env::var("BOTLOC_DIR").unwrap() ), )); }; @@ -559,3 +567,35 @@ async fn status() -> Result { StatusCode::INTERNAL_SERVER_ERROR }) } + +async fn git_pull() -> Result { + info!("Requested to pull"); + let mut output = tokio::process::Command::new("git") + .current_dir(std::env::var("BOTLOC_DIR").map_err(|e| { + error!("Error with git pull command {e}"); + ( + StatusCode::INTERNAL_SERVER_ERROR, + "Please set the BOTLOC_DIR variable", + ) + })?) + .args(["pull"]) + .output() + .await + // let mut output = child.wait_with_output().await + .map_err(|e| { + error!("Error with git pull command {e}"); + ( + StatusCode::INTERNAL_SERVER_ERROR, + "Error with the git pull command!", + ) + })?; + output.stdout.push(b'\n'); + output.stdout.append(&mut output.stderr); + String::from_utf8(output.stdout).map_err(|e| { + error!("Error with git pull output {e}"); + ( + StatusCode::INTERNAL_SERVER_ERROR, + "Error with the git pull output!", + ) + }) +}