From 85e6e3da402f7e450d7137ade0fb8c9c88f537f6 Mon Sep 17 00:00:00 2001 From: timvisee Date: Tue, 8 May 2018 14:13:32 +0200 Subject: [PATCH] Sort history list, put first expiring last --- ROADMAP.md | 1 - api/src/file/remote_file.rs | 13 ++++++++++--- cli/src/action/history.rs | 6 +++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ROADMAP.md b/ROADMAP.md index 137ba62..94d31ff 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -1,5 +1,4 @@ # Release 0.1 -- Sort history entries - Panic when secret is missing from URL with info action - History compiler flag - Lowercase error messages diff --git a/api/src/file/remote_file.rs b/api/src/file/remote_file.rs index 7236351..cf7dcab 100644 --- a/api/src/file/remote_file.rs +++ b/api/src/file/remote_file.rs @@ -167,9 +167,16 @@ impl RemoteFile { &self.id } - /// Get the duration the file will expire after, - /// if an expiry time is known. - /// Otherwise `None` is returned. + /// Get the time the file will expire after. + /// Note that this time may not be correct as it may have been guessed, + /// see `expire_uncertain()`. + pub fn expire_at(&self) -> DateTime { + self.expire_at + } + + /// Get the duration the file will expire after. + /// Note that this time may not be correct as it may have been guessed, + /// see `expire_uncertain()`. pub fn expire_duration(&self) -> Duration { // Get the current time let now = Utc::now(); diff --git a/cli/src/action/history.rs b/cli/src/action/history.rs index e6389ea..cfd9e08 100644 --- a/cli/src/action/history.rs +++ b/cli/src/action/history.rs @@ -66,8 +66,12 @@ impl<'a> History<'a> { Cell::new("OWNER TOKEN"), ])); + // Get the list of files, and sort the first expiring files to be last + let mut files = history.files().clone(); + files.sort_by(|a, b| b.expire_at().cmp(&a.expire_at())); + // Add an entry for each file - for (i, file) in history.files().iter().enumerate() { + for (i, file) in files.iter().enumerate() { // Build the expiry time string let mut expiry = format_duration(&file.expire_duration()); if file.expire_uncertain() {