fix: removed broken legacy nodeinfo, fix datetime

This commit is contained in:
əlemi 2023-10-18 03:46:12 +02:00
parent 588cc4bfbc
commit 231d27e00f
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 5 additions and 50 deletions

View file

@ -9,7 +9,7 @@ pub struct Model {
pub id: i32, pub id: i32,
pub domain: String, pub domain: String,
pub data: String, pub data: String,
pub updated: String, pub updated: ChronoDateTimeUtc,
} }
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

View file

@ -3,13 +3,14 @@ use serde_json::{Map, Value};
/// Node metadata for version detection only used for deserialization. /// Node metadata for version detection only used for deserialization.
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, PartialOrd, derive_more::Display)] #[derive(Debug, Clone, Serialize, Deserialize, PartialEq, PartialOrd, derive_more::Display)]
pub(crate) enum NodeVersion { pub enum NodeVersion {
V1_0 = 1000, V1_0 = 1000,
V1_1 = 1001, V1_1 = 1001,
V2_0 = 2000, V2_0 = 2000,
V2_1 = 2001, V2_1 = 2001,
} }
#[allow(unused)]
pub type NodeInfo<'a> = NodeInfoInternal<&'a str>; pub type NodeInfo<'a> = NodeInfoInternal<&'a str>;
pub type NodeInfoOwned = NodeInfoInternal<String>; pub type NodeInfoOwned = NodeInfoInternal<String>;
@ -30,23 +31,6 @@ pub struct NodeInfoInternal<T> {
pub metadata: Map<String, Value>, pub metadata: Map<String, Value>,
} }
/// Node legacy metadata about a server running in the federation, only used for deserialization.
#[derive(Debug, PartialEq, Deserialize)]
pub(crate) struct LegacyNodeInfo<'a> {
version: NodeVersion,
software: Software<&'a str>,
#[serde(default)]
services: Services<&'a str>,
#[serde(default)]
protocols: Services<&'a str>,
#[serde(rename = "openRegistrations", default)]
open_registrations: bool,
#[serde(default)]
usage: Usage,
#[serde(default)]
metadata: Map<String, Value>,
}
/// Software contains infos about software running on the node. /// Software contains infos about software running on the node.
#[derive(Debug, PartialEq, Serialize, Deserialize)] #[derive(Debug, PartialEq, Serialize, Deserialize)]
pub struct Software<T> { pub struct Software<T> {
@ -101,11 +85,12 @@ impl<'a> Services<&'a str> {
} }
} }
#[allow(unused)]
impl NodeInfo<'_> { impl NodeInfo<'_> {
/// Converts all internal `&str`s into `String`s. /// Converts all internal `&str`s into `String`s.
pub fn to_owned(&self) -> NodeInfoOwned { pub fn to_owned(&self) -> NodeInfoOwned {
NodeInfoOwned { NodeInfoOwned {
version: self.version.to_string(), version: self.version.clone(),
software: self.software.to_owned(), software: self.software.to_owned(),
protocols: self.protocols.iter().map(ToString::to_string).collect(), protocols: self.protocols.iter().map(ToString::to_string).collect(),
services: self.services.to_owned(), services: self.services.to_owned(),
@ -115,33 +100,3 @@ impl NodeInfo<'_> {
} }
} }
} }
impl<'a> From<LegacyNodeInfo<'a>> for NodeInfo<'a> {
fn from(other: LegacyNodeInfo<'a>) -> Self {
let mut combined_protocols: Vec<&'a str> = other
.protocols
.inbound
.into_iter()
.chain(other.protocols.outbound)
.collect();
combined_protocols.sort();
combined_protocols.dedup();
NodeInfo {
version: other.version,
software: other.software,
services: other.services,
protocols: combined_protocols,
open_registrations: other.open_registrations,
usage: other.usage,
metadata: other.metadata,
}
}
}
impl<'a> From<LegacyNodeInfo<'a>> for NodeInfoOwned {
fn from(value: LegacyNodeInfo<'a>) -> Self {
NodeInfo::from(value).to_owned()
}
}