Respect download limits enforced by remote server, update ffsend-api

See issue timvisee/ffsend#17
This commit is contained in:
timvisee 2019-04-05 16:54:34 +02:00
parent b59650f25d
commit 888b10afd6
No known key found for this signature in database
GPG key ID: B8DB720BC383E172
7 changed files with 145 additions and 77 deletions

View file

@ -1,10 +1,12 @@
use clap::ArgMatches;
use ffsend_api::action::params::PARAMS_DEFAULT_DOWNLOAD as DOWNLOAD_DEFAULT;
use ffsend_api::api::Version as ApiVersion;
use ffsend_api::url::Url;
use super::Matcher;
use crate::cmd::arg::{
ArgDownloadLimit, ArgGenPassphrase, ArgHost, ArgPassword, CmdArgFlag, CmdArgOption,
use crate::cmd::{
arg::{ArgDownloadLimit, ArgGenPassphrase, ArgHost, ArgPassword, CmdArgFlag, CmdArgOption},
matcher::MainMatcher,
};
use crate::util::{bin_name, env_var_present, quit_error_msg, ErrorHintsBuilder};
@ -73,13 +75,21 @@ impl<'a: 'b, 'b> UploadMatcher<'a> {
}
/// Get the download limit.
///
/// If the download limit was the default, `None` is returned to not
/// explicitly set it.
pub fn download_limit(&'a self) -> Option<u8> {
ArgDownloadLimit::value(self.matches).and_then(|d| match d {
DOWNLOAD_DEFAULT => None,
d => Some(d),
})
pub fn download_limit(
&'a self,
main_matcher: &MainMatcher,
api_version: ApiVersion,
auth: bool,
) -> Option<usize> {
ArgDownloadLimit::value_checked(self.matches, main_matcher, api_version, auth).and_then(
|d| match d {
d if d == DOWNLOAD_DEFAULT as usize => None,
d => Some(d),
},
)
}
/// Check whether to archive the file to upload.