reifydb_sub_server_admin/
assets.rs1use std::{collections::HashMap, sync::OnceLock};
5
6pub struct EmbeddedFile {
7 pub content: &'static [u8],
8 pub mime_type: &'static str,
9}
10
11static EMBEDDED_FILES: OnceLock<HashMap<&'static str, EmbeddedFile>> = OnceLock::new();
12
13include!(concat!(env!("OUT_DIR"), "/webapp/asset_manifest.rs"));
14
15fn init_embedded_files() -> HashMap<&'static str, EmbeddedFile> {
16 let mut files = HashMap::new();
17
18 for (path, content, mime_type) in ASSETS {
19 files.insert(
20 *path,
21 EmbeddedFile {
22 content,
23 mime_type,
24 },
25 );
26 }
27
28 files
29}
30
31pub fn get_embedded_file(path: &str) -> Option<&'static EmbeddedFile> {
32 let files = EMBEDDED_FILES.get_or_init(init_embedded_files);
33
34 let path = path.strip_prefix('/').unwrap_or(path);
36
37 let path = if path.is_empty() {
39 "index.html"
40 } else {
41 path
42 };
43
44 let result = files.get(path);
45 if result.is_none() && path.starts_with("assets/") {
46 println!("File not found: '{}'. Available asset files:", path);
47 for key in files.keys() {
48 if key.starts_with("assets/") {
49 println!(" - {}", key);
50 }
51 }
52 }
53 result
54}