From 553d3b7a78f9318fc81555823b1dc669b873e5d2 Mon Sep 17 00:00:00 2001 From: Ryan Aidan Date: Sun, 30 Jun 2024 18:10:14 +0800 Subject: [PATCH] fix: prepend urls starting with www with https (#45) --- rm-main/src/cli.rs | 5 +++++ rm-main/src/transmission/action.rs | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/rm-main/src/cli.rs b/rm-main/src/cli.rs index 158af8e..9760132 100644 --- a/rm-main/src/cli.rs +++ b/rm-main/src/cli.rs @@ -38,6 +38,11 @@ async fn add_torrent(config: &Config, torrent: String) -> Result<()> { filename: Some(torrent), ..Default::default() } + } else if torrent.starts_with("www") { + TorrentAddArgs { + filename: Some(format!("https://{torrent}")), + ..Default::default() + } } else { let mut torrent_file = File::open(torrent)?; let mut buf = vec![]; diff --git a/rm-main/src/transmission/action.rs b/rm-main/src/transmission/action.rs index 6d49760..f0886e7 100644 --- a/rm-main/src/transmission/action.rs +++ b/rm-main/src/transmission/action.rs @@ -25,8 +25,15 @@ pub async fn action_handler(ctx: app::Ctx, mut trans_rx: UnboundedReceiver { + let formatted = { + if url.starts_with("www") { + format!("https://{url}") + } else { + url.to_string() + } + }; let args = TorrentAddArgs { - filename: Some(url.clone()), + filename: Some(formatted), download_dir: directory, ..Default::default() };