diff --git a/src/action/params.rs b/src/action/params.rs index cf0d707..675cc66 100644 --- a/src/action/params.rs +++ b/src/action/params.rs @@ -2,6 +2,7 @@ use clap::ArgMatches; use ffsend_api::action::params::{Error as ParamsError, Params as ApiParams, ParamsDataBuilder}; use ffsend_api::file::remote_file::RemoteFile; +use super::select_api_version; use crate::client::create_config; use crate::cmd::matcher::{main::MainMatcher, params::ParamsMatcher, Matcher}; use crate::error::ActionError; @@ -27,13 +28,23 @@ impl<'a> Params<'a> { let matcher_main = MainMatcher::with(self.cmd_matches).unwrap(); let matcher_params = ParamsMatcher::with(self.cmd_matches).unwrap(); - // Get the share URL + // Get the share URL and the host + // TODO: derive host through helper function let url = matcher_params.url(); + let mut host = url.clone(); + host.set_path(""); + host.set_query(None); + host.set_fragment(None); // Create a reqwest client let client_config = create_config(&matcher_main); let client = client_config.client(false); + // Determine the API version to use + let mut desired_version = matcher_main.api(); + select_api_version(&client, host, &mut desired_version)?; + let api_version = desired_version.version().unwrap(); + // Parse the remote file based on the share URL, derive the owner token from history let mut file = RemoteFile::parse_url(url, matcher_params.owner())?; #[cfg(feature = "history")] @@ -42,9 +53,16 @@ impl<'a> Params<'a> { // Ensure the owner token is set ensure_owner_token(file.owner_token_mut(), &matcher_main, false); + // We don't authenticate for now + let auth = false; + // Build the parameters data object let data = ParamsDataBuilder::default() - .download_limit(matcher_params.download_limit().map(|d| d as u8)) + .download_limit( + matcher_params + .download_limit(&matcher_main, api_version, auth) + .map(|d| d as u8), + ) .build() .unwrap(); diff --git a/src/cmd/matcher/params.rs b/src/cmd/matcher/params.rs index 00ab481..795220a 100644 --- a/src/cmd/matcher/params.rs +++ b/src/cmd/matcher/params.rs @@ -1,8 +1,12 @@ use clap::ArgMatches; +use ffsend_api::api::Version as ApiVersion; use ffsend_api::url::Url; use super::Matcher; -use crate::cmd::arg::{ArgDownloadLimit, ArgOwner, ArgUrl, CmdArgOption}; +use crate::cmd::{ + arg::{ArgDownloadLimit, ArgOwner, ArgUrl, CmdArgOption}, + matcher::MainMatcher, +}; /// The params command matcher. pub struct ParamsMatcher<'a> { @@ -26,8 +30,16 @@ impl<'a: 'b, 'b> ParamsMatcher<'a> { } /// Get the download limit. - pub fn download_limit(&'a self) -> Option { - ArgDownloadLimit::value(self.matches) + /// + /// If the download limit was the default, `None` is returned to not + /// explicitly set it. + pub fn download_limit( + &'a self, + main_matcher: &MainMatcher, + api_version: ApiVersion, + auth: bool, + ) -> Option { + ArgDownloadLimit::value_checked(self.matches, main_matcher, api_version, auth) } }