add vault --name option, /api/info endpoint
parent
7f358932f6
commit
8044137531
|
@ -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(
|
||||
"/",
|
||||
|
|
|
@ -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<String>,
|
||||
pub directory: PathBuf,
|
||||
pub db_pool: DbPool,
|
||||
pub job_container: Arc<RwLock<JobContainer>>,
|
||||
|
@ -207,3 +209,11 @@ pub async fn get_jobs(state: web::Data<State>) -> Result<HttpResponse, Error> {
|
|||
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<State>) -> Result<HttpResponse, Error> {
|
||||
Ok(HttpResponse::Ok().json(json!({
|
||||
"name": state.vault_name,
|
||||
"location": state.directory
|
||||
})))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue