diff options
author | alyx <alyx@aleteoryx.me> | 2024-04-01 20:27:44 -0400 |
---|---|---|
committer | alyx <alyx@aleteoryx.me> | 2024-04-01 20:27:44 -0400 |
commit | 83ba4fe37a1184b998be09b9cbe53a22c7ba9e3b (patch) | |
tree | c60c2c17caeed24db920dee4613c1e185b12d12b /src/main.rs | |
parent | 22c2e4e2db9ad9d892ed5fb63d92254677f6dafd (diff) | |
download | lfm_embed-83ba4fe37a1184b998be09b9cbe53a22c7ba9e3b.tar.gz lfm_embed-83ba4fe37a1184b998be09b9cbe53a22c7ba9e3b.tar.bz2 lfm_embed-83ba4fe37a1184b998be09b9cbe53a22c7ba9e3b.zip |
Move caching to src/cache/; Finalize API parsing fixes
Font and user cache code has been moved to special files, independant from src/config.rs
API parsing changes have been properly tested, and last.fm API JSON is now trace-logged for debugging convenience.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/src/main.rs b/src/main.rs index cf7856a..38ee31f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,8 @@ use log::LevelFilter; use std::collections::BTreeMap; use std::fs::File; use std::sync::Arc; -use lfm_embed::{STATE, ResponseCtx}; -use lfm_embed::font::FontQuery; +use lfm_embed::{CONFIG, ResponseCtx}; +use lfm_embed::cache::font::FontQuery; use warp::Filter; #[derive(serde::Deserialize, Debug)] @@ -38,22 +38,20 @@ async fn main() { .unwrap_or(env_logger::Target::Stderr) ).init(); - std::sync::LazyLock::force(&STATE); - let user = warp::path!("user" / String) .and(warp::query::<UserQuery>()) .then(|s, q: UserQuery| async move { - log::debug!(target: "lfm::server::user", "Handling request for user `{s}` with {q:?}"); - let (ctx, dur) = STATE.get_userinfo(&s).await; + log::debug!(target: "lfm_embed::server::user", "Handling request for user `{s}` with {q:?}"); + 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| STATE.handlebars().has_template(a)).unwrap_or_else(|| STATE.default_theme()); - log::debug!(target: "lfm::server::user", "Using theme {theme}"); + let theme = q.theme.filter(|a| CONFIG.handlebars().has_template(a)).unwrap_or_else(|| CONFIG.default_theme()); + 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( - STATE.handlebars().render(&theme, &data).unwrap() + CONFIG.handlebars().render(&theme, &data).unwrap() ), status ), "Refresh", dur.as_secs() ), "X-Selected-Theme", theme.as_ref() @@ -61,5 +59,5 @@ async fn main() { }); warp::serve(user) - .bind(([127,0,0,1], STATE.port())).await; + .bind(([127,0,0,1], CONFIG.port())).await; } |