1 use crate::db::site_view::SiteView;
4 use actix_web::body::Body;
6 use actix_web::HttpResponse;
7 use diesel::r2d2::{ConnectionManager, Pool};
8 use diesel::PgConnection;
11 pub fn config(cfg: &mut web::ServiceConfig) {
13 .route("/nodeinfo/2.0.json", web::get().to(node_info))
14 .route("/.well-known/nodeinfo", web::get().to(node_info_well_known));
17 async fn node_info_well_known() -> HttpResponse<Body> {
18 let node_info = NodeInfoWellKnown {
19 links: NodeInfoWellKnownLinks {
20 rel: "http://nodeinfo.diaspora.software/ns/schema/2.0".to_string(),
21 href: format!("https://{}/nodeinfo/2.0.json", Settings::get().hostname),
24 HttpResponse::Ok().json(node_info)
28 db: web::Data<Pool<ConnectionManager<PgConnection>>>,
29 ) -> Result<HttpResponse, actix_web::Error> {
30 let res = web::block(move || {
32 let site_view = match SiteView::read(&conn) {
33 Ok(site_view) => site_view,
34 Err(_) => return Err(format_err!("not_found")),
36 let protocols = if Settings::get().federation_enabled {
37 vec!["activitypub".to_string()]
42 version: "2.0".to_string(),
43 software: NodeInfoSoftware {
44 name: "lemmy".to_string(),
45 version: version::VERSION.to_string(),
48 usage: NodeInfoUsage {
49 users: NodeInfoUsers {
50 total: site_view.number_of_users,
52 local_posts: site_view.number_of_posts,
53 local_comments: site_view.number_of_comments,
54 open_registrations: site_view.open_registration,
59 .map(|json| HttpResponse::Ok().json(json))
60 .map_err(|_| HttpResponse::InternalServerError())?;
65 struct NodeInfoWellKnown {
66 links: NodeInfoWellKnownLinks,
70 struct NodeInfoWellKnownLinks {
78 software: NodeInfoSoftware,
79 protocols: Vec<String>,
84 struct NodeInfoSoftware {
90 #[serde(rename_all = "camelCase")]
91 struct NodeInfoUsage {
95 open_registrations: bool,
99 struct NodeInfoUsers {