diff --git a/Cargo.lock b/Cargo.lock index 4e63698..0d5f6ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -221,6 +221,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "num-integer 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/Cargo.toml b/Cargo.toml index 6062c91..6c51400 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,7 @@ serde = "1.0.104" serde_json = "1.0.44" serde_derive = "1.0.104" serde_yaml = "0.8.11" -chrono = "0.4.10" +chrono = { version = "0.4.10", features = ["serde"] } jsonwebtoken = "7.0.0-alpha.2" app_dirs = "1.2.1" ring = "0.16.9" diff --git a/src/cli.yml b/src/cli.yml index 9fc14cb..af4b97d 100644 --- a/src/cli.yml +++ b/src/cli.yml @@ -47,4 +47,8 @@ subcommands: - settings: about: "Manage the Lucid configuration file" author: *author - template: *template \ No newline at end of file + template: *template + - dump: + about: Dump or restore any data of a node + author: *author + template: *template diff --git a/src/kvstore.rs b/src/kvstore.rs index 49eefd5..97199ad 100644 --- a/src/kvstore.rs +++ b/src/kvstore.rs @@ -1,18 +1,23 @@ use block_modes::block_padding::ZeroPadding; use block_modes::{BlockMode, Cbc}; use chashmap::CHashMap; +use chrono::serde::ts_seconds::serialize as ts_seconds; use chrono::{DateTime, Utc}; use serpent::Serpent; type SerpentCbc = Cbc; -#[derive(Debug, Clone)] +#[derive(Serialize, Deserialize, PartialEq, Debug, Clone)] pub struct KvElement { + #[serde(skip_serializing)] pub data: Vec, pub mime_type: String, + #[serde(serialize_with = "ts_seconds")] pub created_at: DateTime, + #[serde(serialize_with = "ts_seconds")] pub updated_at: DateTime, + #[serde(serialize_with = "ts_seconds")] pub expire_at: DateTime, pub update_count: i32, pub locked: bool, @@ -46,7 +51,7 @@ impl KvStore { kv } - pub fn set(&self, key: String, mut value: Vec) -> Option { + pub fn set(&self, key: String, mut value: Vec, mime_type: String) -> Option { // TODO: prepare iterative persistence if let Some(c) = &self.cipher { let cipher = SerpentCbc::new_var(&c.priv_key, &c.iv).unwrap(); @@ -55,7 +60,6 @@ impl KvStore { match &mut self.container.get_mut(&key) { Some(kv_element) => { if !kv_element.locked { - let mime_type = tree_magic::from_u8(value.as_ref()); kv_element.data = value; kv_element.mime_type = mime_type; } diff --git a/src/main.rs b/src/main.rs index db0ee94..14b8def 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,11 @@ #[macro_use] extern crate clap; #[macro_use] -extern crate serde_derive; -#[macro_use] extern crate log; +extern crate serde; +#[macro_use] +extern crate serde_derive; +extern crate serde_json; extern crate block_modes; extern crate hex; diff --git a/src/server.rs b/src/server.rs index 008a96f..c14884c 100644 --- a/src/server.rs +++ b/src/server.rs @@ -159,11 +159,12 @@ pub fn routes_filter( .or(fs::dir("assets/webui/dist")) .and(webui_enabled) .or(warp::get().map(move || warp::reply::html(WELCOME_PAGE))) - .and(warp::path::end()); + .and(warp::path::end()) + .with(warp::log("lucid::server::webui")); let robots = warp::path("robots.txt") .and(path::end()) - .and(warp::get().map(|| "User-agent: *\nDisallow: /")); + .and(warp::get().map(|| "User-agent: *\nDisallow: /api")); let cors = warp::cors() .allow_methods(vec!["HEAD", "GET", "PUT", "POST", "PATCH", "DELETE"])