aboutsummaryrefslogtreecommitdiff
path: root/server/src/routes/ui/mod.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-02-06 16:52:46 +0100
committermetamuffin <metamuffin@disroot.org>2025-02-06 16:52:46 +0100
commit0ce64a50b763d2b19f5ca254233370418f4b7658 (patch)
treefe1587d38c77180b0c7fa4911d416605e5d6c6e3 /server/src/routes/ui/mod.rs
parent87ebdede17007b626b1275c66dde1e5aefd6cddc (diff)
downloadjellything-0ce64a50b763d2b19f5ca254233370418f4b7658.tar
jellything-0ce64a50b763d2b19f5ca254233370418f4b7658.tar.bz2
jellything-0ce64a50b763d2b19f5ca254233370418f4b7658.tar.zst
add json capability to most useful endpoints
Diffstat (limited to 'server/src/routes/ui/mod.rs')
-rw-r--r--server/src/routes/ui/mod.rs31
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<'_> {