2020-03-20 00:55:11 +00:00
|
|
|
use crate::config::{Config, UrlKind};
|
2020-03-19 19:05:16 +00:00
|
|
|
use actix_web::{web, Responder};
|
|
|
|
use actix_webfinger::Link;
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
2020-03-20 00:55:11 +00:00
|
|
|
pub async fn well_known(config: web::Data<Config>) -> impl Responder {
|
2020-03-19 19:05:16 +00:00
|
|
|
web::Json(Link {
|
|
|
|
rel: "http://nodeinfo.diaspora.software/ns/schema/2.0".to_owned(),
|
2020-03-20 00:55:11 +00:00
|
|
|
href: Some(config.generate_url(UrlKind::NodeInfo)),
|
2020-03-19 19:05:16 +00:00
|
|
|
template: None,
|
|
|
|
kind: None,
|
|
|
|
})
|
|
|
|
.with_header("Content-Type", "application/jrd+json")
|
|
|
|
}
|
|
|
|
|
2020-03-20 00:55:11 +00:00
|
|
|
pub async fn route(config: web::Data<Config>) -> web::Json<NodeInfo> {
|
2020-03-19 19:05:16 +00:00
|
|
|
web::Json(NodeInfo {
|
|
|
|
version: NodeInfoVersion,
|
|
|
|
software: Software {
|
2020-03-20 00:55:11 +00:00
|
|
|
name: config.software_name(),
|
|
|
|
version: config.software_version(),
|
2020-03-19 19:05:16 +00:00
|
|
|
},
|
|
|
|
protocols: vec![Protocol::ActivityPub],
|
|
|
|
services: vec![],
|
|
|
|
open_registrations: false,
|
|
|
|
usage: Usage {
|
|
|
|
local_posts: 0,
|
|
|
|
local_comments: 0,
|
|
|
|
},
|
|
|
|
metadata: Metadata::default(),
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct NodeInfo {
|
|
|
|
version: NodeInfoVersion,
|
|
|
|
software: Software,
|
|
|
|
protocols: Vec<Protocol>,
|
|
|
|
services: Vec<Service>,
|
|
|
|
open_registrations: bool,
|
|
|
|
usage: Usage,
|
|
|
|
metadata: Metadata,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default)]
|
|
|
|
pub struct NodeInfoVersion;
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default, serde::Serialize)]
|
|
|
|
pub struct Software {
|
|
|
|
name: String,
|
|
|
|
version: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
pub enum Protocol {
|
|
|
|
ActivityPub,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, serde::Serialize)]
|
|
|
|
pub enum Service {}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default, serde::Serialize)]
|
|
|
|
#[serde(rename_all = "camelCase")]
|
|
|
|
pub struct Usage {
|
|
|
|
local_posts: u64,
|
|
|
|
local_comments: u64,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default, serde::Serialize)]
|
|
|
|
#[serde(transparent)]
|
|
|
|
pub struct Metadata(pub HashMap<String, serde_json::Value>);
|
|
|
|
|
|
|
|
impl serde::ser::Serialize for NodeInfoVersion {
|
|
|
|
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
|
|
|
where
|
|
|
|
S: serde::ser::Serializer,
|
|
|
|
{
|
|
|
|
serializer.serialize_str("2.0")
|
|
|
|
}
|
|
|
|
}
|