diff --git a/src/content/mod.rs b/src/content/mod.rs index a45c779..530df5b 100644 --- a/src/content/mod.rs +++ b/src/content/mod.rs @@ -123,6 +123,11 @@ impl Content self.uri.clone() } + pub fn get_last_refreshed(&self) -> SystemTime + { + self.last_refreshed.clone() + } + pub fn utf8_body(&self) -> Result { String::from_utf8(self.body.clone()) diff --git a/src/content/pages/page.rs b/src/content/pages/page.rs index de32456..6dbd7a4 100644 --- a/src/content/pages/page.rs +++ b/src/content/pages/page.rs @@ -98,7 +98,6 @@ impl IntoResponse for Page { pub fn is_page(uri: &str, domain: &str) -> bool { - let domain_escaped = domain.replace("https://", "").replace("http://", "").replace(".", r"\."); match Regex::new(format!(r"((^|(http)(s|)://){})(/|/[^\.]+|/[^\.]+.html|$)$",domain_escaped).as_str()) { diff --git a/tests/test_content.rs b/tests/test_content.rs index 8cbe9cb..84cebe0 100644 --- a/tests/test_content.rs +++ b/tests/test_content.rs @@ -3,9 +3,10 @@ mod common; #[cfg(test)] mod test_content { - use std::{fs::remove_file, path::Path}; + use std::{fs::remove_file, path::Path, thread::sleep, time}; use busser::{content::Content, filesystem::file::{file_hash, write_file_bytes, Observed}, util::read_bytes}; + use chrono::Duration; #[test] fn test_load_content() @@ -55,5 +56,18 @@ mod test_content let _ = remove_file(path); } + #[test] + fn test_last_refreshed() + { + let mut content = Content::new("tests/pages/a.html", "tests/pages/a.html", 3600); + assert!(content.load_from_file().is_ok()); + let a = content.get_last_refreshed(); + sleep(time::Duration::from_secs(2)); + assert!(content.load_from_file().is_ok()); + let b = content.get_last_refreshed(); + assert!(a < b); + } + + }