1use serde::{Deserialize, Serialize};
3use std::path::Path;
4
5#[derive(Deserialize, Debug, Clone)]
9#[serde(untagged)]
10pub(crate) enum WaifuApiResponse {
11 WaifuFileResponse(WaifuFileEntry),
13
14 WaifuAlbumResponse(WaifuAlbumEntry),
16
17 WaifuBucketResponse(WaifuBucketEntry),
19
20 WaifuGenericResponse(WaifuGenericMessage),
22
23 WaifuError(WaifuError),
25
26 Delete(bool),
29}
30
31#[derive(Debug, Deserialize, Clone)]
33pub struct WaifuFileEntry {
34 pub token: String,
36
37 pub url: String,
39
40 pub bucket: Option<String>,
42
43 pub id: usize,
45
46 pub album: Option<WaifuAlbumMetadata>,
48
49 pub views: usize,
51
52 #[serde(rename = "retentionPeriod")]
54 pub retention_period: serde_json::Value,
55
56 pub options: Option<WaifuFileOptions>,
58}
59
60#[derive(Clone, Debug, PartialEq, Eq, Deserialize)]
62pub struct WaifuFileOptions {
63 #[serde(rename = "hideFilename")]
65 pub hide_filename: bool,
66
67 #[serde(rename = "oneTimeDownload")]
69 pub one_time_download: bool,
70
71 pub protected: bool,
73}
74
75#[derive(Debug, Deserialize, Clone)]
77pub struct WaifuBucketEntry {
78 pub token: String,
80
81 pub files: Vec<WaifuFileEntry>,
83
84 pub albums: Option<Vec<WaifuAlbumMetadata>>,
86}
87
88#[derive(Debug, Deserialize, Clone)]
90pub struct WaifuAlbumEntry {
91 pub token: String,
93
94 #[serde(rename = "bucketToken")]
96 pub bucket_token: String,
97
98 #[serde(rename = "publicToken")]
100 pub public_token: Option<String>,
101
102 pub name: String,
104
105 pub files: Vec<WaifuFileEntry>,
107}
108
109#[derive(Debug, Deserialize, Clone)]
111pub struct WaifuAlbumMetadata {
112 pub token: String,
114
115 #[serde(rename = "publicToken")]
117 pub public_token: Option<String>,
118
119 pub name: String,
121
122 pub bucket: String,
124
125 #[serde(rename = "dateCreated")]
127 pub date_created: u64,
128}
129
130#[derive(Debug, Deserialize, Clone)]
132pub struct WaifuGenericMessage {
133 pub success: bool,
135
136 pub description: String,
138}
139
140#[derive(Debug, Deserialize, Clone)]
142pub struct WaifuError {
143 pub name: String,
145
146 pub message: String,
148
149 pub status: u16,
151}
152
153impl std::fmt::Display for WaifuError {
154 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
155 write!(
156 f,
157 "WaifuError {} ({})\nMessage: {}",
158 self.name, self.status, self.message
159 )
160 }
161}
162
163impl std::error::Error for WaifuError {}
164
165#[derive(Debug, Default, Clone)]
167pub struct WaifuUploadRequest {
168 pub(crate) file: Option<String>,
170
171 pub(crate) url: Option<String>,
173
174 pub(crate) bytes: Option<Vec<u8>>,
176
177 pub(crate) bucket: Option<String>,
179
180 pub(crate) filename: Option<String>,
182
183 pub(crate) expires: Option<String>,
187
188 pub(crate) hide_filename: bool,
190
191 pub(crate) password: Option<String>,
195
196 pub(crate) one_time_download: bool,
198}
199
200impl WaifuUploadRequest {
201 pub fn new() -> Self {
203 Self::default()
204 }
205
206 pub fn file(mut self, file: impl AsRef<Path>) -> Self {
208 let file = file.as_ref().display().to_string();
209 self.file = Some(file);
210 self
211 }
212
213 pub fn url(mut self, url: impl AsRef<str>) -> Self {
215 self.url = Some(url.as_ref().to_string());
216 self
217 }
218
219 pub fn bytes(mut self, bytes: Vec<u8>, filename: impl AsRef<str>) -> Self {
221 self.bytes = Some(bytes);
222 self.filename = Some(filename.as_ref().to_string());
223 self
224 }
225
226 pub fn bucket(mut self, token: impl AsRef<str>) -> Self {
228 self.bucket = Some(token.as_ref().to_string());
229 self
230 }
231
232 pub fn expires(mut self, expires: impl AsRef<str>) -> Self {
234 self.expires = Some(expires.as_ref().to_string());
235 self
236 }
237
238 pub fn hide_filename(mut self, hide: bool) -> Self {
240 self.hide_filename = hide;
241 self
242 }
243
244 pub fn password(mut self, password: impl AsRef<str>) -> Self {
246 self.password = Some(password.as_ref().to_string());
247 self
248 }
249
250 pub fn one_time_download(mut self, otd: bool) -> Self {
252 self.one_time_download = otd;
253 self
254 }
255}
256
257#[derive(Debug, Default, Clone)]
259pub struct WaifuGetRequest {
260 pub(crate) token: String,
262
263 pub(crate) formatted: bool,
265}
266
267impl WaifuGetRequest {
268 pub fn new(token: impl AsRef<str>) -> Self {
270 Self {
271 token: token.as_ref().to_string(),
272 ..Default::default()
273 }
274 }
275
276 pub fn formatted(mut self, format: bool) -> Self {
278 self.formatted = format;
279 self
280 }
281}
282
283#[derive(Debug, Default, Clone, Serialize)]
286pub struct WaifuModificationRequest {
287 #[serde(skip)]
289 pub(crate) token: String,
290
291 #[serde(skip_serializing_if = "Option::is_none")]
293 pub(crate) password: Option<String>,
294
295 #[serde(skip_serializing_if = "Option::is_none")]
298 #[serde(rename = "previousPassword")]
299 pub(crate) previous_password: Option<String>,
300
301 #[serde(skip_serializing_if = "Option::is_none")]
303 #[serde(rename = "customExpiry")]
304 pub(crate) custom_expiry: Option<String>,
305
306 #[serde(skip_serializing_if = "Option::is_none")]
308 #[serde(rename = "hideFilename")]
309 pub(crate) hide_filename: Option<bool>,
310}
311
312impl WaifuModificationRequest {
313 pub fn new(token: impl AsRef<str>) -> Self {
315 Self {
316 token: token.as_ref().to_string(),
317 ..Default::default()
318 }
319 }
320
321 pub fn password(mut self, password: impl AsRef<str>) -> Self {
323 self.password = Some(password.as_ref().to_string());
324 self
325 }
326
327 pub fn previous_password(mut self, prev_pwd: impl AsRef<str>) -> Self {
329 self.previous_password = Some(prev_pwd.as_ref().to_string());
330 self
331 }
332
333 pub fn custom_expiry(mut self, expiry: impl AsRef<str>) -> Self {
335 self.custom_expiry = Some(expiry.as_ref().to_string());
336 self
337 }
338
339 pub fn hide_filename(mut self, hide: bool) -> Self {
341 self.hide_filename = Some(hide);
342 self
343 }
344}