From 5249aad35741f6f029c442a04d679937fb91d2bb Mon Sep 17 00:00:00 2001 From: Owen Jacobson Date: Sat, 14 Sep 2024 00:16:51 -0400 Subject: Placeholder UX, probably --- src/index/routes.rs | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'src/index/routes.rs') 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, login: Option) -> Result { match login { @@ -17,6 +26,36 @@ async fn index_authenticated(app: App, login: Login) -> Result) -> 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, + _: Login, + Path(channel): Path, +) -> Result { + let channel = app.index().channel(channel).await?; + Ok(templates::channel(&channel)) +} + pub fn router() -> Router { - Router::new().route("/", get(index)) + Router::new() + .route("/", get(index)) + .route("/js/*path", get(js)) + .route("/:channel", get(channel)) } -- cgit v1.2.3