mirror of
https://github.com/timvisee/ffsend.git
synced 2025-10-06 02:29:57 +02:00
Make timeout configurable
This commit is contained in:
parent
0054daadff
commit
f693ff42d3
12 changed files with 99 additions and 22 deletions
|
@ -2,20 +2,20 @@ use std::time::Duration;
|
|||
|
||||
use ffsend_api::reqwest::{Client, ClientBuilder};
|
||||
|
||||
use config::{CLIENT_TIMEOUT, CLIENT_TRANSFER_TIMEOUT};
|
||||
use cmd::matcher::MainMatcher;
|
||||
|
||||
/// Create the default client, which is used for generic Send requests.
|
||||
///
|
||||
/// Note: use `create_transfer_client()` instead for clients that upload/download.
|
||||
pub fn create_client() -> Client {
|
||||
create_custom_client(CLIENT_TIMEOUT)
|
||||
pub fn create_client(matcher_main: &MainMatcher) -> Client {
|
||||
create_custom_client(to_duration(matcher_main.timeout()))
|
||||
}
|
||||
|
||||
/// Create the default client, which is used for generic Send requests.
|
||||
///
|
||||
/// Note: use `create_transfer_client()` instead for clients that upload/download.
|
||||
pub fn create_transfer_client() -> Client {
|
||||
create_custom_client(CLIENT_TRANSFER_TIMEOUT)
|
||||
pub fn create_transfer_client(matcher_main: &MainMatcher) -> Client {
|
||||
create_custom_client(to_duration(matcher_main.transfer_timeout()))
|
||||
}
|
||||
|
||||
/// Create the Send client with a custom timeout.
|
||||
|
@ -25,3 +25,12 @@ fn create_custom_client(timeout: Option<Duration>) -> Client {
|
|||
.build()
|
||||
.expect("failed to build custom reqwest client")
|
||||
}
|
||||
|
||||
/// Convert the given number of seconds into an optional duration, used for clients.
|
||||
fn to_duration(secs: u64) -> Option<Duration> {
|
||||
if secs > 0 {
|
||||
Some(Duration::from_secs(secs))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue