feat: load static assets info in serialize able form for tera integration
This commit is contained in:
parent
73cfe1b95d
commit
33cd4e23bd
2 changed files with 73 additions and 30 deletions
|
@ -23,3 +23,63 @@ pub fn services(cfg: &mut actix_web::web::ServiceConfig) {
|
||||||
cfg.service(static_files::static_files);
|
cfg.service(static_files::static_files);
|
||||||
cfg.service(static_files::favicons);
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -25,33 +25,13 @@ use rust_embed::RustEmbed;
|
||||||
use crate::CACHE_AGE;
|
use crate::CACHE_AGE;
|
||||||
|
|
||||||
pub mod assets {
|
pub mod assets {
|
||||||
use lazy_static::lazy_static;
|
use serde::*;
|
||||||
|
|
||||||
use crate::FILES;
|
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct Img {
|
pub struct Img {
|
||||||
pub path: &'static str,
|
pub path: &'static str,
|
||||||
pub name: &'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)]
|
#[derive(RustEmbed)]
|
||||||
|
@ -121,19 +101,21 @@ mod tests {
|
||||||
use actix_web::test;
|
use actix_web::test;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::static_assets::routes::ASSETS;
|
||||||
|
use crate::tests::get_test_data;
|
||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
async fn static_assets_work() {
|
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 [
|
for file in [
|
||||||
assets::LOGO.path,
|
ASSETS.logo.path,
|
||||||
assets::HEADSETS.path,
|
ASSETS.js,
|
||||||
*crate::JS,
|
ASSETS.css,
|
||||||
*crate::CSS,
|
ASSETS.mobile_css,
|
||||||
*crate::MOBILE_CSS,
|
ASSETS.glue,
|
||||||
*crate::GLUE,
|
|
||||||
]
|
]
|
||||||
.iter()
|
.iter()
|
||||||
{
|
{
|
||||||
|
@ -150,7 +132,8 @@ mod tests {
|
||||||
async fn favicons_work() {
|
async fn favicons_work() {
|
||||||
assert!(Favicons::get("favicon.ico").is_some());
|
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(
|
let resp = test::call_service(
|
||||||
&app,
|
&app,
|
||||||
|
|
Loading…
Reference in a new issue