mirror of
https://github.com/timvisee/ffsend.git
synced 2025-10-05 10:19:23 +02:00
Create parameter data builder
This commit is contained in:
parent
928b3d9beb
commit
3ba39751f2
6 changed files with 38 additions and 10 deletions
22
Cargo.lock
generated
22
Cargo.lock
generated
|
@ -259,6 +259,25 @@ dependencies = [
|
||||||
"generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "derive_builder"
|
||||||
|
version = "0.5.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"derive_builder_core 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "derive_builder_core"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
dependencies = [
|
||||||
|
"quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "digest"
|
name = "digest"
|
||||||
version = "0.7.2"
|
version = "0.7.2"
|
||||||
|
@ -319,6 +338,7 @@ dependencies = [
|
||||||
"arrayref 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"arrayref 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"base64 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"base64 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"chrono 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"chrono 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
"derive_builder 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"hkdf 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"hkdf 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -1473,6 +1493,8 @@ dependencies = [
|
||||||
"checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9"
|
"checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9"
|
||||||
"checksum crossbeam-utils 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d636a8b3bcc1b409d7ffd3facef8f21dcb4009626adbd0c5e6c4305c07253c7b"
|
"checksum crossbeam-utils 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d636a8b3bcc1b409d7ffd3facef8f21dcb4009626adbd0c5e6c4305c07253c7b"
|
||||||
"checksum crypto-mac 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0999b4ff4d3446d4ddb19a63e9e00c1876e75cd7000d20e57a693b4b3f08d958"
|
"checksum crypto-mac 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0999b4ff4d3446d4ddb19a63e9e00c1876e75cd7000d20e57a693b4b3f08d958"
|
||||||
|
"checksum derive_builder 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c998e6ab02a828dd9735c18f154e14100e674ed08cb4e1938f0e4177543f439"
|
||||||
|
"checksum derive_builder_core 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "735e24ee9e5fa8e16b86da5007856e97d592e11867e45d76e0c0d0a164a0b757"
|
||||||
"checksum digest 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "00a49051fef47a72c9623101b19bd71924a45cca838826caae3eaa4d00772603"
|
"checksum digest 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "00a49051fef47a72c9623101b19bd71924a45cca838826caae3eaa4d00772603"
|
||||||
"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
|
"checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab"
|
||||||
"checksum encoding_rs 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "98fd0f24d1fb71a4a6b9330c8ca04cbd4e7cc5d846b54ca74ff376bc7c9f798d"
|
"checksum encoding_rs 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "98fd0f24d1fb71a4a6b9330c8ca04cbd4e7cc5d846b54ca74ff376bc7c9f798d"
|
||||||
|
|
|
@ -8,6 +8,7 @@ workspace = ".."
|
||||||
arrayref = "0.3"
|
arrayref = "0.3"
|
||||||
base64 = "0.9"
|
base64 = "0.9"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
|
derive_builder = "0.5"
|
||||||
failure = "0.1"
|
failure = "0.1"
|
||||||
failure_derive = "0.1"
|
failure_derive = "0.1"
|
||||||
hkdf = "0.3"
|
hkdf = "0.3"
|
||||||
|
|
|
@ -149,7 +149,8 @@ impl<'a> Params<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The parameters data object, that is sent to the server.
|
/// The parameters data object, that is sent to the server.
|
||||||
#[derive(Clone, Debug, Serialize)]
|
// TODO: make sure downloads are in-bound when using the builder
|
||||||
|
#[derive(Clone, Debug, Builder, Serialize)]
|
||||||
pub struct ParamsData {
|
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.
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate arrayref;
|
extern crate arrayref;
|
||||||
|
#[macro_use]
|
||||||
|
extern crate derive_builder;
|
||||||
extern crate failure;
|
extern crate failure;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate failure_derive;
|
extern crate failure_derive;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use ffsend_api::action::params::{
|
use ffsend_api::action::params::{
|
||||||
Params as ApiParams,
|
Params as ApiParams,
|
||||||
ParamsData,
|
ParamsDataBuilder,
|
||||||
};
|
};
|
||||||
use ffsend_api::file::remote_file::RemoteFile;
|
use ffsend_api::file::remote_file::RemoteFile;
|
||||||
use ffsend_api::reqwest::Client;
|
use ffsend_api::reqwest::Client;
|
||||||
|
@ -37,8 +37,11 @@ impl<'a> Params<'a> {
|
||||||
|
|
||||||
// TODO: show an informative error if the owner token isn't set
|
// TODO: show an informative error if the owner token isn't set
|
||||||
|
|
||||||
// Build the params data object
|
// Build the parameters data object
|
||||||
let data = ParamsData::from(self.cmd.downloads());
|
let data = ParamsDataBuilder::default()
|
||||||
|
.downloads(self.cmd.downloads())
|
||||||
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// TODO: make sure the data isn't empty
|
// TODO: make sure the data isn't empty
|
||||||
|
|
||||||
|
|
|
@ -41,12 +41,11 @@ impl<'a> Upload<'a> {
|
||||||
|
|
||||||
// Build a parameters object to set for the file
|
// Build a parameters object to set for the file
|
||||||
let params = {
|
let params = {
|
||||||
// Build an empty parameters object
|
// Build the parameters data object
|
||||||
let mut params = ParamsData::new();
|
let mut params = ParamsDataBuilder::default()
|
||||||
|
.download(self.cmd.downloads())
|
||||||
// Set the downloads
|
.build()
|
||||||
// TODO: do not unwrap, handle the error
|
.unwrap();
|
||||||
params.set_downloads(self.cmd.downloads()).unwrap();
|
|
||||||
|
|
||||||
// Wrap the data in an option if not empty
|
// Wrap the data in an option if not empty
|
||||||
if params.is_empty() {
|
if params.is_empty() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue