diff options
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) |