2021-04-09 00:22:17 +00:00
|
|
|
/// http://nodeinfo.diaspora.software/schema.html
|
|
|
|
|
|
|
|
use serde::Serialize;
|
|
|
|
|
|
|
|
use crate::config::Config;
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
struct Software {
|
|
|
|
name: String,
|
|
|
|
version: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
struct Services {
|
|
|
|
inbound: Vec<String>,
|
|
|
|
outbound: Vec<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
2022-07-07 18:55:47 +00:00
|
|
|
pub struct Users {
|
|
|
|
pub total: i64,
|
2021-04-09 00:22:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
2022-07-07 18:55:47 +00:00
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct Usage {
|
|
|
|
pub users: Users,
|
|
|
|
pub local_posts: i64,
|
2021-04-09 00:22:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
struct Metadata {
|
|
|
|
node_name: String,
|
|
|
|
node_description: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct NodeInfo20 {
|
|
|
|
version: String,
|
|
|
|
software: Software,
|
|
|
|
protocols: Vec<String>,
|
|
|
|
services: Services,
|
|
|
|
open_registrations: bool,
|
|
|
|
usage: Usage,
|
|
|
|
metadata: Metadata,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl NodeInfo20 {
|
2022-07-07 18:55:47 +00:00
|
|
|
pub fn new(config: &Config, usage: Usage) -> Self {
|
2021-04-09 00:22:17 +00:00
|
|
|
let software = Software {
|
|
|
|
name: "mitra".to_string(),
|
|
|
|
version: config.version.clone(),
|
|
|
|
};
|
2022-04-13 17:45:47 +00:00
|
|
|
let services = Services {
|
|
|
|
inbound: vec![],
|
|
|
|
outbound: vec!["atom1.0".to_string()],
|
|
|
|
};
|
2021-04-09 00:22:17 +00:00
|
|
|
let metadata = Metadata {
|
|
|
|
node_name: config.instance_title.clone(),
|
|
|
|
node_description: config.instance_short_description.clone(),
|
|
|
|
};
|
|
|
|
Self {
|
|
|
|
version: "2.0".to_string(),
|
|
|
|
software,
|
|
|
|
protocols: vec!["activitypub".to_string()],
|
|
|
|
services,
|
|
|
|
open_registrations: config.registrations_open,
|
2022-07-07 18:55:47 +00:00
|
|
|
usage,
|
2021-04-09 00:22:17 +00:00
|
|
|
metadata,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|