Sfoglia il codice sorgente

App now bundled into the binary

Lee Morgan 4 settimane fa
parent
commit
b9641f20f6
3 ha cambiato i file con 16 aggiunte e 59 eliminazioni
  1. 0 52
      Cargo.lock
  2. 0 1
      Cargo.toml
  3. 16 6
      src/controllers/home.rs

+ 0 - 52
Cargo.lock

@@ -19,29 +19,6 @@ dependencies = [
  "tracing",
 ]
 
-[[package]]
-name = "actix-files"
-version = "0.6.10"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "df8c4f30e3272d7c345f88ae0aac3848507ef5ba871f9cc2a41c8085a0f0523b"
-dependencies = [
- "actix-http",
- "actix-service",
- "actix-utils",
- "actix-web",
- "bitflags",
- "bytes",
- "derive_more",
- "futures-core",
- "http-range",
- "log",
- "mime",
- "mime_guess",
- "percent-encoding",
- "pin-project-lite",
- "v_htmlescape",
-]
-
 [[package]]
 name = "actix-http"
 version = "3.13.1"
@@ -644,7 +621,6 @@ dependencies = [
 name = "ha_permissions"
 version = "0.1.0"
 dependencies = [
- "actix-files",
  "actix-web",
  "awc",
  "dotenvy",
@@ -681,12 +657,6 @@ dependencies = [
  "itoa",
 ]
 
-[[package]]
-name = "http-range"
-version = "0.1.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573"
-
 [[package]]
 name = "httparse"
 version = "1.10.1"
@@ -922,16 +892,6 @@ version = "0.3.17"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
 
-[[package]]
-name = "mime_guess"
-version = "2.0.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f7c44f8e672c00fe5308fa235f821cb4198414e1c77935c1ab6948d3fd78550e"
-dependencies = [
- "mime",
- "unicase",
-]
-
 [[package]]
 name = "miniz_oxide"
 version = "0.8.9"
@@ -1451,12 +1411,6 @@ version = "1.20.1"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20"
 
-[[package]]
-name = "unicase"
-version = "2.9.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dbc4bc3a9f746d862c45cb89d705aa10f187bb96c76001afab07a0d35ce60142"
-
 [[package]]
 name = "unicode-ident"
 version = "1.0.24"
@@ -1505,12 +1459,6 @@ dependencies = [
  "wasm-bindgen",
 ]
 
-[[package]]
-name = "v_htmlescape"
-version = "0.15.8"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4e8257fbc510f0a46eb602c10215901938b5c2a7d5e70fc11483b1d3c9b5b18c"
-
 [[package]]
 name = "version_check"
 version = "0.9.5"

+ 0 - 1
Cargo.toml

@@ -4,7 +4,6 @@ version = "0.1.0"
 edition = "2024"
 
 [dependencies]
-actix-files = "0.6.10"
 actix-web = "4.14.0"
 awc = "3.8.2"
 dotenvy = "0.15.7"

+ 16 - 6
src/controllers/home.rs

@@ -1,9 +1,19 @@
-use actix_web::{Result, get};
-use actix_files::NamedFile;
-use std::path::PathBuf;
+use actix_web::{HttpResponse, web, get};
+use std::sync::Mutex;
+use crate::users::User;
+
+const HTML: &str = include_str!("../../ui/build.html");
 
 #[get("/")]
-pub async fn route() -> Result<NamedFile> {
-    let path: PathBuf = "./ui/build.html".into();
-    Ok(NamedFile::open(path)?)
+pub async fn route(users: web::Data<Mutex<Vec<User>>>) -> HttpResponse {
+    if users.lock().unwrap().is_empty() {
+        let updated_html = HTML.replacen(
+            "window.adminExists = true;",
+            "window.adminExists = false;",
+            1
+        );
+        HttpResponse::Ok().body(updated_html)
+    } else {
+        HttpResponse::Ok().body(HTML)
+    }
 }