diff --git a/crates/ptth_relay/src/config.rs b/crates/ptth_relay/src/config.rs index 389340e..4e204f6 100644 --- a/crates/ptth_relay/src/config.rs +++ b/crates/ptth_relay/src/config.rs @@ -15,10 +15,25 @@ use crate::{ }, }; +/// Machine-editable configs. +/// These are stored in the `data` directory and shouldn't be touched by +/// humans. ptth_relay will re-write them while it's running. + +mod machine_editable { + use serde::{Deserialize, Serialize}; + + use super::file::Server; + + #[derive (Deserialize, Serialize)] + pub struct Config { + pub servers: Option >, + } +} + /// Config fields as they are loaded from the config file pub mod file { - use serde::Deserialize; + use serde::{Deserialize, Serialize}; use crate::key_validity::{ BlakeHashWrapper, @@ -26,7 +41,7 @@ pub mod file { Valid30Days, }; - #[derive (Deserialize)] + #[derive (Deserialize, Serialize)] pub struct Server { /// This is duplicated in the hashmap, but it's not a problem pub name: String, diff --git a/crates/ptth_relay/src/key_validity.rs b/crates/ptth_relay/src/key_validity.rs index 95ddc11..bc19223 100644 --- a/crates/ptth_relay/src/key_validity.rs +++ b/crates/ptth_relay/src/key_validity.rs @@ -12,6 +12,7 @@ use serde::{ }, Deserialize, Deserializer, + Serialize, }; #[derive (Copy, Clone, PartialEq, Eq)] @@ -70,6 +71,13 @@ impl <'de> Deserialize <'de> for BlakeHashWrapper { } } +impl Serialize for BlakeHashWrapper { + fn serialize (&self, serializer: S) -> Result + { + serializer.serialize_str (&self.encode_base64 ()) + } +} + pub struct Valid7Days; pub struct Valid30Days; //pub struct Valid90Days; @@ -166,9 +174,19 @@ impl ScraperKey { #[cfg (test)] mod tests { use chrono::{Utc}; + use serde_json::json; use super::*; use KeyValidity::*; + #[test] + fn roundtrip_tripcode () { + let tripcode = "m8vG/sQnsn/87CQ5Ob6wMJeAnMKtXYfCBLNZ1SrSkvI="; + + let j = json! ({ + "tripcode": tripcode, + }); + } + #[test] fn duration_negative () { let zero_time = Utc::now ();