diff options
author | Vika <vika@fireburn.ru> | 2025-04-20 09:07:49 +0300 |
---|---|---|
committer | Vika <vika@fireburn.ru> | 2025-04-20 10:00:17 +0300 |
commit | b3288627d171fff9a289a56a4ae27307985f9f96 (patch) | |
tree | e691caf5c647bef16aff2b5e15cc19b8523f409b /templates/src/lib.rs | |
parent | 6f85c8520180d7f875457896a2b6fbf91f6d81e2 (diff) | |
download | kittybox-b3288627d171fff9a289a56a4ae27307985f9f96.tar.zst |
kittybox-frontend-renderer: factor out the `assets` module into a file
Change-Id: I6138cfe8479ba8df9a1580049675c1dd84abdad1
Diffstat (limited to 'templates/src/lib.rs')
-rw-r--r-- | templates/src/lib.rs | 54 |
1 files changed, 1 insertions, 53 deletions
diff --git a/templates/src/lib.rs b/templates/src/lib.rs index fde0dab..0f9f7c6 100644 --- a/templates/src/lib.rs +++ b/templates/src/lib.rs @@ -8,60 +8,8 @@ mod login; pub use login::{LoginPage, LogoutPage}; mod mf2; pub use mf2::{Entry, Feed, Food, VCard, POSTS_PER_PAGE}; - pub mod admin; - -pub mod assets { - use axum::extract::Path; - use axum::http::header::{ - CACHE_CONTROL, CONTENT_ENCODING, CONTENT_TYPE, X_CONTENT_TYPE_OPTIONS, - }; - use axum::http::StatusCode; - use axum::response::{IntoResponse, Response}; - - const ASSETS: include_dir::Dir<'static> = include_dir::include_dir!("$OUT_DIR/"); - const CACHE_FOR_A_DAY: &str = "max-age=86400"; - const GZIP: &str = "gzip"; - - pub async fn statics(Path(path): Path<String>) -> Response { - let content_type: &'static str = if path.ends_with(".js") { - "application/javascript" - } else if path.ends_with(".css") { - "text/css" - } else if path.ends_with(".html") { - "text/html; charset=\"utf-8\"" - } else { - "application/octet-stream" - }; - - match ASSETS.get_file(path.clone() + ".gz") { - Some(file) => ( - StatusCode::OK, - [ - (CONTENT_TYPE, content_type), - (CONTENT_ENCODING, GZIP), - (CACHE_CONTROL, CACHE_FOR_A_DAY), - (X_CONTENT_TYPE_OPTIONS, "nosniff"), - ], - file.contents(), - ) - .into_response(), - None => match ASSETS.get_file(path) { - Some(file) => ( - StatusCode::OK, - [ - (CONTENT_TYPE, content_type), - (CACHE_CONTROL, CACHE_FOR_A_DAY), - (X_CONTENT_TYPE_OPTIONS, "nosniff"), - ], - file.contents(), - ) - .into_response(), - None => StatusCode::NOT_FOUND.into_response(), - }, - } - } -} +pub mod assets; #[cfg(test)] mod tests { |