add contentlength in reqprops
This commit is contained in:
parent
2d4905f506
commit
0922066baa
@ -1,4 +1,5 @@
|
|||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
use futures_util::StreamExt;
|
||||||
use chrono::{Utc, DateTime};
|
use chrono::{Utc, DateTime};
|
||||||
use reqwest::{Method, Response, Error};
|
use reqwest::{Method, Response, Error};
|
||||||
use xml::reader::{EventReader, XmlEvent};
|
use xml::reader::{EventReader, XmlEvent};
|
||||||
@ -12,6 +13,7 @@ pub struct ObjProps {
|
|||||||
pub href: Option<String>,
|
pub href: Option<String>,
|
||||||
pub relative_s: Option<String>,
|
pub relative_s: Option<String>,
|
||||||
pub lastmodified: Option<DateTime<Utc>>,
|
pub lastmodified: Option<DateTime<Utc>>,
|
||||||
|
pub contentlength: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Clone for ObjProps {
|
impl Clone for ObjProps {
|
||||||
@ -20,6 +22,7 @@ impl Clone for ObjProps {
|
|||||||
href: self.href.clone(),
|
href: self.href.clone(),
|
||||||
relative_s: self.relative_s.clone(),
|
relative_s: self.relative_s.clone(),
|
||||||
lastmodified: self.lastmodified.clone(),
|
lastmodified: self.lastmodified.clone(),
|
||||||
|
contentlength: self.contentlength.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -30,6 +33,7 @@ impl ObjProps {
|
|||||||
href: None,
|
href: None,
|
||||||
relative_s: None,
|
relative_s: None,
|
||||||
lastmodified: None,
|
lastmodified: None,
|
||||||
|
contentlength: None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,7 +77,7 @@ impl ReqProps {
|
|||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn _getcontentlenght(&mut self) -> &mut ReqProps {
|
pub fn getcontentlength(&mut self) -> &mut ReqProps {
|
||||||
self.xml_balises.push(String::from("getcontentlength"));
|
self.xml_balises.push(String::from("getcontentlength"));
|
||||||
self.xml_payload.push_str(r#"<d:getcontentlength/>"#);
|
self.xml_payload.push_str(r#"<d:getcontentlength/>"#);
|
||||||
self
|
self
|
||||||
@ -157,6 +161,7 @@ impl ReqProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn parse(&self, xml: String, multiple: bool) -> Vec<ObjProps> {
|
fn parse(&self, xml: String, multiple: bool) -> Vec<ObjProps> {
|
||||||
|
dbg!(xml.clone());
|
||||||
let cursor = Cursor::new(xml);
|
let cursor = Cursor::new(xml);
|
||||||
let parser = EventReader::new(cursor);
|
let parser = EventReader::new(cursor);
|
||||||
|
|
||||||
@ -170,6 +175,7 @@ impl ReqProps {
|
|||||||
for event in parser {
|
for event in parser {
|
||||||
match event {
|
match event {
|
||||||
Ok(XmlEvent::StartElement { name, .. }) => {
|
Ok(XmlEvent::StartElement { name, .. }) => {
|
||||||
|
dbg!(name.clone().local_name);
|
||||||
if let Some(v) = val.clone() {
|
if let Some(v) = val.clone() {
|
||||||
should_get = &name.local_name == v;
|
should_get = &name.local_name == v;
|
||||||
} else {
|
} else {
|
||||||
@ -193,21 +199,30 @@ impl ReqProps {
|
|||||||
match val.unwrap().as_str() {
|
match val.unwrap().as_str() {
|
||||||
"href" => {
|
"href" => {
|
||||||
content.href = Some(text.clone());
|
content.href = Some(text.clone());
|
||||||
content.relative_s = Some(get_relative_s(text, &(self.api_props.clone().unwrap())));
|
content.relative_s = Some(
|
||||||
|
get_relative_s(text, &(self.api_props
|
||||||
|
.clone()
|
||||||
|
.unwrap())));
|
||||||
},
|
},
|
||||||
"getlastmodified" => {
|
"getlastmodified" => {
|
||||||
content.lastmodified = Some(parse_timestamp(&text).unwrap());
|
content.lastmodified = Some(
|
||||||
|
parse_timestamp(&text).unwrap());
|
||||||
|
},
|
||||||
|
"getcontentlength" => {
|
||||||
|
content.contentlength = Some(
|
||||||
|
text.clone().parse().unwrap());
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
val = iter.next()
|
val = iter.next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(XmlEvent::EndElement { .. }) => {
|
Ok(XmlEvent::EndElement { name, .. }) => {
|
||||||
|
dbg!(name.clone().local_name);
|
||||||
should_get = false;
|
should_get = false;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!("Error: {}", e);
|
eprintln!("err: parsing xml: {}", e);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
Loading…
Reference in New Issue
Block a user