From: Felix Ableitner Date: Tue, 12 Nov 2019 00:27:16 +0000 (+0100) Subject: Implement nodeinfo support (fixes #144) X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/readmes/%22https:/hacktivis.me/%7Bthis.src%28%27jpg%27%29%7D?a=commitdiff_plain;h=fcf3252292a094b889dc07c470974e44fe6e7b00;p=lemmy.git Implement nodeinfo support (fixes #144) --- diff --git a/server/src/main.rs b/server/src/main.rs index 10f6026b..392b0bbb 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -5,11 +5,13 @@ extern crate diesel_migrations; use actix::prelude::*; use actix_files::NamedFile; use actix_web::*; +use actix_web::web::Json; use actix_web_actors::ws; use lemmy_server::db::establish_connection; use lemmy_server::websocket::server::*; use std::env; use std::time::{Duration, Instant}; +use serde::Serialize; embed_migrations!(); @@ -197,6 +199,7 @@ fn main() { .service(web::resource("/").to(index)) // static resources .service(actix_files::Files::new("/static", front_end_dir())) + .route("/nodeinfo/2.0.json", web::get().to(node_info)) }) .bind("0.0.0.0:8536") .unwrap() @@ -206,6 +209,56 @@ fn main() { let _ = sys.run(); } +#[derive(Serialize)] +struct Software { + name: String, + version: String, +} + +#[derive(Serialize)] +struct Usage { + users: Users, + localPosts: i32, + localComments: i32, +} + +#[derive(Serialize)] +struct Users { + total: i32, +} + +#[derive(Serialize)] +struct NodeInfo { + version: String, + software: Software, + protocols: [String; 0], + usage: Usage, + openRegistrations: bool, +} + +fn node_info() -> Result> { + // TODO: get info from database + // TODO: need to get lemmy version from somewhere else + let conn = establish_connection(); + let userCount = User_::count(conn) + let json = Json(NodeInfo { + version: "2.0".to_string(), + software: Software { + name: "lemmy".to_string(), + version: "0.1".to_string() + }, + protocols: [], // TODO: activitypub once that is implemented + usage: Usage { + users: Users { + total: 123, + }, + localPosts: 123, + localComments: 123, + }, + openRegistrations: true }); + return Ok(json); +} + fn index() -> Result { Ok(NamedFile::open(front_end_dir() + "/index.html")?) }