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
use crate::common::StorageClass;
use std::collections::BTreeMap;
#[doc(hidden)]
#[macro_export]
macro_rules! __make_obj_url {
($url:expr, $id:expr) => {{
format!(
$url,
percent_encoding::percent_encode($id.bucket().as_ref(), crate::util::PATH_ENCODE_SET),
percent_encoding::percent_encode($id.object().as_ref(), crate::util::PATH_ENCODE_SET)
)
}};
}
mod delete;
mod download;
mod get;
mod insert;
mod list;
mod patch;
pub use delete::*;
pub use download::*;
pub use get::*;
pub use insert::*;
pub use list::*;
pub use patch::*;
pub struct Object;
#[derive(Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Metadata {
#[serde(skip_serializing)]
pub id: Option<String>,
#[serde(skip_serializing)]
pub self_link: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing)]
pub bucket: Option<String>,
#[serde(default, skip_serializing, deserialize_with = "from_str_opt")]
pub generation: Option<i64>,
#[serde(default, skip_serializing, deserialize_with = "from_str_opt")]
pub metageneration: Option<i64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub content_type: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub content_disposition: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub content_encoding: Option<String>,
#[serde(skip_serializing)]
pub time_created: Option<chrono::DateTime<chrono::Utc>>,
#[serde(skip_serializing)]
pub updated: Option<chrono::DateTime<chrono::Utc>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub storage_class: Option<StorageClass>,
#[serde(skip_serializing)]
pub time_storage_class_updated: Option<chrono::DateTime<chrono::Utc>>,
#[serde(default, skip_serializing, deserialize_with = "from_str_opt")]
pub size: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub md5_hash: Option<String>,
#[serde(skip_serializing)]
pub media_link: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub content_language: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub crc32c: Option<String>,
#[serde(skip_serializing)]
pub etag: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub metadata: Option<BTreeMap<String, String>>,
}
fn from_str_opt<'de, T, D>(deserializer: D) -> Result<Option<T>, D::Error>
where
T: std::str::FromStr,
T::Err: std::fmt::Display,
D: serde::de::Deserializer<'de>,
{
use serde::de::Deserialize;
let s: &str = Deserialize::deserialize(deserializer)?;
Ok(Some(T::from_str(&s).map_err(serde::de::Error::custom)?))
}