From 2c64e5318654204265f0d555900ab0657ffc8f32 Mon Sep 17 00:00:00 2001 From: aidanaden Date: Thu, 27 Jun 2024 13:51:11 +0800 Subject: [PATCH] fix: prepend urls starting with www with https --- 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() };