mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-30 08:11:20 +00:00
Implement nodeinfo support (fixes #144)
This commit is contained in:
parent
51b69ef736
commit
9c94e23fcd
1 changed files with 53 additions and 0 deletions
|
@ -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<Json<NodeInfo>> {
|
||||
// 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<NamedFile, actix_web::error::Error> {
|
||||
Ok(NamedFile::open(front_end_dir() + "/index.html")?)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue