Przeglądaj źródła

Sort history list, put first expiring last

timvisee 7 lat temu
rodzic
commit
85e6e3da40
3 zmienionych plików z 15 dodań i 5 usunięć
  1. 0 1
      ROADMAP.md
  2. 10 3
      api/src/file/remote_file.rs
  3. 5 1
      cli/src/action/history.rs

+ 0 - 1
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

+ 10 - 3
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<Utc> {
+        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();

+ 5 - 1
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() {