add lastmodified in req props

This commit is contained in:
grimhilt
2023-06-17 16:41:00 +02:00
parent 1fd7948122
commit e0d4c5efac
5 changed files with 91 additions and 4 deletions

View File

@@ -1,13 +1,15 @@
use crate::services::api::{ApiBuilder, ApiError};
use crate::utils::api::get_relative_s;
use xml::reader::{EventReader, XmlEvent};
use std::io::Cursor;
use xml::reader::{EventReader, XmlEvent};
use reqwest::{Method, Response, Error};
use crate::utils::api::ApiProps;
use chrono::{Utc, DateTime};
use crate::services::api::{ApiBuilder, ApiError};
use crate::utils::time::parse_timestamp;
use crate::utils::api::{get_relative_s, ApiProps};
pub struct ObjProps {
pub href: Option<String>,
pub relative_s: Option<String>,
pub lastmodified: Option<DateTime<Utc>>,
}
impl Clone for ObjProps {
@@ -15,6 +17,7 @@ impl Clone for ObjProps {
ObjProps {
href: self.href.clone(),
relative_s: self.relative_s.clone(),
lastmodified: self.lastmodified.clone(),
}
}
}
@@ -24,6 +27,7 @@ impl ObjProps {
ObjProps {
href: None,
relative_s: None,
lastmodified: None,
}
}
}
@@ -177,6 +181,9 @@ impl ReqProps {
content.href = Some(text.clone());
content.relative_s = Some(get_relative_s(text, &(self.api_props.clone().unwrap())));
},
"getlastmodified" => {
content.lastmodified = Some(parse_timestamp(&text).unwrap());
},
_ => (),
}
val = iter.next()

View File

@@ -2,3 +2,4 @@ pub mod path;
pub mod read;
pub mod nextsyncignore;
pub mod api;
pub mod time;

6
src/utils/time.rs Normal file
View File

@@ -0,0 +1,6 @@
use chrono::{DateTime, TimeZone, Utc, ParseError};
pub fn parse_timestamp(timestamp: &str) -> Result<DateTime<Utc>, ParseError> {
let format = "%a, %d %b %Y %H:%M:%S %Z";
Utc.datetime_from_str(timestamp, format)
}