mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-25 08:41:05 +00:00
fix: add chrono to display validity range
This commit is contained in:
parent
437cbc2290
commit
c5766ebb51
5 changed files with 20 additions and 39 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -6238,6 +6238,7 @@ name = "yazi-vfs"
|
|||
version = "26.2.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
"deadpool",
|
||||
"either",
|
||||
"futures",
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ ansi-to-tui = "8.0.1"
|
|||
anyhow = "1.0.102"
|
||||
base64 = "0.22.1"
|
||||
bitflags = { version = "2.11.0", features = [ "serde" ] }
|
||||
chrono = "0.4.44"
|
||||
clap = { version = "4.5.60", features = [ "derive" ] }
|
||||
core-foundation-sys = "0.8.7"
|
||||
crossterm = { version = "0.29.0", features = [ "event-stream" ] }
|
||||
|
|
|
|||
|
|
@ -1,35 +1,6 @@
|
|||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
|
||||
#[inline]
|
||||
pub fn timestamp_us() -> u64 {
|
||||
SystemTime::now().duration_since(UNIX_EPOCH).expect("Time went backwards").as_micros() as _
|
||||
}
|
||||
|
||||
pub fn format_duration(duration: Duration) -> String {
|
||||
// go till days precision, but only show the non-zero parts
|
||||
let mut secs = duration.as_secs();
|
||||
let days = secs / 86_400;
|
||||
secs %= 86_400;
|
||||
let hours = secs / 3_600;
|
||||
secs %= 3_600;
|
||||
let minutes = secs / 60;
|
||||
secs %= 60;
|
||||
let mut parts = Vec::with_capacity(4);
|
||||
if days > 0 {
|
||||
parts.push(format!("{}d", days));
|
||||
}
|
||||
if hours > 0 || days > 0 {
|
||||
parts.push(format!("{:0>2}h", hours));
|
||||
}
|
||||
if minutes > 0 || hours > 0 || days > 0 {
|
||||
parts.push(format!("{:0>2}m", minutes));
|
||||
}
|
||||
if secs > 0 || minutes > 0 || hours > 0 || days > 0 {
|
||||
parts.push(format!("{:0>2}s", secs));
|
||||
}
|
||||
if parts.is_empty() {
|
||||
"0s".to_string()
|
||||
} else {
|
||||
parts.join("")
|
||||
}
|
||||
}
|
||||
|
|
@ -21,6 +21,7 @@ yazi-shared = { path = "../yazi-shared", version = "26.2.2" }
|
|||
|
||||
# External dependencies
|
||||
anyhow = { workspace = true }
|
||||
chrono = {workspace = true}
|
||||
deadpool = { version = "0.13.0", default-features = false, features = [ "managed", "rt_tokio_1" ] }
|
||||
either = { workspace = true }
|
||||
futures = { workspace = true }
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::{io, sync::Arc, time::Duration};
|
|||
use russh::keys::PrivateKeyWithHashAlg;
|
||||
use yazi_config::vfs::ServiceSftp;
|
||||
use yazi_fs::provider::local::Local;
|
||||
use yazi_shared::{format_duration, timestamp_us};
|
||||
use yazi_shared::timestamp_us;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub(super) struct Conn {
|
||||
|
|
@ -175,15 +175,22 @@ impl Conn {
|
|||
russh::Error::InvalidConfig(format!("Certificate signature verification failed: {e}"))
|
||||
})?;
|
||||
let unix_timestamp = timestamp_us() / 1_000_000;
|
||||
if unix_timestamp < cert.valid_after() {
|
||||
|
||||
if unix_timestamp < cert.valid_after() || unix_timestamp > cert.valid_before() {
|
||||
let format_time = |ts: u64| {
|
||||
i64::try_from(ts)
|
||||
.ok()
|
||||
.and_then(chrono::DateTime::from_timestamp_secs)
|
||||
.map(|dt| dt.with_timezone(&chrono::Local).format("%Y-%m-%d %H:%M:%S").to_string())
|
||||
.unwrap_or_else(|| "unknown date".to_string())
|
||||
};
|
||||
|
||||
let start = format_time(cert.valid_after());
|
||||
let end = format_time(cert.valid_before());
|
||||
|
||||
return Err(russh::Error::InvalidConfig(format!(
|
||||
"Certificate will be valid in {}",
|
||||
format_duration(Duration::from_secs(cert.valid_after() - unix_timestamp))
|
||||
)));
|
||||
} else if unix_timestamp > cert.valid_before() {
|
||||
return Err(russh::Error::InvalidConfig(format!(
|
||||
"Certificate expired {} ago",
|
||||
format_duration(Duration::from_secs(unix_timestamp - cert.valid_before()))
|
||||
"Certificate is invalid. The validity range is {} to {}",
|
||||
start, end
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue