2023-04-21 23:39:52 +00:00
|
|
|
use crate::config::MagnetarConfig;
|
|
|
|
use axum::extract::State;
|
|
|
|
use axum::Json;
|
|
|
|
use magnetar_core::web_model::rel::{RelNodeInfo20, RelNodeInfo21};
|
|
|
|
use magnetar_core::web_model::Rel;
|
|
|
|
use magnetar_nodeinfo::version_1_0::{
|
|
|
|
NodeInfo10Services, NodeInfo10Software, NodeInfo10Usage, NodeInfo10UsageUsers,
|
|
|
|
};
|
|
|
|
use magnetar_nodeinfo::version_2_0::NodeInfo20;
|
|
|
|
use magnetar_nodeinfo::version_2_1::{NodeInfo21, NodeInfo21Software};
|
|
|
|
use serde::Serialize;
|
2023-05-18 23:51:58 +00:00
|
|
|
use serde_json::{json, Value};
|
2023-04-21 23:39:52 +00:00
|
|
|
use std::collections::{HashMap, HashSet};
|
|
|
|
|
|
|
|
const NODEINFO_PATH: &str = "/nodeinfo";
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Serialize)]
|
|
|
|
pub struct NodeInfoLink {
|
|
|
|
rel: &'static str,
|
2023-04-22 00:21:02 +00:00
|
|
|
href: String,
|
2023-04-21 23:39:52 +00:00
|
|
|
}
|
|
|
|
|
2023-05-18 23:51:58 +00:00
|
|
|
pub async fn handle_nodeinfo(State(config): State<&'static MagnetarConfig>) -> Json<Value> {
|
|
|
|
let links = vec![
|
2023-04-21 23:39:52 +00:00
|
|
|
NodeInfoLink {
|
2023-04-22 00:21:02 +00:00
|
|
|
href: format!(
|
|
|
|
"{}://{}/nodeinfo/2.0",
|
|
|
|
config.networking.protocol, config.networking.host
|
|
|
|
),
|
2023-04-21 23:39:52 +00:00
|
|
|
rel: RelNodeInfo20.rel(),
|
|
|
|
},
|
|
|
|
NodeInfoLink {
|
2023-04-22 00:21:02 +00:00
|
|
|
href: format!(
|
|
|
|
"{}://{}/nodeinfo/2.1",
|
|
|
|
config.networking.protocol, config.networking.host
|
|
|
|
),
|
2023-04-21 23:39:52 +00:00
|
|
|
rel: RelNodeInfo21.rel(),
|
|
|
|
},
|
2023-05-18 23:51:58 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
let links_serialized = serde_json::to_value(links).unwrap();
|
|
|
|
|
|
|
|
Json(json!({ "links": links_serialized }))
|
2023-04-21 23:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn handle_nodeinfo_21(State(config): State<&'static MagnetarConfig>) -> Json<NodeInfo21> {
|
|
|
|
Json(NodeInfo21 {
|
|
|
|
software: NodeInfo21Software {
|
|
|
|
name: config.branding.name.clone(),
|
|
|
|
version: config.branding.version.clone(),
|
|
|
|
homepage: Some(config.branding.homepage.clone()),
|
|
|
|
repository: Some(config.branding.repository.clone()),
|
|
|
|
},
|
|
|
|
protocols: HashSet::from(["activitypub".to_owned()]),
|
|
|
|
services: NodeInfo10Services {
|
|
|
|
inbound: HashSet::new(),
|
|
|
|
outbound: HashSet::new(),
|
|
|
|
},
|
|
|
|
open_registrations: false,
|
|
|
|
usage: NodeInfo10Usage {
|
|
|
|
users: NodeInfo10UsageUsers {
|
|
|
|
total: Some(0),
|
|
|
|
active_halfyear: Some(0),
|
|
|
|
active_month: Some(0),
|
|
|
|
},
|
|
|
|
local_posts: Some(0),
|
|
|
|
local_comments: Some(0),
|
|
|
|
},
|
|
|
|
metadata: HashMap::new(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn handle_nodeinfo_20(State(config): State<&'static MagnetarConfig>) -> Json<NodeInfo20> {
|
|
|
|
Json(NodeInfo20 {
|
|
|
|
software: NodeInfo10Software {
|
|
|
|
name: config.branding.name.clone(),
|
|
|
|
version: config.branding.version.clone(),
|
|
|
|
},
|
|
|
|
protocols: HashSet::from(["activitypub".to_owned()]),
|
|
|
|
services: NodeInfo10Services {
|
|
|
|
inbound: HashSet::new(),
|
|
|
|
outbound: HashSet::new(),
|
|
|
|
},
|
|
|
|
open_registrations: false,
|
|
|
|
usage: NodeInfo10Usage {
|
|
|
|
users: NodeInfo10UsageUsers {
|
|
|
|
total: Some(0),
|
|
|
|
active_halfyear: Some(0),
|
|
|
|
active_month: Some(0),
|
|
|
|
},
|
|
|
|
local_posts: Some(0),
|
|
|
|
local_comments: None,
|
|
|
|
},
|
|
|
|
metadata: HashMap::new(),
|
|
|
|
})
|
|
|
|
}
|