diff options
author | alyx <alyx@aleteoryx.me> | 2024-04-02 11:51:14 -0400 |
---|---|---|
committer | alyx <alyx@aleteoryx.me> | 2024-04-02 11:51:14 -0400 |
commit | 52aeff65a82d949dd3ce33d1a5998e00ad4c379e (patch) | |
tree | 1f99b836c9faca0600a68f40817d240d02cf123e /src/main.rs | |
parent | 8c9125b4c48a08112549f1b9b411f8bfc0bd336f (diff) | |
download | lfm_embed-52aeff65a82d949dd3ce33d1a5998e00ad4c379e.tar.gz lfm_embed-52aeff65a82d949dd3ce33d1a5998e00ad4c379e.tar.bz2 lfm_embed-52aeff65a82d949dd3ce33d1a5998e00ad4c379e.zip |
Theming refactor
Theming has been broken off into a seperate space, so that it'll be easier to add lua support later.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 26 |
1 files changed, 16 insertions, 10 deletions
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("<h1>Internal Server Error.</h1>"), status)) + as Box<dyn warp::reply::Reply>, + 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<dyn warp::reply::Reply> + } }); warp::serve(user) |