aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authoralyx <alyx@aleteoryx.me>2023-08-10 20:45:01 -0400
committeralyx <alyx@aleteoryx.me>2023-08-10 20:45:01 -0400
commit9edafd94b00a73662d51824dbcba0a018e2140cf (patch)
tree3389bb7be8296ccfa1b287cb23ba4b45f35f1b2e /src/main.rs
parent0216a2a99ff28b1f5f102f52b7d980bbc4afc729 (diff)
downloadlfm_embed-9edafd94b00a73662d51824dbcba0a018e2140cf.tar.gz
lfm_embed-9edafd94b00a73662d51824dbcba0a018e2140cf.tar.bz2
lfm_embed-9edafd94b00a73662d51824dbcba0a018e2140cf.zip
Create plain theme, do some escaping, fix some busted envvars, document themes.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/main.rs b/src/main.rs
index 729482f..b787049 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -2,6 +2,7 @@
use dotenv::var;
use log::LevelFilter;
+use std::collections::BTreeMap;
use std::fs::File;
use std::sync::Arc;
use lfm_embed::{STATE, ResponseCtx};
@@ -10,7 +11,9 @@ use warp::Filter;
#[derive(serde::Deserialize, Debug)]
struct UserQuery {
#[serde(default)]
- theme: Option<Arc<str>>
+ theme: Option<Arc<str>>,
+ #[serde(flatten)]
+ rest: BTreeMap<String, String>
}
#[tokio::main]
@@ -35,17 +38,20 @@ async fn main() {
let user = warp::path!("user" / String)
.and(warp::query::<UserQuery>())
.then(|s, q: UserQuery| async move {
- log::info!(target: "lfm::server::user", "Handling request for user `{s}` with {q:?}");
+ log::debug!(target: "lfm::server::user", "Handling request for user `{s}` with {q:?}");
let (ctx, dur) = STATE.get_userinfo(&s).await;
- let ResponseCtx(data, status) = ctx.into();
-
- let theme = q.theme.unwrap_or_else(|| STATE.default_theme());
+ let ResponseCtx(mut data, status) = (ctx, q.rest).into();
+
+ let theme = q.theme.filter(|a| STATE.handlebars().has_template(&a)).unwrap_or_else(|| STATE.default_theme());
+ log::debug!(target: "lfm::server::user", "Using theme {theme}");
warp::reply::with_header(
- warp::reply::with_status(
- warp::reply::html(
- STATE.handlebars().render(&theme, &data).unwrap()
- ), status
- ), "Refresh", dur.as_secs()
+ warp::reply::with_header(
+ warp::reply::with_status(
+ warp::reply::html(
+ STATE.handlebars().render(&theme, &data).unwrap()
+ ), status
+ ), "Refresh", dur.as_secs()
+ ), "X-Selected-Theme", theme.as_ref()
)
});