fix(web): use browser recovery timestamps
This commit is contained in:
commit
af2f5f691b
1 changed files with 44 additions and 0 deletions
|
|
@ -589,6 +589,7 @@ fn diagnostic_platform() -> String {
|
||||||
format!("{}/{}", std::env::consts::OS, std::env::consts::ARCH)
|
format!("{}/{}", std::env::consts::OS, std::env::consts::ARCH)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
fn unix_seconds() -> u64 {
|
fn unix_seconds() -> u64 {
|
||||||
std::time::SystemTime::now()
|
std::time::SystemTime::now()
|
||||||
.duration_since(std::time::UNIX_EPOCH)
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
|
|
@ -596,6 +597,11 @@ fn unix_seconds() -> u64 {
|
||||||
.unwrap_or(0)
|
.unwrap_or(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
fn unix_seconds() -> u64 {
|
||||||
|
(js_sys::Date::now() / 1000.0) as u64
|
||||||
|
}
|
||||||
|
|
||||||
fn safe_stem(value: &str) -> String {
|
fn safe_stem(value: &str) -> String {
|
||||||
let filtered: String = value
|
let filtered: String = value
|
||||||
.chars()
|
.chars()
|
||||||
|
|
@ -672,3 +678,41 @@ fn write_unique(directory: &Path, file_name: &str, body: &str) -> Result<PathBuf
|
||||||
}
|
}
|
||||||
Err("Could not allocate a unique recovery-log name".to_string())
|
Err("Could not allocate a unique recovery-log name".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::{report_id, RecoveryReport, RecoveryStatus};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn report_id_includes_timestamp_and_source_fingerprint() {
|
||||||
|
assert_eq!(
|
||||||
|
report_id(
|
||||||
|
Some("0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"),
|
||||||
|
1_777_777_777,
|
||||||
|
),
|
||||||
|
"R2-1777777777-0123456789ab"
|
||||||
|
);
|
||||||
|
assert_eq!(report_id(None, 1_777_777_777), "R2-1777777777-nohash");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn failed_report_uses_current_timestamp_in_report_id() {
|
||||||
|
let report = RecoveryReport::failed(
|
||||||
|
None,
|
||||||
|
"invalid.dwg".to_string(),
|
||||||
|
42,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
"parse".to_string(),
|
||||||
|
"invalid drawing".to_string(),
|
||||||
|
7,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_eq!(report.status, RecoveryStatus::Failed);
|
||||||
|
assert!(report.created_unix_seconds > 0);
|
||||||
|
assert_eq!(
|
||||||
|
report.report_id,
|
||||||
|
report_id(report.source_sha256.as_deref(), report.created_unix_seconds)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue