浏览代码

Implement Serialize and Deserialize for RemoteFile

timvisee 7 年之前
父节点
当前提交
ca616f6167
共有 5 个文件被更改,包括 20 次插入3 次删除
  1. 12 0
      Cargo.lock
  2. 1 1
      ROADMAP.md
  3. 2 1
      api/Cargo.toml
  4. 4 1
      api/src/file/remote_file.rs
  5. 1 0
      api/src/lib.rs

+ 12 - 0
Cargo.lock

@@ -137,6 +137,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "num-integer 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)",
  "num-traits 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
+ "serde 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)",
  "time 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -352,6 +353,7 @@ dependencies = [
  "serde_json 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)",
  "sha2 0.7.0 (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)",
 ]
 
 [[package]]
@@ -1381,6 +1383,15 @@ dependencies = [
  "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
+[[package]]
+name = "url_serde"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "serde 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)",
+ "url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
 [[package]]
 name = "utf8-ranges"
 version = "1.0.0"
@@ -1630,6 +1641,7 @@ dependencies = [
 "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
 "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56"
 "checksum url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f808aadd8cfec6ef90e4a14eb46f24511824d1ac596b9682703c87056c8678b7"
+"checksum url_serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "74e7d099f1ee52f823d4bdd60c93c3602043c728f5db3b97bdb548467f7bddea"
 "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122"
 "checksum uuid 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcc7e3b898aa6f6c08e5295b6c89258d1331e9ac578cc992fb818759951bdc22"
 "checksum vcpkg 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7ed0f6789c8a85ca41bbc1c9d175422116a9869bd1cf31bb08e1493ecce60380"

+ 1 - 1
ROADMAP.md

@@ -1,5 +1,4 @@
 # Release 0.1
-- Color usage flag
 - Remember all uploaded files, make files listable
 - Incognito mode, to not remember files `--incognito`
 - Automatically get owner token, from file history when setting password
@@ -15,6 +14,7 @@
 - Check all TODOs, solve them when possible
 
 # Future releases
+- Color usage flag
 - Implement verbose logging with `-v`
 - Box errors
 - A status command, to check the server status using `/__version__` and

+ 2 - 1
api/Cargo.toml

@@ -8,7 +8,7 @@ workspace = ".."
 [dependencies]
 arrayref = "0.3"
 base64 = "0.9"
-chrono = "0.4"
+chrono = {version = "0.4", features = ["serde"]}
 derive_builder = "0.5"
 failure = "0.1"
 failure_derive = "0.1"
@@ -23,3 +23,4 @@ serde_derive = "1.0"
 serde_json = "1.0"
 sha2 = "0.7"
 url = "1.7"
+url_serde = "0.2"

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

@@ -8,6 +8,7 @@ use url::{
 };
 use self::chrono::{DateTime, Utc};
 use self::regex::Regex;
+use url_serde;
 
 use crypto::b64;
 
@@ -25,7 +26,7 @@ const SHARE_FRAGMENT_PATTERN: &'static str = r"^([a-zA-Z0-9-_+/]+)?\s*$";
 ///
 /// The struct contains the file ID, the file URL, the key that is required
 /// in combination with the file, and the owner key.
-#[derive(Debug)]
+#[derive(Debug, Serialize, Deserialize)]
 pub struct RemoteFile {
     /// The ID of the file on that server.
     id: String,
@@ -34,9 +35,11 @@ pub struct RemoteFile {
     time: Option<DateTime<Utc>>,
 
     /// The host the file was uploaded to.
+    #[serde(with = "url_serde")]
     host: Url,
 
     /// The file URL that was provided by the server.
+    #[serde(with = "url_serde")]
     url: Url,
 
     /// The secret key that is required to download the file.

+ 1 - 0
api/src/lib.rs

@@ -13,6 +13,7 @@ extern crate serde;
 extern crate serde_derive;
 extern crate serde_json;
 pub extern crate url;
+pub extern crate url_serde;
 
 pub mod action;
 mod api;