Skip to content

Commit

Permalink
A bit of cleanup and adding a GHA.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob McWhirter committed May 9, 2024
1 parent 1da9eb8 commit 0a48bd3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci-actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:

steps:
- uses: actions/checkout@v4
- uses: Swatinem/rust-cache@v2
- name: Use Node.js
uses: actions/setup-node@v4
with:
Expand All @@ -31,3 +32,13 @@ jobs:
run: npm run build
- name: Test
run: npm run test -- --coverage --watchAll=false

- name: Format
run: cargo fmt --check
working-directory: ./crate
- name: Check
run: cargo check
working-directory: ./crate
- name: Clippy
run: cargo clippy --all-targets --all-features -- -D warnings -D clippy::unwrap_used -D clippy::expect_used
working-directory: ./crate
19 changes: 6 additions & 13 deletions crate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ use serde::Serialize;
use serde_json::Value;
use static_files::resource::new_resource;
use static_files::Resource;
use std::cell::OnceCell;
use std::collections::HashMap;
use std::fs;
use std::str::from_utf8;
use std::sync::{Arc, Mutex, OnceLock};
use std::sync::OnceLock;

#[derive(Serialize, Clone, Default)]
pub struct UI {
Expand Down Expand Up @@ -77,7 +75,7 @@ pub fn generate_index_html(
tera::Tera::one_off(&template, &context, true)
}

pub fn trustify_ui(ui: &UI) -> Result<HashMap<&'static str, Resource>, ()> {
pub fn trustify_ui(ui: &UI) -> HashMap<&'static str, Resource> {
let mut resources = generate();

let template_file = resources.get("index.html.ejs");
Expand All @@ -87,10 +85,8 @@ pub fn trustify_ui(ui: &UI) -> Result<HashMap<&'static str, Resource>, ()> {
if let (Some(template_file), Some(branding_file_content)) =
(template_file, branding_file_content)
{
let template_file = from_utf8(template_file.data).map_err(|_| ()).unwrap();
let branding_file_content = from_utf8(branding_file_content.data)
.map_err(|_| ())
.unwrap();
let template_file = from_utf8(template_file.data).unwrap();
let branding_file_content = from_utf8(branding_file_content.data).unwrap();
generate_index_html(
ui,
template_file.to_string(),
Expand All @@ -102,12 +98,9 @@ pub fn trustify_ui(ui: &UI) -> Result<HashMap<&'static str, Resource>, ()> {
}
});

resources.insert(
"",
new_resource(index_html.as_bytes(), 0, "text/html"),
);
resources.insert("", new_resource(index_html.as_bytes(), 0, "text/html"));

Ok(resources)
resources
}

static INDEX_HTML: OnceLock<String> = OnceLock::new();

0 comments on commit 0a48bd3

Please sign in to comment.