From 6d081731599db962420dc5cc2b63ac3bfccfbab7 Mon Sep 17 00:00:00 2001 From: Ivan Date: Sat, 19 Oct 2024 19:47:57 +0200 Subject: [PATCH 1/2] Add parameter for remote server to download client --- crates/rqbit/src/main.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/rqbit/src/main.rs b/crates/rqbit/src/main.rs index e2c67f0..8a60cab 100644 --- a/crates/rqbit/src/main.rs +++ b/crates/rqbit/src/main.rs @@ -301,6 +301,10 @@ struct DownloadOpts { #[arg(long = "initial-peers")] initial_peers: Option, + + + #[arg(long = "server-url")] + server_url: Option, } #[derive(Clone)] @@ -634,7 +638,7 @@ async fn async_main(opts: Opts, cancel: CancellationToken) -> anyhow::Result<()> if download_opts.torrent_path.is_empty() { anyhow::bail!("you must provide at least one URL to download") } - let http_api_url = format!("http://{}", opts.http_api_listen_addr); + let http_api_url = download_opts.server_url.clone().unwrap_or_else(|| format!("http://{}", opts.http_api_listen_addr)); let client = http_api_client::HttpApiClient::new(&http_api_url)?; let torrent_opts = |with_output_folder: bool| AddTorrentOptions { @@ -662,6 +666,10 @@ async fn async_main(opts: Opts, cancel: CancellationToken) -> anyhow::Result<()> false } }; + if !connect_to_existing && download_opts.server_url.is_some() { + anyhow::bail!("cannot connect to server at {}", client.base_url()); + + } if connect_to_existing { for torrent_url in &download_opts.torrent_path { match client From bac364760e6c83fb24bd109ee64a00a7fcaa2646 Mon Sep 17 00:00:00 2001 From: Ivan Date: Sat, 19 Oct 2024 19:50:26 +0200 Subject: [PATCH 2/2] fmt --- crates/librqbit/src/session.rs | 4 +++- crates/rqbit/src/main.rs | 7 ++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/librqbit/src/session.rs b/crates/librqbit/src/session.rs index 579e6da..a8305da 100644 --- a/crates/librqbit/src/session.rs +++ b/crates/librqbit/src/session.rs @@ -1365,7 +1365,9 @@ impl Session { } pub async fn pause(&self, handle: &ManagedTorrentHandle) -> anyhow::Result<()> { - handle.pause().map(|_| handle.locked.write().paused = true)?; + handle + .pause() + .map(|_| handle.locked.write().paused = true)?; self.try_update_persistence_metadata(handle).await; Ok(()) } diff --git a/crates/rqbit/src/main.rs b/crates/rqbit/src/main.rs index 8a60cab..ebefde8 100644 --- a/crates/rqbit/src/main.rs +++ b/crates/rqbit/src/main.rs @@ -302,7 +302,6 @@ struct DownloadOpts { #[arg(long = "initial-peers")] initial_peers: Option, - #[arg(long = "server-url")] server_url: Option, } @@ -638,7 +637,10 @@ async fn async_main(opts: Opts, cancel: CancellationToken) -> anyhow::Result<()> if download_opts.torrent_path.is_empty() { anyhow::bail!("you must provide at least one URL to download") } - let http_api_url = download_opts.server_url.clone().unwrap_or_else(|| format!("http://{}", opts.http_api_listen_addr)); + let http_api_url = download_opts + .server_url + .clone() + .unwrap_or_else(|| format!("http://{}", opts.http_api_listen_addr)); let client = http_api_client::HttpApiClient::new(&http_api_url)?; let torrent_opts = |with_output_folder: bool| AddTorrentOptions { @@ -668,7 +670,6 @@ async fn async_main(opts: Opts, cancel: CancellationToken) -> anyhow::Result<()> }; if !connect_to_existing && download_opts.server_url.is_some() { anyhow::bail!("cannot connect to server at {}", client.base_url()); - } if connect_to_existing { for torrent_url in &download_opts.torrent_path {