From 8044137531ed6d4afad1132a5808aac783a64fd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Thu, 6 May 2021 20:23:20 +0200 Subject: [PATCH] add vault --name option, /api/info endpoint --- src/main.rs | 8 ++++++++ src/routes.rs | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/main.rs b/src/main.rs index f9b9a70..f54d2b9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,6 +56,12 @@ fn main() -> Result<()> { Arg::with_name("REINITIALIZE") .long("reinitialize") .help("Delete and initialize database, if it exists already."), + ) + .arg( + Arg::with_name("VAULT_NAME") + .takes_value(true) + .long("name") + .help("Name of the vault."), ); let matches = app.get_matches(); @@ -80,6 +86,7 @@ fn main() -> Result<()> { info!("Starting server at: {}", &bind); let state = routes::State { + vault_name: matches.value_of("VAULT_NAME").map(|s| s.to_string()), directory: vault_path.clone(), db_pool: db_pool.clone(), job_container: job_container.clone(), @@ -100,6 +107,7 @@ fn main() -> Result<()> { .service(routes::latest_files) .service(routes::get_file) .service(routes::get_jobs) + .service(routes::get_info) .service( actix_files::Files::new( "/", diff --git a/src/routes.rs b/src/routes.rs index 379125c..e0d52e7 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -13,6 +13,7 @@ use anyhow::Result; use futures_util::StreamExt; use log::debug; use serde::Deserialize; +use serde_json::json; use std::collections::HashMap; use std::convert::TryFrom; use std::path::PathBuf; @@ -20,6 +21,7 @@ use std::sync::{Arc, RwLock}; #[derive(Clone)] pub struct State { + pub vault_name: Option, pub directory: PathBuf, pub db_pool: DbPool, pub job_container: Arc>, @@ -207,3 +209,11 @@ pub async fn get_jobs(state: web::Data) -> Result { let jobs = state.job_container.read().unwrap().get_jobs(); Ok(HttpResponse::Ok().json(&jobs)) } + +#[get("/api/info")] +pub async fn get_info(state: web::Data) -> Result { + Ok(HttpResponse::Ok().json(json!({ + "name": state.vault_name, + "location": state.directory + }))) +}