diff options
Diffstat (limited to 'server/src/ui/mod.rs')
-rw-r--r-- | server/src/ui/mod.rs | 89 |
1 files changed, 22 insertions, 67 deletions
diff --git a/server/src/ui/mod.rs b/server/src/ui/mod.rs index 6728b81..f59118e 100644 --- a/server/src/ui/mod.rs +++ b/server/src/ui/mod.rs @@ -3,27 +3,19 @@ which is licensed under the GNU Affero General Public License (version 3); see /COPYING. Copyright (C) 2025 metamuffin <metamuffin.org> */ -use crate::logic::session::Session; +use crate::locale::AcceptLanguage; use error::MyResult; use home::rocket_uri_macro_r_home; use jellybase::CONF; -use log::debug; +use jellylogic::session::Session; +use jellyui::{render_page, scaffold::RenderInfo, CustomPage}; use rocket::{ futures::FutureExt, get, - http::{ContentType, Header, Status}, - response::{self, Redirect, Responder}, - Either, Request, Response, -}; -use std::{ - collections::hash_map::DefaultHasher, - future::Future, - hash::{Hash, Hasher}, - io::Cursor, - os::unix::prelude::MetadataExt, - path::Path, - pin::Pin, + response::{content::RawHtml, Redirect}, + Either, }; +use std::{future::Future, pin::Pin}; use tokio::{ fs::{read_to_string, File}, io::AsyncRead, @@ -32,60 +24,36 @@ use tokio::{ pub mod account; pub mod admin; pub mod assets; -pub mod browser; pub mod error; pub mod home; +pub mod items; pub mod node; pub mod player; pub mod search; pub mod stats; pub mod style; -impl<'r, Main: Render> Responder<'r, 'static> for LayoutPage<Main> { - fn respond_to(self, req: &'r Request<'_>) -> response::Result<'static> { - // TODO blocking the event loop here. it seems like there is no other way to - // TODO offload this, since the guard references `req` which has a lifetime. - // TODO therefore we just block. that is fine since the database is somewhat fast. - let lang = lang_from_request(&req); - let session = block_on(req.guard::<Option<Session>>()).unwrap(); - let mut out = String::new(); - Scaffold { - main: self.content, - title: self.title, - class: &format!( - "{} theme-{:?}", - self.class.unwrap_or(""), - session - .as_ref() - .map(|s| s.user.theme) - .unwrap_or(Theme::Dark) - ), - session, - lang, - } - .render(&mut out) - .unwrap(); - - Response::build() - .header(ContentType::HTML) - .streamed_body(Cursor::new(out)) - .ok() - } -} - #[get("/")] -pub async fn r_index(sess: Option<Session>) -> MyResult<Either<Redirect, DynLayoutPage<'static>>> { +pub async fn r_index( + lang: AcceptLanguage, + sess: Option<Session>, +) -> MyResult<Either<Redirect, RawHtml<String>>> { + let AcceptLanguage(lang) = lang; 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) + Ok(Either::Right(RawHtml(render_page( + &CustomPage { + title: "Jellything".to_string(), + body: front, }, - ..Default::default() - })) + RenderInfo { + importing: false, + session: None, + }, + lang, + )))) } } @@ -94,19 +62,6 @@ pub async fn r_favicon() -> MyResult<File> { Ok(File::open(CONF.asset_path.join("favicon.ico")).await?) } -pub struct HtmlTemplate<'a>(pub markup::DynRender<'a>); - -impl<'r> Responder<'r, 'static> for HtmlTemplate<'_> { - fn respond_to(self, _req: &'r Request<'_>) -> response::Result<'static> { - let mut out = String::new(); - self.0.render(&mut out).unwrap(); - Response::build() - .header(ContentType::HTML) - .sized_body(out.len(), Cursor::new(out)) - .ok() - } -} - pub struct Defer(Pin<Box<dyn Future<Output = String> + Send>>); impl AsyncRead for Defer { |