forked from LemmyNet/lemmy
parent
9c94e23fcd
commit
45671b555e
7 changed files with 72 additions and 68 deletions
@ -1,2 +1,4 @@ |
||||
ansible/inventory |
||||
ansible/passwords/ |
||||
build/ |
||||
.idea/ |
||||
|
@ -0,0 +1,60 @@ |
||||
use actix_web::web::Json; |
||||
use serde::Serialize; |
||||
use crate::db::establish_connection; |
||||
use crate::db::community_view::SiteView; |
||||
use actix_web::*; |
||||
use failure::Error; |
||||
use crate::version; |
||||
|
||||
#[derive(Serialize)] |
||||
pub struct Software { |
||||
name: String, |
||||
version: String, |
||||
} |
||||
|
||||
#[derive(Serialize)] |
||||
#[serde(rename_all = "camelCase")] |
||||
pub struct Usage { |
||||
users: Users, |
||||
local_posts: i64, |
||||
local_comments: i64, |
||||
} |
||||
|
||||
#[derive(Serialize)] |
||||
pub struct Users { |
||||
total: i64, |
||||
} |
||||
|
||||
#[derive(Serialize)] |
||||
#[serde(rename_all = "camelCase")] |
||||
pub struct NodeInfo { |
||||
version: String, |
||||
software: Software, |
||||
protocols: [String; 0], |
||||
usage: Usage, |
||||
open_registrations: bool, |
||||
} |
||||
|
||||
pub fn node_info() -> Result<Json<NodeInfo>, Error> { |
||||
let conn = establish_connection(); |
||||
let site_view = match SiteView::read(&conn) { |
||||
Ok(site_view) => site_view, |
||||
Err(_e) => return Err(_e)?, |
||||
}; |
||||
let json = Json(NodeInfo { |
||||
version: "2.0".to_string(), |
||||
software: Software { |
||||
name: "lemmy".to_string(), |
||||
version: version::VERSION.to_string(), |
||||
}, |
||||
protocols: [], // TODO: put 'activitypub' once that is implemented
|
||||
usage: Usage { |
||||
users: Users { |
||||
total: site_view.number_of_users, |
||||
}, |
||||
local_posts: site_view.number_of_posts, |
||||
local_comments: site_view.number_of_comments, |
||||
}, |
||||
open_registrations: true }); |
||||
return Ok(json); |
||||
} |
@ -0,0 +1 @@ |
||||
pub const VERSION: &'static str = "v0.4.0-6-gd767e94"; |
@ -1,11 +0,0 @@ |
||||
const fs = require('fs'); |
||||
|
||||
exports.setVersion = function() { |
||||
let revision = require('child_process') |
||||
.execSync('git describe --tags --long') |
||||
.toString().trim(); |
||||
let line = `export let version: string = "${revision}";`; |
||||
fs.writeFileSync("./src/version.ts", line); |
||||
} |
||||
|
||||
this.setVersion() |
Reference in new issue