1 extern crate lazy_static;
2 use crate::db::site_view::SiteView;
5 use actix_web::body::Body;
7 use actix_web::HttpResponse;
8 use diesel::r2d2::{ConnectionManager, Pool};
9 use diesel::PgConnection;
12 pub fn config(cfg: &mut web::ServiceConfig) {
14 .route("/nodeinfo/2.0.json", web::get().to(node_info))
15 .route("/.well-known/nodeinfo", web::get().to(node_info_well_known));
18 async fn node_info_well_known() -> HttpResponse<Body> {
19 let node_info = NodeInfoWellKnown {
20 links: NodeInfoWellKnownLinks {
21 rel: "http://nodeinfo.diaspora.software/ns/schema/2.0".to_string(),
22 href: format!("https://{}/nodeinfo/2.0.json", Settings::get().hostname),
25 HttpResponse::Ok().json(node_info)
29 db: web::Data<Pool<ConnectionManager<PgConnection>>>,
30 ) -> Result<HttpResponse, actix_web::Error> {
31 let res = web::block(move || {
33 let site_view = match SiteView::read(&conn) {
34 Ok(site_view) => site_view,
35 Err(_) => return Err(format_err!("not_found")),
37 let protocols = if Settings::get().federation_enabled {
38 vec!["activitypub".to_string()]
43 version: "2.0".to_string(),
44 software: NodeInfoSoftware {
45 name: "lemmy".to_string(),
46 version: version::VERSION.to_string(),
49 usage: NodeInfoUsage {
50 users: NodeInfoUsers {
51 total: site_view.number_of_users,
53 local_posts: site_view.number_of_posts,
54 local_comments: site_view.number_of_comments,
55 open_registrations: site_view.open_registration,
60 .map(|json| HttpResponse::Ok().json(json))
61 .map_err(|_| HttpResponse::InternalServerError())?;
66 struct NodeInfoWellKnown {
67 links: NodeInfoWellKnownLinks,
71 struct NodeInfoWellKnownLinks {
79 software: NodeInfoSoftware,
80 protocols: Vec<String>,
85 struct NodeInfoSoftware {
91 #[serde(rename_all = "camelCase")]
92 struct NodeInfoUsage {
96 open_registrations: bool,
100 struct NodeInfoUsers {