webdav_request/res/
dav.rs1use crate::multistatus::MultiStatus;
2
3#[derive(Default, Debug, Clone)]
7pub struct DavItem {
8 pub is_dir: bool,
9 pub url: String,
10 pub name: String,
12 pub last_modified: String,
14 pub size: u64,
16 pub content_type: String,
18}
19
20impl DavItem {
21 pub(crate) fn parse(multi_status: MultiStatus, url: &str) -> crate::Result<Vec<Self>> {
22 let responses = multi_status.response;
23 if responses.is_empty() {
24 return Ok(Vec::new());
25 }
26 let mut buf = Vec::new();
27 for item in responses.into_iter().skip(1) {
28 let prop = item.prop_stat.prop;
29 let item_url = format!(
30 "{url}{}{}",
31 if url.ends_with("/") { "" } else { "/" },
32 prop.display_name
33 );
34
35 let path = percent_encoding::percent_decode_str(&item_url)
36 .decode_utf8()?
37 .to_string();
38 buf.push(DavItem {
39 is_dir: prop.is_collection(),
40 url: path,
41 name: prop.display_name,
42 last_modified: prop.last_modified,
43 size: prop.content_length,
44 content_type: prop.content_type,
45 });
46 }
47
48 Ok(buf)
49 }
50}