diff options
| author | Owen Jacobson <owen@grimoire.ca> | 2024-09-14 00:16:51 -0400 |
|---|---|---|
| committer | Owen Jacobson <owen@grimoire.ca> | 2024-09-14 00:18:08 -0400 |
| commit | 5249aad35741f6f029c442a04d679937fb91d2bb (patch) | |
| tree | c75085a93538367ae3f5da8f64f90b33a3c8feef /src/index/routes.rs | |
| parent | 407ca8df6284ce1a4c649b018c7326fd195bbd26 (diff) | |
Placeholder UX, probably
Diffstat (limited to 'src/index/routes.rs')
| -rw-r--r-- | src/index/routes.rs | 45 |
1 files changed, 42 insertions, 3 deletions
diff --git a/src/index/routes.rs b/src/index/routes.rs index c57278f..07b6001 100644 --- a/src/index/routes.rs +++ b/src/index/routes.rs @@ -1,8 +1,17 @@ -use axum::{extract::State, routing::get, Router}; +use axum::{ + extract::{Path, State}, + http::{header, StatusCode}, + response::IntoResponse, + routing::get, + Router, +}; use maud::Markup; use super::templates; -use crate::{app::App, error::InternalError, login::repo::logins::Login}; +use crate::{ + app::App, channel::repo::channels::Id as ChannelId, error::InternalError, + login::repo::logins::Login, +}; async fn index(State(app): State<App>, login: Option<Login>) -> Result<Markup, InternalError> { match login { @@ -17,6 +26,36 @@ async fn index_authenticated(app: App, login: Login) -> Result<Markup, InternalE Ok(templates::authenticated(login, &channels)) } +#[derive(rust_embed::Embed)] +#[folder = "js"] +struct Js; + +async fn js(Path(path): Path<String>) -> impl IntoResponse { + let mime = mime_guess::from_path(&path).first_or_octet_stream(); + + match Js::get(&path) { + Some(file) => ( + StatusCode::OK, + [(header::CONTENT_TYPE, mime.as_ref())], + file.data, + ) + .into_response(), + None => (StatusCode::NOT_FOUND, "").into_response(), + } +} + +async fn channel( + State(app): State<App>, + _: Login, + Path(channel): Path<ChannelId>, +) -> Result<Markup, InternalError> { + let channel = app.index().channel(channel).await?; + Ok(templates::channel(&channel)) +} + pub fn router() -> Router<App> { - Router::new().route("/", get(index)) + Router::new() + .route("/", get(index)) + .route("/js/*path", get(js)) + .route("/:channel", get(channel)) } |
