From 83ba4fe37a1184b998be09b9cbe53a22c7ba9e3b Mon Sep 17 00:00:00 2001 From: alyx Date: Mon, 1 Apr 2024 20:27:44 -0400 Subject: 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. --- src/main.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/main.rs') 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::()) .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; } -- cgit v1.2.3-54-g00ecf