From 0ce64a50b763d2b19f5ca254233370418f4b7658 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Thu, 6 Feb 2025 16:52:46 +0100 Subject: add json capability to most useful endpoints --- server/src/routes/ui/mod.rs | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'server/src/routes/ui/mod.rs') 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 */ +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) -> MyResult>> { + 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<'_> { -- cgit v1.2.3-70-g09d2