diff --git a/config.toml b/config.toml index f7e3c9b..9161ad4 100644 --- a/config.toml +++ b/config.toml @@ -1,6 +1,7 @@ bind = "127.0.0.1:8085" item_tpl = "./assets/item.html" page_tpl = "./assets/index.html" +feeds_path = "./feeds/" [feeds.tc] url = "https://www.youtube.com/feeds/videos.xml?channel_id=UCy0tKL1T7wFoYcxCe0xjN6Q" diff --git a/src/main.rs b/src/main.rs index 455f01f..6209896 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,12 +3,13 @@ use reqwest; #[derive(Debug, Clone, serde::Deserialize)] struct FeedConfig { interval_secs: Option, - url: String + url: String, } #[derive(Debug, Clone, serde::Deserialize)] struct AppConfig { bind: String, + feeds_path: String, item_tpl: String, page_tpl: String, feeds: std::collections::HashMap @@ -23,7 +24,7 @@ struct AppState<'a> { fn read_config() -> anyhow::Result { let config_path = std::env::var("RSS_CONFIG").unwrap_or("./config.toml".into()); let cfg = std::fs::read_to_string(&config_path)?; - let mut cfg: AppConfig = toml::from_str(&cfg)?; + let cfg: AppConfig = toml::from_str(&cfg)?; Ok(cfg) } @@ -51,9 +52,9 @@ async fn file_needs_update( Ok(time.elapsed()?.as_secs() >= expiration_timeout.as_secs()) } -async fn get_rss(name: &str, cfg: &FeedConfig) -> anyhow::Result { +async fn get_rss(name: &str, cfg: &FeedConfig, feed_folder: &str) -> anyhow::Result { - let filename = std::path::PathBuf::from(format!("./feeds/{}.last_feed", name)); + let filename = std::path::PathBuf::from(format!("./{}/{}.last_feed", &feed_folder, name)); let data; if file_needs_update(&filename, std::time::Duration::from_secs(cfg.interval_secs.unwrap_or(0))).await.unwrap_or(true) { data = reqwest::get(cfg.url.clone()).await?.text().await?; @@ -71,7 +72,7 @@ async fn render_rss_feeds(axum::extract::State(state): axum::extract::State { res.push(format!("Error fetching feed: {}", &name)); log::error!("Error fetching feed: {}", e);