Rename dlimit/download property to download_limit for consistency

This commit is contained in:
timvisee 2018-04-02 14:03:58 +02:00
parent 31d9ec0b52
commit 14f24c9603
No known key found for this signature in database
GPG key ID: 109CBA0BF74036C2
6 changed files with 40 additions and 37 deletions

View file

@ -69,10 +69,6 @@ impl<'a> Params<'a> {
let sig = signature_encoded(key.auth_key().unwrap(), &self.nonce)
.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
let data = OwnedData::from(self.params.clone(), &self.file)
.map_err(|err| -> PrepareError { err.into() })?;
@ -155,22 +151,22 @@ pub struct ParamsData {
/// The number of times this file may be downloaded.
/// This value must be in the `(0,20)` bounds, as enforced by Send servers.
#[serde(rename = "dlimit")]
downloads: Option<u8>,
download_limit: Option<u8>,
}
impl ParamsData {
/// Construct a new parameters object, that is empty.
pub fn new() -> Self {
ParamsData {
downloads: None,
download_limit: None,
}
}
/// Create a new parameters data object, with the given parameters.
// TODO: the downloads must be between bounds
pub fn from(downloads: Option<u8>) -> Self {
pub fn from(download_limit: Option<u8>) -> Self {
ParamsData {
downloads,
download_limit,
}
}
@ -182,18 +178,18 @@ impl ParamsData {
/// An error may be returned if the download value is out of the allowed
/// bound. These bounds are fixed and enforced by the server.
/// 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>
{
// Check the download bounds
if let Some(d) = downloads {
// Check the download limit bounds
if let Some(d) = download_limit {
if d < PARAMS_DOWNLOAD_MIN || d > PARAMS_DOWNLOAD_MAX {
return Err(ParamsDataError::DownloadBounds);
}
}
// Set the downloads
self.downloads = downloads;
// Set the download limit
self.download_limit = download_limit;
Ok(())
}
@ -201,14 +197,14 @@ impl ParamsData {
/// and wouldn't change any parameter on the server when sent.
/// Sending an empty parameter data object would thus be useless.
pub fn is_empty(&self) -> bool {
self.downloads.is_none()
self.download_limit.is_none()
}
}
impl Default for ParamsData {
fn default() -> ParamsData {
ParamsData {
downloads: Some(PARAMS_DEFAULT_DOWNLOAD),
download_limit: None,
}
}
}

View file

@ -486,7 +486,7 @@ pub enum UploadError {
#[fail(display = "Bad HTTP response '{}' while requesting file upload", _1)]
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.
#[fail(display = "Failed to decode upload response")]
Decode(#[cause] ReqwestError),

View file

@ -39,7 +39,7 @@ impl<'a> Params<'a> {
// Build the parameters data object
let data = ParamsDataBuilder::default()
.downloads(self.cmd.downloads())
.download_limit(self.cmd.download_limit())
.build()
.unwrap();

View file

@ -2,7 +2,7 @@ use std::path::Path;
use std::sync::{Arc, Mutex};
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::reqwest::Client;
@ -43,7 +43,7 @@ impl<'a> Upload<'a> {
let params = {
// Build the parameters data object
let mut params = ParamsDataBuilder::default()
.download(self.cmd.downloads())
.download_limit(self.cmd.download_limit())
.build()
.unwrap();

View file

@ -17,7 +17,7 @@ impl<'a: 'b, 'b> CmdParams<'a> {
/// Build the sub command definition.
pub fn build<'y, 'z>() -> App<'y, 'z> {
// Build a list of data parameter arguments of which one is required
let param_args = ["downloads"];
let param_args = ["download-limit"];
// Build the subcommand
let cmd = SubCommand::with_name("parameters")
@ -38,12 +38,16 @@ impl<'a: 'b, 'b> CmdParams<'a> {
.alias("token")
.value_name("TOKEN")
.help("File owner token"))
.arg(Arg::with_name("downloads")
.long("downloads")
.arg(Arg::with_name("download-limit")
.long("download-limit")
.short("d")
.alias("downloads")
.alias("download")
.alias("down")
.alias("dlimit")
.alias("limit")
.alias("lim")
.alias("l")
.required_unless_one(&param_args)
.value_name("COUNT")
.help("Set the download limit parameter"));
@ -94,17 +98,16 @@ impl<'a: 'b, 'b> CmdParams<'a> {
.map(|token| token.to_owned())
}
/// Get the download counts.
pub fn downloads(&'a self) -> Option<u8> {
// Get the number of downloads
/// Get the download limit.
pub fn download_limit(&'a self) -> Option<u8> {
// TODO: do not unwrap, report an error
self.matches.value_of("downloads")
.map(|d| d.parse::<u8>().expect("invalid number of downloads"))
self.matches.value_of("download-limit")
.map(|d| d.parse::<u8>().expect("invalid download limit"))
.and_then(|d| {
// Check the download count bounds
// Check the download limit bounds
if d < DOWNLOAD_MIN || d > DOWNLOAD_MAX {
panic!(
"invalid number of downloads, must be between {} and {}",
"invalid download limit, must be between {} and {}",
DOWNLOAD_MIN,
DOWNLOAD_MAX,
);

View file

@ -44,12 +44,16 @@ impl<'a: 'b, 'b> CmdUpload<'a> {
.min_values(0)
.max_values(1)
.help("Protect the file with a password"))
.arg(Arg::with_name("downloads")
.long("downloads")
.arg(Arg::with_name("downloads-limit")
.long("download-limit")
.short("d")
.alias("downloads")
.alias("download")
.alias("down")
.alias("dlimit")
.alias("limit")
.alias("lim")
.alias("l")
.value_name("COUNT")
.default_value("1")
.help("Set the download limit"))
@ -169,17 +173,17 @@ impl<'a: 'b, 'b> CmdUpload<'a> {
}
/// Get the download limit if set.
pub fn downloads(&'a self) -> Option<u8> {
// Get the number of downloads, or none if not set or default
pub fn download_limit(&'a self) -> Option<u8> {
// Get the download limit, or None if not set or default
// TODO: do not unwrap, report an error
self.matches.value_of("downloads")
.map(|d| d.parse::<u8>().expect("invalid number of downloads"))
self.matches.value_of("download-limit")
.map(|d| d.parse::<u8>().expect("invalid download limit"))
.and_then(|d| if d == DOWNLOAD_DEFAULT { None } else { Some(d) })
.and_then(|d| {
// Check the download count bounds
// Check the download limit bounds
if d < DOWNLOAD_MIN || d > DOWNLOAD_MAX {
panic!(
"invalid number of downloads, must be between {} and {}",
"invalid download limit, must be between {} and {}",
DOWNLOAD_MIN,
DOWNLOAD_MAX,
);