aboutsummaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs21
1 files changed, 15 insertions, 6 deletions
diff --git a/src/config.rs b/src/config.rs
index aad298f..ab92108 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -11,17 +11,17 @@ use super::deserialize::{GetRecentTracks, GetUserInfo, Track, User};
use reqwest::{Client, StatusCode};
use dotenv::var;
use tokio::sync::RwLock;
-use handlebars::Handlebars;
+use handlebars::{Handlebars, handlebars_helper};
use duration_str as ds;
-static INTERNAL_THEMES: &[(&'static str, &'static str)] = &[("plain", "")];
+static INTERNAL_THEMES: &[(&'static str, &'static str)] = &[("plain", include_str!("themes/plain.hbs"))];
pub static STATE: LazyLock<Arc<State>> = LazyLock::new(|| {
State::new()
});
fn getter(username: &String) -> Pin<Box<(dyn Future<Output = Result<Arc<(User, Track)>, (StatusCode, &'static str)>> + Send + Sync)>> {
- let username = username.clone();
+ let username = urlencoding::encode(username.as_ref()).to_string();
Box::pin(async move {
let userreq = STATE.http.get(format!("https://ws.audioscrobbler.com/2.0/?method=user.getInfo&format=json&user={username}&api_key={}", STATE.api_key))
.send().await
@@ -84,6 +84,15 @@ impl State {
handlebars: {
let mut hb = Handlebars::new();
+
+ handlebars_helper!(html_escape: |s: String| htmlize::escape_text(s));
+ handlebars_helper!(html_attr_escape: |s: String| htmlize::escape_attribute(s));
+ handlebars_helper!(url_encode: |s: String| urlencoding::encode(&s));
+
+ hb.register_helper("html-escape", Box::new(html_escape));
+ hb.register_helper("html-attr-escape", Box::new(html_attr_escape));
+ hb.register_helper("url-encode", Box::new(html_attr_escape));
+
for (key, fulltext) in INTERNAL_THEMES {
log::info!(target: "lfm::config::theme", "Registering internal theme `{key}`");
hb.register_template_string(key, fulltext).unwrap();
@@ -92,7 +101,7 @@ impl State {
if let Ok(themes_dir) = var("LFME_THEME_DIR") {
log::info!(target: "lfm::config::theme", "Registering theme dir `{themes_dir}`");
- hb.register_templates_directory(&var("LFME_THEME_EXT").unwrap_or_else(|_| "hbs".into()), themes_dir).unwrap();
+ hb.register_templates_directory(&var("LFME_THEME_EXT").unwrap_or_else(|_| ".hbs".into()), themes_dir).unwrap();
}
hb
@@ -118,8 +127,8 @@ impl State {
}
}
},
- default_refresh: default_refresh + Duration::from_secs(5),
- whitelist_refresh: whitelist_refresh + Duration::from_secs(5)
+ default_refresh: default_refresh + Duration::from_secs(1),
+ whitelist_refresh: whitelist_refresh + Duration::from_secs(1)
})
}