瀏覽代碼

Add remote file expiry time property

timvisee 7 年之前
父節點
當前提交
05517f64d3
共有 6 個文件被更改,包括 29 次插入5 次删除
  1. 1 0
      Cargo.lock
  2. 3 0
      ROADMAP.md
  3. 1 0
      api/Cargo.toml
  4. 4 1
      api/src/config.rs
  5. 19 4
      api/src/file/remote_file.rs
  6. 1 0
      api/src/lib.rs

+ 1 - 0
Cargo.lock

@@ -384,6 +384,7 @@ dependencies = [
  "serde_derive 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
  "serde_json 1.0.15 (registry+https://github.com/rust-lang/crates.io-index)",
  "sha2 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
  "url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
 ]

+ 3 - 0
ROADMAP.md

@@ -7,6 +7,9 @@
   - Info, if file doesn't exist, and update TTL
   - Parameters, if file doesn't exist
   - Password, if file doesn't exist
+- Remote file expiry time:
+  - Add uncertainty flag
+  - Give all files the default expiry flag if not set (with uncertainty flag)
 - Create history command
 - History compiler flag
 - Incognito mode, to not remember files `--incognito`

+ 1 - 0
api/Cargo.toml

@@ -22,5 +22,6 @@ serde = "1.0"
 serde_derive = "1.0"
 serde_json = "1.0"
 sha2 = "0.7"
+time = "0.1"
 url = "1.7"
 url_serde = "0.2"

+ 4 - 1
api/src/config.rs

@@ -1,8 +1,11 @@
 use reqwest::StatusCode;
 
-/// The default Send host to use.
+/// The Send host to use by default.
 pub const SEND_DEFAULT_HOST: &'static str = "https://send.firefox.com/";
 
+/// The default time after which uploaded files expire after, in seconds.
+pub const SEND_DEFAULT_EXPIRE_TIME: i64 = 24 * 60 * 60;
+
 /// The HTTP status code that is returned for expired or non existant files.
 pub const HTTP_STATUS_EXPIRED: StatusCode = StatusCode::NotFound;
 

+ 19 - 4
api/src/file/remote_file.rs

@@ -8,8 +8,10 @@ use url::{
 };
 use self::chrono::{DateTime, Utc};
 use self::regex::Regex;
+use time::Duration;
 use url_serde;
 
+use config::SEND_DEFAULT_EXPIRE_TIME;
 use crypto::b64;
 
 /// A pattern for share URL paths, capturing the file ID.
@@ -32,7 +34,10 @@ pub struct RemoteFile {
     id: String,
 
     /// The time the file was uploaded at, if known.
-    time: Option<DateTime<Utc>>,
+    upload_at: Option<DateTime<Utc>>,
+
+    /// The time the file will expire at, if known.
+    expire_at: Option<DateTime<Utc>>,
 
     /// The host the file was uploaded to.
     #[serde(with = "url_serde")]
@@ -53,7 +58,8 @@ impl RemoteFile {
     /// Construct a new file.
     pub fn new(
         id: String,
-        time: Option<DateTime<Utc>>,
+        upload_at: Option<DateTime<Utc>>,
+        expire_at: Option<DateTime<Utc>>,
         host: Url,
         url: Url,
         secret: Vec<u8>,
@@ -61,7 +67,8 @@ impl RemoteFile {
     ) -> Self {
         Self {
             id,
-            time,
+            upload_at,
+            expire_at,
             host,
             url,
             secret,
@@ -70,6 +77,7 @@ impl RemoteFile {
     }
 
     /// Construct a new file, that was created at this exact time.
+    /// This will set the file expiration time 
     pub fn new_now(
         id: String,
         host: Url,
@@ -77,9 +85,15 @@ impl RemoteFile {
         secret: Vec<u8>,
         owner_token: Option<String>,
     ) -> Self {
+        // Get the current time
+        let now = Utc::now();
+        let expire_at = now + Duration::seconds(SEND_DEFAULT_EXPIRE_TIME);
+
+        // Construct and return
         Self::new(
             id,
-            Some(Utc::now()),
+            Some(now),
+            Some(expire_at),
             host,
             url,
             secret,
@@ -130,6 +144,7 @@ impl RemoteFile {
         Ok(Self::new(
             id,
             None,
+            None,
             host,
             url,
             secret,

+ 1 - 0
api/src/lib.rs

@@ -12,6 +12,7 @@ extern crate serde;
 #[macro_use]
 extern crate serde_derive;
 extern crate serde_json;
+extern crate time;
 pub extern crate url;
 pub extern crate url_serde;