diff --git a/src/static_assets/mod.rs b/src/static_assets/mod.rs index a080139..a8c8161 100644 --- a/src/static_assets/mod.rs +++ b/src/static_assets/mod.rs @@ -23,3 +23,63 @@ pub fn services(cfg: &mut actix_web::web::ServiceConfig) { cfg.service(static_files::static_files); cfg.service(static_files::favicons); } + +pub mod routes { + use lazy_static::lazy_static; + use serde::*; + + use super::static_files::assets::Img; + use crate::FILES; + + lazy_static! { + pub static ref ASSETS: Assets = Assets::new(); + } + + #[derive(Clone, Debug, PartialEq, Eq, Serialize)] + pub struct Svg { + pub trash: Img, + } + + impl Svg { + /// create new instance of Routes + fn new() -> Svg { + let trash = Img { + path: FILES.get("./static/cache/img/trash.svg").unwrap(), + name: "Trash icon", + }; + + Svg { trash } + } + } + + #[derive(Clone, Debug, PartialEq, Eq, Serialize)] + /// Top-level routes data structure for V1 AP1 + pub struct Assets { + /// Authentication routes + pub css: &'static str, + pub mobile_css: &'static str, + pub js: &'static str, + pub glue: &'static str, + pub logo: Img, + pub svg: Svg, + } + + impl Assets { + /// create new instance of Routes + pub fn new() -> Assets { + let logo = Img { + path: FILES.get("./static/cache/img/icon-trans.png").unwrap(), + name: "mCaptcha logo", + }; + + Assets { + css: *crate::CSS, + mobile_css: *crate::MOBILE_CSS, + js: *crate::JS, + glue: *crate::GLUE, + svg: Svg::new(), + logo, + } + } + } +} diff --git a/src/static_assets/static_files.rs b/src/static_assets/static_files.rs index a78aabd..f6ecaed 100644 --- a/src/static_assets/static_files.rs +++ b/src/static_assets/static_files.rs @@ -25,33 +25,13 @@ use rust_embed::RustEmbed; use crate::CACHE_AGE; pub mod assets { - use lazy_static::lazy_static; - - use crate::FILES; + use serde::*; + #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] pub struct Img { pub path: &'static str, pub name: &'static str, } - - lazy_static! { - pub static ref LOGO: Img = Img { - path: FILES.get("./static/cache/img/icon-trans.png").unwrap(), - name: "mCaptcha logo" - }; - pub static ref TRASH: Img = Img { - path: FILES.get("./static/cache/img/trash.svg").unwrap(), - name: "Trash logo" - }; - pub static ref HEADSETS: Img = Img { - path: FILES.get("./static/cache/img/headsets.jpg").unwrap(), - name: "Headsets image" - }; - pub static ref EXTERNAL_LINK: Img = Img { - path: FILES.get("./static/cache/img/external-link.svg").unwrap(), - name: "External Link" - }; - } } #[derive(RustEmbed)] @@ -121,19 +101,21 @@ mod tests { use actix_web::test; use super::*; + use crate::static_assets::routes::ASSETS; + use crate::tests::get_test_data; use crate::*; #[actix_rt::test] async fn static_assets_work() { - let app = get_app!().await; + let data = get_test_data().await; + let app = get_app!(data).await; for file in [ - assets::LOGO.path, - assets::HEADSETS.path, - *crate::JS, - *crate::CSS, - *crate::MOBILE_CSS, - *crate::GLUE, + ASSETS.logo.path, + ASSETS.js, + ASSETS.css, + ASSETS.mobile_css, + ASSETS.glue, ] .iter() { @@ -150,7 +132,8 @@ mod tests { async fn favicons_work() { assert!(Favicons::get("favicon.ico").is_some()); - let app = get_app!().await; + let data = get_test_data().await; + let app = get_app!(data).await; let resp = test::call_service( &app,