diff options
| author | Joris Guyonvarch | 2026-01-01 18:29:11 +0100 |
|---|---|---|
| committer | Joris Guyonvarch | 2026-01-01 18:29:11 +0100 |
| commit | 12aba49b256d11a34c1472288e8a585be74928e1 (patch) | |
| tree | ee6a2c7849adb30202d852d8906884cb1497d554 /src/routes.rs | |
| parent | be94934ccd7d144cd30f6029941d5d835e29746d (diff) | |
Add page icon
https://uxwing.com/blank-file-icon/
Diffstat (limited to 'src/routes.rs')
| -rw-r--r-- | src/routes.rs | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/routes.rs b/src/routes.rs index ae97b7a..509f1b2 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -17,6 +17,10 @@ use crate::model; use crate::templates; use crate::util; +static MAIN_JS: &[u8] = include_bytes!("static/main.js"); +static MAIN_CSS: &[u8] = include_bytes!("static/main.css"); +static ICON_PNG: &[u8] = include_bytes!("static/icon.png"); + pub async fn routes( request: Request<Incoming>, db_conn: Connection, @@ -29,12 +33,12 @@ pub async fn routes( match (request.method(), path_parts) { (&Method::GET, []) => Ok(html(templates::INDEX)), - (&Method::GET, ["static", "main.js"]) => Ok(static_file( - include_str!("static/main.js"), - "application/javascript", - )), + (&Method::GET, ["static", "main.js"]) => + Ok(static_file(MAIN_JS, "application/javascript")), + (&Method::GET, ["static", "icon.png"]) => + Ok(static_file(ICON_PNG, "image/png")), (&Method::GET, ["static", "main.css"]) => { - Ok(static_file(include_str!("static/main.css"), "text/css")) + Ok(static_file(MAIN_CSS, "text/css")) } (&Method::POST, ["upload"]) => { upload_file(request, db_conn, authorized_key, files_dir).await @@ -146,15 +150,11 @@ async fn get( } fn static_file( - text: impl Into<String>, + content: &'static[u8], content_type: &str, ) -> Response<BoxBody<Bytes, std::io::Error>> { let response = Response::builder() - .body( - Full::new(text.into().into()) - .map_err(|e| match e {}) - .boxed(), - ) + .body(Full::new(content.into()).map_err(|e| match e {}).boxed()) .unwrap(); with_headers(response, vec![(CONTENT_TYPE, content_type)]) } |
