1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
pub mod client;
mod test;
use serde::Deserialize;
#[derive(Debug, Deserialize)]
struct DbxRequestLimitsErrorSummary {
error_summary: String,
error: DbxRequestErrorReason,
}
#[derive(Debug, Deserialize)]
struct DbxRequestErrorSummary {
error_summary: String,
error: DbxRequestErrorTag,
}
#[derive(Debug, Deserialize)]
struct DbxRequestErrorReason {
reason: DbxRequestErrorTag,
retry_after: u32,
}
#[derive(Debug, Deserialize)]
struct DbxRequestErrorTag {
#[serde(alias = ".tag")]
tag: String,
}
#[derive(Debug, Deserialize)]
struct UserCheckResult {
result: String,
}
pub type DropboxResult<T> = std::result::Result<T, DropboxError>;
#[derive(Debug)]
pub enum DropboxError {
#[cfg(feature = "non-blocking")]
NonBlockingRequestError(reqwest::Error),
#[cfg(feature = "blocking")]
BlockingRequestError(ureq::Error),
DbxUserCheckError(String),
DbxPathError(String),
DbxExistedError(String),
DbxInvalidTokenError(String),
DbxFromLookUpError(String),
DbxRequestLimitsError(String),
DbxAccessError(String),
DbxConflictError(String),
DbxServerError(String),
OtherError(String),
#[cfg(feature = "blocking")]
BodyParseError(std::io::Error),
}
#[cfg(feature = "blocking")]
impl From<std::io::Error> for DropboxError {
fn from(e: std::io::Error) -> Self {
Self::BodyParseError(e)
}
}
#[cfg(feature = "non-blocking")]
impl From<reqwest::Error> for DropboxError {
fn from(e: reqwest::Error) -> Self {
Self::NonBlockingRequestError(e)
}
}
#[cfg(feature = "blocking")]
impl From<ureq::Error> for DropboxError {
fn from(e: ureq::Error) -> Self {
Self::BlockingRequestError(e)
}
}
pub struct UploadOption {
mode: UploadMode,
allow_auto_rename: bool,
mute_notification: bool,
allow_strict_conflict: bool,
}
impl UploadOption {
pub fn new() -> Self {
Self {
mode: UploadMode::Add,
allow_auto_rename: true,
mute_notification: false,
allow_strict_conflict: false,
}
}
pub fn disallow_auto_rename(mut self) -> Self {
self.allow_auto_rename = false;
self
}
pub fn mute_notification(mut self) -> Self {
self.mute_notification = true;
self
}
pub fn allow_strict_conflict(mut self) -> Self {
self.allow_strict_conflict = true;
self
}
pub fn set_upload_mode(mut self, mode: UploadMode) -> Self {
self.mode = mode;
self
}
}
pub struct MoveCopyOption {
allow_shared_folder: bool,
auto_rename: bool,
allow_ownership_transfer: bool,
}
impl MoveCopyOption {
pub fn new() -> Self {
Self {
allow_shared_folder: false,
auto_rename: false,
allow_ownership_transfer: false,
}
}
pub fn allow_shared_folder(mut self) -> Self {
self.allow_shared_folder = true;
self
}
pub fn allow_auto_rename(mut self) -> Self {
self.auto_rename = true;
self
}
pub fn allow_ownership_transfer(mut self) -> Self {
self.allow_ownership_transfer = true;
self
}
}
pub enum UploadMode {
Add,
Overwrite,
Update(String),
}