From 52aeff65a82d949dd3ce33d1a5998e00ad4c379e Mon Sep 17 00:00:00 2001 From: alyx Date: Tue, 2 Apr 2024 11:51:14 -0400 Subject: Theming refactor Theming has been broken off into a seperate space, so that it'll be easier to add lua support later. --- src/main.rs | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index d71f05c..dd31e58 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,17 +48,23 @@ async fn main() { let (ctx, dur) = lfm_embed::cache::user::get_userinfo(&s).await; let ResponseCtx(data, status) = ResponseCtx::create(ctx, q.font, q.rest).await; - let theme = q.theme.filter(|a| CONFIG.handlebars().has_template(a)).unwrap_or_else(|| CONFIG.default_theme()); + let (theme, res) = lfm_embed::theming::render_theme(q.theme.as_deref(), &data); log::debug!(target: "lfm_embed::server::user", "Using theme {theme}"); - warp::reply::with_header( - warp::reply::with_header( - warp::reply::with_status( - warp::reply::html( - CONFIG.handlebars().render(&theme, &data).unwrap() - ), status - ), "Refresh", dur.as_secs() - ), "X-Selected-Theme", theme.as_ref() - ) + match res { + Err(status) => + Box::new(warp::reply::with_status(warp::reply::html("

Internal Server Error.

"), status)) + as Box, + Ok(contents) => + Box::new(warp::reply::with_header( + warp::reply::with_header( + warp::reply::with_status( + warp::reply::html( + contents + ), status + ), "Refresh", dur.as_secs() + ), "X-Selected-Theme", theme + )) as Box + } }); warp::serve(user) -- cgit v1.2.3-54-g00ecf