ali_oss/
file.rs

1#[derive(Debug, Clone)]
2pub struct File {
3	pub name: String,
4	pub r#type: String,
5	pub size: u64,
6	pub etag: String,
7	pub last_modified: chrono::DateTime<chrono::Utc>,
8	pub storage_class: String,
9}
10
11impl File {
12	pub fn new<T: ToString>(name: T, r#type: T, size: u64, etag: T, last_modified: chrono::DateTime<chrono::Utc>, storage_class: T) -> Self {
13		Self {
14			name: name.to_string(),
15			r#type: r#type.to_string(),
16			size,
17			etag: etag.to_string(),
18			last_modified,
19			storage_class: storage_class.to_string(),
20		}
21	}
22}
23
24impl File {
25	pub fn new_from_xml_node(node: roxmltree::Node) -> anyhow::Result<Self> {
26		let name = node.descendants().find(|n| n.has_tag_name("Key")).and_then(|node| node.text()).unwrap_or("");
27		let r#type = node.descendants().find(|n| n.has_tag_name("Type")).and_then(|node| node.text()).unwrap_or("");
28		let size = node.descendants().find(|n| n.has_tag_name("Size")).and_then(|node| node.text()).unwrap_or("").parse()?;
29		let etag = node.descendants().find(|n| n.has_tag_name("ETag")).and_then(|node| node.text()).unwrap_or("").trim_matches('"');
30		let last_modified = node.descendants().find(|n| n.has_tag_name("LastModified")).and_then(|node| node.text()).unwrap_or("");
31		let storage_class = node.descendants().find(|n| n.has_tag_name("StorageClass")).and_then(|node| node.text()).unwrap_or("");
32		Ok(Self::new(name, r#type, size, etag, last_modified.parse()?, storage_class))
33	}
34}