Rename dlimit/download property to download_limit for consistency
This commit is contained in:
parent
31d9ec0b52
commit
14f24c9603
6 changed files with 40 additions and 37 deletions
|
@ -69,10 +69,6 @@ impl<'a> Params<'a> {
|
||||||
let sig = signature_encoded(key.auth_key().unwrap(), &self.nonce)
|
let sig = signature_encoded(key.auth_key().unwrap(), &self.nonce)
|
||||||
.map_err(|_| PrepareError::ComputeSignature)?;
|
.map_err(|_| PrepareError::ComputeSignature)?;
|
||||||
|
|
||||||
// TODO: can we remove this?
|
|
||||||
// // Derive a new authentication key
|
|
||||||
// key.derive_auth_password(self.password, &self.file.download_url(true));
|
|
||||||
|
|
||||||
// Wrap the parameters data
|
// Wrap the parameters data
|
||||||
let data = OwnedData::from(self.params.clone(), &self.file)
|
let data = OwnedData::from(self.params.clone(), &self.file)
|
||||||
.map_err(|err| -> PrepareError { err.into() })?;
|
.map_err(|err| -> PrepareError { err.into() })?;
|
||||||
|
@ -155,22 +151,22 @@ pub struct ParamsData {
|
||||||
/// The number of times this file may be downloaded.
|
/// The number of times this file may be downloaded.
|
||||||
/// This value must be in the `(0,20)` bounds, as enforced by Send servers.
|
/// This value must be in the `(0,20)` bounds, as enforced by Send servers.
|
||||||
#[serde(rename = "dlimit")]
|
#[serde(rename = "dlimit")]
|
||||||
downloads: Option<u8>,
|
download_limit: Option<u8>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ParamsData {
|
impl ParamsData {
|
||||||
/// Construct a new parameters object, that is empty.
|
/// Construct a new parameters object, that is empty.
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
ParamsData {
|
ParamsData {
|
||||||
downloads: None,
|
download_limit: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new parameters data object, with the given parameters.
|
/// Create a new parameters data object, with the given parameters.
|
||||||
// TODO: the downloads must be between bounds
|
// TODO: the downloads must be between bounds
|
||||||
pub fn from(downloads: Option<u8>) -> Self {
|
pub fn from(download_limit: Option<u8>) -> Self {
|
||||||
ParamsData {
|
ParamsData {
|
||||||
downloads,
|
download_limit,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,18 +178,18 @@ impl ParamsData {
|
||||||
/// An error may be returned if the download value is out of the allowed
|
/// An error may be returned if the download value is out of the allowed
|
||||||
/// bound. These bounds are fixed and enforced by the server.
|
/// bound. These bounds are fixed and enforced by the server.
|
||||||
/// See `PARAMS_DOWNLOAD_MIN` and `PARAMS_DOWNLOAD_MAX`.
|
/// See `PARAMS_DOWNLOAD_MIN` and `PARAMS_DOWNLOAD_MAX`.
|
||||||
pub fn set_downloads(&mut self, downloads: Option<u8>)
|
pub fn set_download_limit(&mut self, download_limit: Option<u8>)
|
||||||
-> Result<(), ParamsDataError>
|
-> Result<(), ParamsDataError>
|
||||||
{
|
{
|
||||||
// Check the download bounds
|
// Check the download limit bounds
|
||||||
if let Some(d) = downloads {
|
if let Some(d) = download_limit {
|
||||||
if d < PARAMS_DOWNLOAD_MIN || d > PARAMS_DOWNLOAD_MAX {
|
if d < PARAMS_DOWNLOAD_MIN || d > PARAMS_DOWNLOAD_MAX {
|
||||||
return Err(ParamsDataError::DownloadBounds);
|
return Err(ParamsDataError::DownloadBounds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the downloads
|
// Set the download limit
|
||||||
self.downloads = downloads;
|
self.download_limit = download_limit;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -201,14 +197,14 @@ impl ParamsData {
|
||||||
/// and wouldn't change any parameter on the server when sent.
|
/// and wouldn't change any parameter on the server when sent.
|
||||||
/// Sending an empty parameter data object would thus be useless.
|
/// Sending an empty parameter data object would thus be useless.
|
||||||
pub fn is_empty(&self) -> bool {
|
pub fn is_empty(&self) -> bool {
|
||||||
self.downloads.is_none()
|
self.download_limit.is_none()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ParamsData {
|
impl Default for ParamsData {
|
||||||
fn default() -> ParamsData {
|
fn default() -> ParamsData {
|
||||||
ParamsData {
|
ParamsData {
|
||||||
downloads: Some(PARAMS_DEFAULT_DOWNLOAD),
|
download_limit: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -486,7 +486,7 @@ pub enum UploadError {
|
||||||
#[fail(display = "Bad HTTP response '{}' while requesting file upload", _1)]
|
#[fail(display = "Bad HTTP response '{}' while requesting file upload", _1)]
|
||||||
RequestStatus(StatusCode, String),
|
RequestStatus(StatusCode, String),
|
||||||
|
|
||||||
/// Decoding the upload response from the server.
|
/// Failed to decode the upload response from the server.
|
||||||
/// Maybe the server responded with data from a newer API version.
|
/// Maybe the server responded with data from a newer API version.
|
||||||
#[fail(display = "Failed to decode upload response")]
|
#[fail(display = "Failed to decode upload response")]
|
||||||
Decode(#[cause] ReqwestError),
|
Decode(#[cause] ReqwestError),
|
||||||
|
|
|
@ -39,7 +39,7 @@ impl<'a> Params<'a> {
|
||||||
|
|
||||||
// Build the parameters data object
|
// Build the parameters data object
|
||||||
let data = ParamsDataBuilder::default()
|
let data = ParamsDataBuilder::default()
|
||||||
.downloads(self.cmd.downloads())
|
.download_limit(self.cmd.download_limit())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::path::Path;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
|
||||||
use failure::{err_msg, Fail};
|
use failure::{err_msg, Fail};
|
||||||
use ffsend_api::action::params::ParamsData;
|
use ffsend_api::action::params::ParamsDataBuilder;
|
||||||
use ffsend_api::action::upload::Upload as ApiUpload;
|
use ffsend_api::action::upload::Upload as ApiUpload;
|
||||||
use ffsend_api::reqwest::Client;
|
use ffsend_api::reqwest::Client;
|
||||||
|
|
||||||
|
@ -43,7 +43,7 @@ impl<'a> Upload<'a> {
|
||||||
let params = {
|
let params = {
|
||||||
// Build the parameters data object
|
// Build the parameters data object
|
||||||
let mut params = ParamsDataBuilder::default()
|
let mut params = ParamsDataBuilder::default()
|
||||||
.download(self.cmd.downloads())
|
.download_limit(self.cmd.download_limit())
|
||||||
.build()
|
.build()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ impl<'a: 'b, 'b> CmdParams<'a> {
|
||||||
/// Build the sub command definition.
|
/// Build the sub command definition.
|
||||||
pub fn build<'y, 'z>() -> App<'y, 'z> {
|
pub fn build<'y, 'z>() -> App<'y, 'z> {
|
||||||
// Build a list of data parameter arguments of which one is required
|
// Build a list of data parameter arguments of which one is required
|
||||||
let param_args = ["downloads"];
|
let param_args = ["download-limit"];
|
||||||
|
|
||||||
// Build the subcommand
|
// Build the subcommand
|
||||||
let cmd = SubCommand::with_name("parameters")
|
let cmd = SubCommand::with_name("parameters")
|
||||||
|
@ -38,12 +38,16 @@ impl<'a: 'b, 'b> CmdParams<'a> {
|
||||||
.alias("token")
|
.alias("token")
|
||||||
.value_name("TOKEN")
|
.value_name("TOKEN")
|
||||||
.help("File owner token"))
|
.help("File owner token"))
|
||||||
.arg(Arg::with_name("downloads")
|
.arg(Arg::with_name("download-limit")
|
||||||
.long("downloads")
|
.long("download-limit")
|
||||||
.short("d")
|
.short("d")
|
||||||
|
.alias("downloads")
|
||||||
.alias("download")
|
.alias("download")
|
||||||
.alias("down")
|
.alias("down")
|
||||||
.alias("dlimit")
|
.alias("dlimit")
|
||||||
|
.alias("limit")
|
||||||
|
.alias("lim")
|
||||||
|
.alias("l")
|
||||||
.required_unless_one(¶m_args)
|
.required_unless_one(¶m_args)
|
||||||
.value_name("COUNT")
|
.value_name("COUNT")
|
||||||
.help("Set the download limit parameter"));
|
.help("Set the download limit parameter"));
|
||||||
|
@ -94,17 +98,16 @@ impl<'a: 'b, 'b> CmdParams<'a> {
|
||||||
.map(|token| token.to_owned())
|
.map(|token| token.to_owned())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the download counts.
|
/// Get the download limit.
|
||||||
pub fn downloads(&'a self) -> Option<u8> {
|
pub fn download_limit(&'a self) -> Option<u8> {
|
||||||
// Get the number of downloads
|
|
||||||
// TODO: do not unwrap, report an error
|
// TODO: do not unwrap, report an error
|
||||||
self.matches.value_of("downloads")
|
self.matches.value_of("download-limit")
|
||||||
.map(|d| d.parse::<u8>().expect("invalid number of downloads"))
|
.map(|d| d.parse::<u8>().expect("invalid download limit"))
|
||||||
.and_then(|d| {
|
.and_then(|d| {
|
||||||
// Check the download count bounds
|
// Check the download limit bounds
|
||||||
if d < DOWNLOAD_MIN || d > DOWNLOAD_MAX {
|
if d < DOWNLOAD_MIN || d > DOWNLOAD_MAX {
|
||||||
panic!(
|
panic!(
|
||||||
"invalid number of downloads, must be between {} and {}",
|
"invalid download limit, must be between {} and {}",
|
||||||
DOWNLOAD_MIN,
|
DOWNLOAD_MIN,
|
||||||
DOWNLOAD_MAX,
|
DOWNLOAD_MAX,
|
||||||
);
|
);
|
||||||
|
|
|
@ -44,12 +44,16 @@ impl<'a: 'b, 'b> CmdUpload<'a> {
|
||||||
.min_values(0)
|
.min_values(0)
|
||||||
.max_values(1)
|
.max_values(1)
|
||||||
.help("Protect the file with a password"))
|
.help("Protect the file with a password"))
|
||||||
.arg(Arg::with_name("downloads")
|
.arg(Arg::with_name("downloads-limit")
|
||||||
.long("downloads")
|
.long("download-limit")
|
||||||
.short("d")
|
.short("d")
|
||||||
|
.alias("downloads")
|
||||||
.alias("download")
|
.alias("download")
|
||||||
.alias("down")
|
.alias("down")
|
||||||
.alias("dlimit")
|
.alias("dlimit")
|
||||||
|
.alias("limit")
|
||||||
|
.alias("lim")
|
||||||
|
.alias("l")
|
||||||
.value_name("COUNT")
|
.value_name("COUNT")
|
||||||
.default_value("1")
|
.default_value("1")
|
||||||
.help("Set the download limit"))
|
.help("Set the download limit"))
|
||||||
|
@ -169,17 +173,17 @@ impl<'a: 'b, 'b> CmdUpload<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the download limit if set.
|
/// Get the download limit if set.
|
||||||
pub fn downloads(&'a self) -> Option<u8> {
|
pub fn download_limit(&'a self) -> Option<u8> {
|
||||||
// Get the number of downloads, or none if not set or default
|
// Get the download limit, or None if not set or default
|
||||||
// TODO: do not unwrap, report an error
|
// TODO: do not unwrap, report an error
|
||||||
self.matches.value_of("downloads")
|
self.matches.value_of("download-limit")
|
||||||
.map(|d| d.parse::<u8>().expect("invalid number of downloads"))
|
.map(|d| d.parse::<u8>().expect("invalid download limit"))
|
||||||
.and_then(|d| if d == DOWNLOAD_DEFAULT { None } else { Some(d) })
|
.and_then(|d| if d == DOWNLOAD_DEFAULT { None } else { Some(d) })
|
||||||
.and_then(|d| {
|
.and_then(|d| {
|
||||||
// Check the download count bounds
|
// Check the download limit bounds
|
||||||
if d < DOWNLOAD_MIN || d > DOWNLOAD_MAX {
|
if d < DOWNLOAD_MIN || d > DOWNLOAD_MAX {
|
||||||
panic!(
|
panic!(
|
||||||
"invalid number of downloads, must be between {} and {}",
|
"invalid download limit, must be between {} and {}",
|
||||||
DOWNLOAD_MIN,
|
DOWNLOAD_MIN,
|
||||||
DOWNLOAD_MAX,
|
DOWNLOAD_MAX,
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue