1
0
Fork 0
mirror of https://github.com/Nutomic/ibis.git synced 2024-11-22 12:31:08 +00:00

Add basic nodeinfo

This commit is contained in:
Felix Ableitner 2024-03-08 16:49:00 +01:00
parent 31b720a15c
commit 11c3971d9e
2 changed files with 68 additions and 0 deletions

View file

@ -50,6 +50,7 @@ pub mod config;
pub mod database; pub mod database;
pub mod error; pub mod error;
pub mod federation; pub mod federation;
mod nodeinfo;
mod utils; mod utils;
const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations"); const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations");
@ -92,6 +93,7 @@ pub async fn start(config: IbisConfig) -> MyResult<()> {
.nest("", asset_routes()?) .nest("", asset_routes()?)
.nest(FEDERATION_ROUTES_PREFIX, federation_routes()) .nest(FEDERATION_ROUTES_PREFIX, federation_routes())
.nest("/api/v1", api_routes()) .nest("/api/v1", api_routes())
.nest("", nodeinfo::config())
.layer(FederationMiddleware::new(config)) .layer(FederationMiddleware::new(config))
.layer(CorsLayer::permissive()); .layer(CorsLayer::permissive());

66
src/backend/nodeinfo.rs Normal file
View file

@ -0,0 +1,66 @@
use crate::{
backend::{database::IbisData, error::MyResult},
common::utils::http_protocol_str,
};
use activitypub_federation::config::Data;
use axum::{routing::get, Json, Router};
use serde::{Deserialize, Serialize};
use url::Url;
pub fn config() -> Router {
Router::new()
.route("/nodeinfo/2.0.json", get(node_info))
.route("/.well-known/nodeinfo", get(node_info_well_known))
}
async fn node_info_well_known(data: Data<IbisData>) -> MyResult<Json<NodeInfoWellKnown>> {
Ok(Json(NodeInfoWellKnown {
links: vec![NodeInfoWellKnownLinks {
rel: Url::parse("http://nodeinfo.diaspora.software/ns/schema/2.0")?,
href: Url::parse(&format!(
"{}://{}/nodeinfo/2.0.json",
http_protocol_str(),
data.domain()
))?,
}],
}))
}
async fn node_info(data: Data<IbisData>) -> MyResult<Json<NodeInfo>> {
Ok(Json(NodeInfo {
version: "2.0".to_string(),
software: NodeInfoSoftware {
name: "ibis".to_string(),
version: env!("CARGO_PKG_VERSION").to_string(),
},
protocols: vec!["activitypub".to_string()],
open_registrations: data.config.registration_open,
}))
}
#[derive(Serialize, Deserialize, Debug)]
struct NodeInfoWellKnown {
pub links: Vec<NodeInfoWellKnownLinks>,
}
#[derive(Serialize, Deserialize, Debug)]
struct NodeInfoWellKnownLinks {
pub rel: Url,
pub href: Url,
}
#[derive(Serialize, Deserialize, Debug, Default)]
#[serde(rename_all = "camelCase", default)]
pub struct NodeInfo {
pub version: String,
pub software: NodeInfoSoftware,
pub protocols: Vec<String>,
pub open_registrations: bool,
}
#[derive(Serialize, Deserialize, Debug, Default)]
#[serde(default)]
pub struct NodeInfoSoftware {
pub name: String,
pub version: String,
}