diff --git a/src/rocket_api.rs b/src/rocket_api.rs index 3a5a85c..222ea38 100644 --- a/src/rocket_api.rs +++ b/src/rocket_api.rs @@ -2,6 +2,7 @@ use rocket::http::{Cookie, Cookies, Status}; use rocket::request::{self, FromRequest, Request}; use rocket::{Outcome, State}; use rocket_contrib::json::Json; +use std::path::PathBuf; use std::sync::Arc; use config::{self, Config}; @@ -15,7 +16,7 @@ const CURRENT_MINOR_VERSION: i32 = 2; const SESSION_FIELD_USERNAME: &str = "username"; pub fn get_routes() -> Vec { - routes![version, initial_setup, get_settings, put_settings, trigger_index, auth] + routes![version, initial_setup, get_settings, put_settings, trigger_index, auth, browse_root, browse, flatten_root, flatten] } struct Auth { @@ -127,3 +128,27 @@ fn auth(db: State, credentials: Json, mut cookies: Cookies) }; Ok(Json(auth_output)) } + +#[get("/browse")] +fn browse_root(db: State, _auth: Auth) -> Result<(Json>), errors::Error> { + let result = index::browse::(&db, &PathBuf::new())?; + Ok(Json(result)) +} + +#[get("/browse/")] +fn browse(db: State, _auth: Auth, path: PathBuf) -> Result<(Json>), errors::Error> { + let result = index::browse::(&db, &path)?; + Ok(Json(result)) +} + +#[get("/flatten")] +fn flatten_root(db: State, _auth: Auth) -> Result<(Json>), errors::Error> { + let result = index::flatten::(&db, &PathBuf::new())?; + Ok(Json(result)) +} + +#[get("/flatten/")] +fn flatten(db: State, _auth: Auth, path: PathBuf) -> Result<(Json>), errors::Error> { + let result = index::flatten::(&db, &path)?; + Ok(Json(result)) +} \ No newline at end of file