| d23464c0 Andy McCall ↶ |
1 |
|
| 2 |
|
| 3 |
use axum::extract::Path; |
| 4 |
use axum::http::{header, StatusCode}; |
| 5 |
use axum::response::{IntoResponse, Response}; |
| 6 |
|
| 7 |
const CSS: &str = include_str!("../../../../templates/style.css"); |
| 8 |
const FAVICON: &str = include_str!("../../../../assets/icons/oxygenhub.svg"); |
| 9 |
|
| 8e820b4a Andy McCall ↶ |
10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
pub fn assets_version() -> &'static str { |
| 15 |
static V: std::sync::OnceLock<String> = std::sync::OnceLock::new(); |
| 16 |
V.get_or_init(|| { |
| 17 |
let mut h = blake3::Hasher::new(); |
| 18 |
h.update(CSS.as_bytes()); |
| 17ca6cdd Andy McCall ↶ |
19 |
for a in ASSETS.iter().filter(|a| { |
| 20 |
matches!( |
| 21 |
a.path, |
| a7aa76ac Andy McCall |
22 |
"github.css" |
| 23 |
| "hub.js" |
| 24 |
| "early.js" |
| 25 |
| "pulse.js" |
| 26 |
| "backdrop-boot.js" |
| 27 |
| "report-frame.js" |
| 28 |
| "report.css" |
| 29 |
| "backdrop/backdrop.js" |
| 30 |
| "backdrop/backdrop_bg.wasm" |
| 17ca6cdd Andy McCall ↶ |
31 |
) |
| 32 |
}) { |
| 8e820b4a Andy McCall ↶ |
33 |
h.update(a.bytes); |
| 34 |
} |
| 35 |
h.finalize().to_hex()[..12].to_string() |
| 36 |
}) |
| 37 |
} |
| 38 |
|
| d23464c0 Andy McCall ↶ |
39 |
struct Asset { |
| 40 |
path: &'static str, |
| 41 |
mime: &'static str, |
| 42 |
bytes: &'static [u8], |
| 43 |
} |
| 44 |
|
| 45 |
const ASSETS: &[Asset] = &[ |
| 46 |
Asset { path: "fonts/Barlow-300.woff2", mime: "font/woff2", bytes: include_bytes!("../../../../assets/fonts/Barlow-300.woff2") }, |
| 47 |
Asset { path: "fonts/Barlow-400.woff2", mime: "font/woff2", bytes: include_bytes!("../../../../assets/fonts/Barlow-400.woff2") }, |
| 48 |
Asset { path: "fonts/Barlow-500.woff2", mime: "font/woff2", bytes: include_bytes!("../../../../assets/fonts/Barlow-500.woff2") }, |
| 49 |
Asset { path: "fonts/Barlow-600.woff2", mime: "font/woff2", bytes: include_bytes!("../../../../assets/fonts/Barlow-600.woff2") }, |
| 50 |
Asset { |
| 51 |
path: "fonts/PressStart2P-400.woff2", |
| 52 |
mime: "font/woff2", |
| 53 |
bytes: include_bytes!("../../../../assets/fonts/PressStart2P-400.woff2"), |
| 54 |
}, |
| 749d9a5f Andy McCall ↶ |
55 |
Asset { path: "github.css", mime: "text/css; charset=utf-8", bytes: include_bytes!("../../../../assets/github.css") }, |
| d23464c0 Andy McCall ↶ |
56 |
Asset { path: "hub.js", mime: "text/javascript; charset=utf-8", bytes: include_bytes!("../../../../assets/hub.js") }, |
| a7aa76ac Andy McCall |
57 |
|
| 58 |
|
| 59 |
Asset { path: "early.js", mime: "text/javascript; charset=utf-8", bytes: include_bytes!("../../../../assets/early.js") }, |
| 60 |
Asset { path: "pulse.js", mime: "text/javascript; charset=utf-8", bytes: include_bytes!("../../../../assets/pulse.js") }, |
| 61 |
Asset { |
| 62 |
path: "backdrop-boot.js", |
| 63 |
mime: "text/javascript; charset=utf-8", |
| 64 |
bytes: include_bytes!("../../../../assets/backdrop-boot.js"), |
| 65 |
}, |
| f3e5e2bc Andy McCall ↶ |
66 |
|
| 67 |
|
| 68 |
Asset { path: "report-frame.js", mime: "text/javascript; charset=utf-8", bytes: include_bytes!("../../../../assets/report-frame.js") }, |
| 69 |
Asset { path: "report.css", mime: "text/css; charset=utf-8", bytes: include_bytes!("../../../../assets/report.css") }, |
| 17ca6cdd Andy McCall ↶ |
70 |
|
| 71 |
|
| 72 |
|
| 14530604 Andy McCall ↶ |
73 |
Asset { |
| 17ca6cdd Andy McCall ↶ |
74 |
path: "backdrop/backdrop.js", |
| 75 |
mime: "text/javascript; charset=utf-8", |
| 76 |
bytes: include_bytes!("../../../../assets/backdrop/backdrop.js"), |
| 77 |
}, |
| 78 |
Asset { |
| 79 |
path: "backdrop/backdrop_bg.wasm", |
| 80 |
mime: "application/wasm", |
| 81 |
bytes: include_bytes!("../../../../assets/backdrop/backdrop_bg.wasm"), |
| 82 |
}, |
| 83 |
Asset { |
| 14530604 Andy McCall ↶ |
84 |
path: "vendor/editor.js", |
| 85 |
mime: "text/javascript; charset=utf-8", |
| 86 |
bytes: include_bytes!("../../../../assets/vendor/editor.js"), |
| 87 |
}, |
| 88 |
Asset { |
| 89 |
path: "vendor/easymde.min.js", |
| 90 |
mime: "text/javascript; charset=utf-8", |
| 91 |
bytes: include_bytes!("../../../../assets/vendor/easymde.min.js"), |
| 92 |
}, |
| 84751769 Andy McCall ↶ |
93 |
|
| 94 |
|
| 95 |
|
| 14530604 Andy McCall ↶ |
96 |
Asset { |
| 84751769 Andy McCall ↶ |
97 |
path: "vendor/mermaid.min.js", |
| 98 |
mime: "text/javascript; charset=utf-8", |
| 99 |
bytes: include_bytes!("../../../../assets/vendor/mermaid.min.js"), |
| 100 |
}, |
| c26267b3 Andy McCall ↶ |
101 |
Asset { path: "wasi-worker.js", mime: "text/javascript; charset=utf-8", bytes: include_bytes!("../../../../assets/wasi-worker.js") }, |
| 102 |
Asset { path: "wasm-tab.js", mime: "text/javascript; charset=utf-8", bytes: include_bytes!("../../../../assets/wasm-tab.js") }, |
| 84751769 Andy McCall ↶ |
103 |
Asset { |
| 14530604 Andy McCall ↶ |
104 |
path: "vendor/easymde.min.css", |
| 105 |
mime: "text/css; charset=utf-8", |
| 106 |
bytes: include_bytes!("../../../../assets/vendor/easymde.min.css"), |
| 107 |
}, |
| d23464c0 Andy McCall ↶ |
108 |
]; |
| 109 |
|
| 110 |
const CACHE: &str = "public, max-age=86400"; |
| 111 |
|
| 112 |
pub async fn style() -> Response { |
| 113 |
([(header::CONTENT_TYPE, "text/css; charset=utf-8"), (header::CACHE_CONTROL, CACHE)], CSS).into_response() |
| 114 |
} |
| 115 |
|
| 116 |
pub async fn favicon() -> Response { |
| 117 |
([(header::CONTENT_TYPE, "image/svg+xml"), (header::CACHE_CONTROL, CACHE)], FAVICON).into_response() |
| 118 |
} |
| 119 |
|
| 120 |
pub async fn asset(Path(path): Path<String>) -> Response { |
| 121 |
match ASSETS.iter().find(|a| a.path == path) { |
| f3e5e2bc Andy McCall ↶ |
122 |
|
| 123 |
|
| 124 |
Some(a) => ( |
| 125 |
[ |
| 126 |
(header::CONTENT_TYPE, a.mime), |
| 127 |
(header::CACHE_CONTROL, "public, max-age=31536000, immutable"), |
| 128 |
(header::ACCESS_CONTROL_ALLOW_ORIGIN, "*"), |
| 129 |
], |
| 130 |
a.bytes, |
| 131 |
) |
| 132 |
.into_response(), |
| d23464c0 Andy McCall ↶ |
133 |
None => StatusCode::NOT_FOUND.into_response(), |
| 134 |
} |
| 135 |
} |