webdav_request/res/
collection.rs

1use super::{multistatus::MultiStatus, privilege::Privilege};
2
3#[deprecated]
4#[derive(Default, Debug)]
5pub struct Collection {
6    pub href: String,
7    pub display_name: String,
8    pub children: Vec<Resource>,
9}
10#[allow(deprecated)]
11impl From<MultiStatus> for Collection {
12    fn from(value: MultiStatus) -> Self {
13        if value.response.is_empty() {
14            return Default::default();
15        }
16        let mut iter = value.response.into_iter();
17        let collection = iter.next().expect("never panic!");
18
19        Collection {
20            href: percent_encoding::percent_decode_str(&collection.href)
21                .decode_utf8()
22                .map(|s| s.to_string())
23                .unwrap_or(collection.href),
24
25            display_name: collection.prop_stat.prop.display_name,
26            children: iter
27                .map(|node| {
28                    let (href, prop) = node.upwrap();
29                    Resource {
30                        is_collection: prop.is_collection(),
31                        href: percent_encoding::percent_decode_str(&href)
32                            .decode_utf8()
33                            .map(|s| s.to_string())
34                            .unwrap_or(href),
35                        display_name: prop.display_name,
36                        last_modified: prop.last_modified,
37                        len: prop.content_length,
38                        content_type: prop.content_type,
39                        privilege: prop
40                            .current_user_privilege_set
41                            .unwrap_or_default()
42                            .privilege(),
43                    }
44                })
45                .collect(),
46        }
47    }
48}
49
50#[derive(Default, Debug, Clone)]
51pub struct Resource {
52    pub is_collection: bool,
53    pub href: String,
54    pub display_name: String,
55    pub last_modified: String,
56    pub len: u64,
57    pub content_type: String,
58    pub privilege: Privilege,
59}