Skip to content

Commit

Permalink
Make clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
carlosthe19916 committed Apr 17, 2024
1 parent 6fd55fd commit 341ee40
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 13 deletions.
6 changes: 3 additions & 3 deletions common/ui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ pub fn generate_index_html(ui: &UI) -> tera::Result<String> {
"| default(value=branding.application.title)",
);

let env_json = serde_json::to_string(&ui).expect("Could not create JSON from ENV");
let env_json = serde_json::to_string(&ui)?;
let env_base64 = BASE64_STANDARD.encode(env_json.as_bytes());

let branding_file_content =
fs::read_to_string(format!("{STATIC_DIR}/{}", "branding/strings.json")).unwrap();
let branding: Value = serde_json::from_str(&branding_file_content).unwrap();
fs::read_to_string(format!("{STATIC_DIR}/{}", "branding/strings.json"))?;
let branding: Value = serde_json::from_str(&branding_file_content)?;

let mut context = tera::Context::new();
context.insert("_env", &env_base64);
Expand Down
12 changes: 11 additions & 1 deletion server/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,17 @@ impl InitData {
analytics_write_key: String::from(""),
};

let index_html = generate_index_html(&ui).unwrap();
let index_html = generate_index_html(&ui).unwrap_or(
r#"
<!DOCTYPE html>
<html>
<body>
<h1>Error</h1>
</body>
</html>
"#
.to_string(),
);
let http_response = HttpResponse::Ok()
.content_type(actix_web::http::header::ContentType::html())
.body(index_html);
Expand Down
25 changes: 16 additions & 9 deletions trustd/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::path::Path;
use std::process::Command;
use std::process::{Command, ExitStatus};
use std::{fs, io};

static UI_DIR: &str = "../ui";
Expand All @@ -17,30 +17,37 @@ fn main() {

println!("cargo:rerun-if-changed={}", UI_DIR_SRC);

install_ui_deps();
build_ui();
copy_dir_all(UI_DIST_DIR, STATIC_DIR).unwrap();
let build_ui_status = install_ui_deps()
.and_then(|_| build_ui())
.and_then(|_| copy_dir_all(UI_DIST_DIR, STATIC_DIR));

match build_ui_status {
Ok(_) => println!("UI built successfully"),
Err(_) => println!("Error while building UI"),
}
}

fn install_ui_deps() {
if !Path::new("./ui/node_modules").exists() {
fn install_ui_deps() -> io::Result<ExitStatus> {
if !Path::new("../ui/node_modules").exists() {
println!("Installing node dependencies...");
Command::new(NPM_CMD)
.args(["clean-install", "--ignore-scripts"])
.current_dir(UI_DIR)
.status()
.unwrap();
} else {
Ok(ExitStatus::default())
}
}

fn build_ui() {
fn build_ui() -> io::Result<ExitStatus> {
if !Path::new(STATIC_DIR).exists() {
println!("Building UI...");
Command::new(NPM_CMD)
.args(["run", "build"])
.current_dir(UI_DIR)
.status()
.unwrap();
} else {
Ok(ExitStatus::default())
}
}

Expand Down

0 comments on commit 341ee40

Please sign in to comment.