diff --git a/src/config.rs b/src/config.rs index ac0844b..e6c2d66 100644 --- a/src/config.rs +++ b/src/config.rs @@ -17,10 +17,26 @@ where var.parse().expect("Please set dotenv to valid value") } +fn env_opt(key: &str) -> Option +where + T: FromStr, + ::Err: Debug, +{ + env::var(key) + .ok() + .map(|var| var.parse().expect("Please set dotenv to valid value")) +} + #[derive(Debug, Deserialize)] pub struct Config { pub channels_config_url: String, pub transmission_url: String, + + pub download_dir: Option, + pub speed_limit_up: Option, + pub speed_limit_down: Option, + pub download_queue_size: Option, + pub seed_queue_size: Option, } impl Config { @@ -28,6 +44,12 @@ impl Config { Self { channels_config_url: env("CHANNELS_CONFIG_URL"), transmission_url: env("TRANSMISSION_URL"), + + download_dir: env_opt("DOWNLOAD_DIR"), + speed_limit_up: env_opt("SPEED_LIMIT_UP"), + speed_limit_down: env_opt("SPEED_LIMIT_DOWN"), + download_queue_size: env_opt("DOWNLOAD_QUEUE_SIZE"), + seed_queue_size: env_opt("SEED_QUEUE_SIZE"), } } } diff --git a/src/main.rs b/src/main.rs index c59c59d..966c1cd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,8 @@ use rss::Channel; use transmission_rpc::{ types::{ - Id, Torrent, TorrentAction, TorrentAddArgs, TorrentAddedOrDuplicate, TorrentGetField, - TorrentStatus, + Id, SessionSetArgs, Torrent, TorrentAction, TorrentAddArgs, TorrentAddedOrDuplicate, + TorrentGetField, TorrentStatus, }, TransClient, }; @@ -197,6 +197,26 @@ async fn run() { .expect("can't parse transmission url"), ); + let transmission_config = SessionSetArgs { + download_dir: config.download_dir, + speed_limit_up_enabled: config.speed_limit_up.is_some().then_some(true), + speed_limit_up: config.speed_limit_up, + speed_limit_down_enabled: config.speed_limit_down.is_some().then_some(true), + speed_limit_down: config.speed_limit_down, + download_queue_enabled: config.download_queue_size.is_some().then_some(true), + download_queue_size: config.download_queue_size, + seed_queue_enabled: config.seed_queue_size.is_some().then_some(true), + seed_queue_size: config.seed_queue_size, + ..Default::default() + }; + + println!("{:#?}", transmission_config); + + transmission + .session_set(transmission_config) + .await + .expect("can't set transmission configuration"); + let mut channels = Vec::new(); for channel_config in &channels_config { @@ -336,8 +356,6 @@ async fn run() { #[tokio::main] async fn main() { - println!("Hello, world!"); - dotenv::dotenv().ok(); run().await;