diff --git a/config/default.toml b/config/default.toml index 0b88e6a4..94808aa2 100644 --- a/config/default.toml +++ b/config/default.toml @@ -1,4 +1,5 @@ debug = true +source_code = "https://github.com/mCaptcha/guard" [database] # This section deals with the database location and how to access it diff --git a/src/docs.rs b/src/docs.rs index 119ceb66..d25fbf53 100644 --- a/src/docs.rs +++ b/src/docs.rs @@ -16,12 +16,40 @@ */ use actix_web::body::Body; -use actix_web::{get, web, HttpResponse, Responder}; +use actix_web::{web, HttpResponse, Responder}; use mime_guess::from_path; use rust_embed::RustEmbed; use std::borrow::Cow; +pub const DOCS: routes::Docs = routes::Docs::new(); + +pub mod routes { + pub struct Docs { + pub home: &'static str, + pub spec: &'static str, + pub assets: &'static str, + } + + impl Docs { + pub const fn new() -> Self { + Docs { + home: "/docs", + spec: "/docs/openapi.json", + assets: "/docs/{_:.*}", + } + } + } +} + +pub fn services(cfg: &mut web::ServiceConfig) { + use crate::define_resource; + + define_resource!(cfg, DOCS.home, Methods::Get, index); + define_resource!(cfg, DOCS.spec, Methods::Get, spec); + define_resource!(cfg, DOCS.assets, Methods::Get, dist); +} + #[derive(RustEmbed)] #[folder = "docs/"] struct Asset; @@ -41,29 +69,20 @@ pub fn handle_embedded_file(path: &str) -> HttpResponse { } } -#[get("/docs/{_:.*}")] async fn dist(path: web::Path) -> impl Responder { handle_embedded_file(&path.0) } -#[get("/docs/openapi.json")] async fn spec() -> HttpResponse { HttpResponse::Ok() .content_type("appilcation/json") .body(&*crate::OPEN_API_DOC) } -#[get("/docs")] async fn index() -> HttpResponse { handle_embedded_file("index.html") } -pub fn services(cfg: &mut web::ServiceConfig) { - cfg.service(spec); - cfg.service(index); - cfg.service(dist); -} - #[cfg(test)] mod tests { use actix_web::http::StatusCode; diff --git a/src/main.rs b/src/main.rs index 7656c567..ef7e39db 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,6 +40,7 @@ mod middleware; pub use api::v1::ROUTES as V1_API_ROUTES; pub use data::Data; +pub use docs::DOCS; pub use pages::routes::ROUTES as PAGES; pub use settings::Settings; use static_assets::FileMap; diff --git a/src/settings.rs b/src/settings.rs index 935fb744..cab5f534 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -98,6 +98,7 @@ pub struct Settings { pub database: Database, pub server: Server, pub pow: Captcha, + pub source_code: String, } #[cfg(not(tarpaulin_include))] @@ -116,6 +117,8 @@ impl Settings { // TODO change PLACEHOLDER to app name s.merge(Environment::with_prefix("GUARD"))?; + check_url(&s); + match env::var("PORT") { Ok(val) => { s.set("server.port", val).unwrap(); @@ -138,6 +141,15 @@ impl Settings { } } +#[cfg(not(tarpaulin_include))] +fn check_url(s: &Config) { + let url = s + .get::("source_code") + .expect("Couldn't access source_code"); + + Url::parse(&url).expect("Please enter a URL for source_code in settings"); +} + #[cfg(not(tarpaulin_include))] fn set_from_database_url(s: &mut Config, database_conf: &DatabaseBuilder) { s.set("database.username", database_conf.username.clone()) diff --git a/templates/panel/header/sidebar/index.html b/templates/panel/header/sidebar/index.html index 846e648e..f1d019ad 100644 --- a/templates/panel/header/sidebar/index.html +++ b/templates/panel/header/sidebar/index.html @@ -65,7 +65,7 @@
  • - + " alt="" />
  • - + " alt="GitHub Icon" />