diff options
Diffstat (limited to 'server/src/routes/ui/mod.rs')
-rw-r--r-- | server/src/routes/ui/mod.rs | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/server/src/routes/ui/mod.rs b/server/src/routes/ui/mod.rs index 812e2d1..bffdfdd 100644 --- a/server/src/routes/ui/mod.rs +++ b/server/src/routes/ui/mod.rs @@ -3,13 +3,19 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2025 metamuffin <metamuffin.org> */ +use account::session::Session; +use error::MyResult; +use home::rocket_uri_macro_r_home; +use jellybase::CONF; +use layout::{DynLayoutPage, LayoutPage}; use log::debug; use markup::Render; use rocket::{ futures::FutureExt, + get, http::{ContentType, Header, Status}, - response::{self, Responder}, - Request, Response, + response::{self, Redirect, Responder}, + Either, Request, Response, }; use std::{ collections::hash_map::DefaultHasher, @@ -20,7 +26,10 @@ use std::{ path::Path, pin::Pin, }; -use tokio::{fs::File, io::AsyncRead}; +use tokio::{ + fs::{read_to_string, File}, + io::AsyncRead, +}; pub mod account; pub mod admin; @@ -35,6 +44,22 @@ pub mod search; pub mod sort; pub mod style; +#[get("/")] +pub async fn r_index(sess: Option<Session>) -> MyResult<Either<Redirect, DynLayoutPage<'static>>> { + if sess.is_some() { + Ok(Either::Left(Redirect::temporary(rocket::uri!(r_home())))) + } else { + let front = read_to_string(CONF.asset_path.join("front.htm")).await?; + Ok(Either::Right(LayoutPage { + title: "Home".to_string(), + content: markup::new! { + @markup::raw(&front) + }, + ..Default::default() + })) + } +} + pub struct HtmlTemplate<'a>(pub markup::DynRender<'a>); impl<'r> Responder<'r, 'static> for HtmlTemplate<'_> { |