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

72
Cargo.lock generated
View File

@ -11,6 +11,21 @@ dependencies = [
"memchr",
]
[[package]]
name = "android-tzdata"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
dependencies = [
"libc",
]
[[package]]
name = "ansi_term"
version = "0.12.1"
@ -73,6 +88,21 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec837a71355b28f6556dbd569b37b3f363091c0bd4b2e735674521b4c5fd9bc5"
dependencies = [
"android-tzdata",
"iana-time-zone",
"js-sys",
"num-traits",
"time",
"wasm-bindgen",
"winapi",
]
[[package]]
name = "clap"
version = "2.34.0"
@ -376,6 +406,29 @@ dependencies = [
"tokio-native-tls",
]
[[package]]
name = "iana-time-zone"
version = "0.1.57"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fad5b825842d2b38bd206f3e81d6957625fd7f0a361e345c30e01a0ae2dd613"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"wasm-bindgen",
"windows",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
dependencies = [
"cc",
]
[[package]]
name = "idna"
version = "0.3.0"
@ -526,6 +579,7 @@ dependencies = [
name = "nextsync"
version = "0.1.0"
dependencies = [
"chrono",
"clap",
"colored",
"dotenv",
@ -538,6 +592,15 @@ dependencies = [
"xml-rs",
]
[[package]]
name = "num-traits"
version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
dependencies = [
"autocfg",
]
[[package]]
name = "num_cpus"
version = "1.15.0"
@ -1259,6 +1322,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
dependencies = [
"windows-targets 0.48.0",
]
[[package]]
name = "windows-sys"
version = "0.42.0"

View File

@ -16,3 +16,4 @@ xml-rs = "0.8.0"
regex = "1.8.3"
lazy_static = "1.4.0"
glob = "0.3.1"
chrono = "0.4.26"

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)
}