mirror of
https://github.com/LemmyNet/lemmy
synced 2024-11-23 13:03:11 +00:00
Merge branch 'nodeinfo' of https://github.com/Nutomic/lemmy into Nutomic-nodeinfo
This commit is contained in:
commit
5d02299287
10 changed files with 64 additions and 17 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
|||
ansible/inventory
|
||||
ansible/passwords/
|
||||
build/
|
||||
.idea/
|
||||
|
|
9
docker/dev/deploy.sh
vendored
9
docker/dev/deploy.sh
vendored
|
@ -6,10 +6,11 @@ new_tag="$1"
|
|||
git tag $new_tag
|
||||
|
||||
# Setting the version on the front end
|
||||
pushd ../../ui/
|
||||
node set_version.js
|
||||
git add src/version.ts
|
||||
popd
|
||||
echo "export let version: string = '$(git describe --tags)';" > "ui/src/version.ts"
|
||||
git add "ui/src/version.ts"
|
||||
# Setting the version on the backend
|
||||
echo "pub const VERSION: &'static str = \"$(git describe --tags)\";" > "server/src/version.rs"
|
||||
git add "server/src/version.rs"
|
||||
|
||||
# Changing the docker-compose prod
|
||||
sed -i "s/dessalines\/lemmy:.*/dessalines\/lemmy:$new_tag/" ../prod/docker-compose.yml
|
||||
|
|
1
server/Cargo.lock
generated
vendored
1
server/Cargo.lock
generated
vendored
|
@ -1833,6 +1833,7 @@ name = "serde_json"
|
|||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ryu 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.97 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
2
server/Cargo.toml
vendored
2
server/Cargo.toml
vendored
|
@ -12,7 +12,7 @@ bcrypt = "0.5.0"
|
|||
activitypub = "0.1.5"
|
||||
chrono = { version = "0.4.7", features = ["serde"] }
|
||||
failure = "0.1.5"
|
||||
serde_json = "1.0.40"
|
||||
serde_json = { version = "1.0.40", features = ["preserve_order"]}
|
||||
serde = { version = "1.0.94", features = ["derive"] }
|
||||
actix = "0.8.3"
|
||||
actix-web = "1.0"
|
||||
|
|
|
@ -27,6 +27,8 @@ pub mod apub;
|
|||
pub mod db;
|
||||
pub mod schema;
|
||||
pub mod websocket;
|
||||
pub mod nodeinfo;
|
||||
pub mod version;
|
||||
|
||||
use chrono::{DateTime, NaiveDateTime, Utc};
|
||||
use dotenv::dotenv;
|
||||
|
|
|
@ -7,6 +7,7 @@ use actix_files::NamedFile;
|
|||
use actix_web::*;
|
||||
use actix_web_actors::ws;
|
||||
use lemmy_server::db::establish_connection;
|
||||
use lemmy_server::nodeinfo;
|
||||
use lemmy_server::websocket::server::*;
|
||||
use std::env;
|
||||
use std::time::{Duration, Instant};
|
||||
|
@ -189,6 +190,7 @@ fn main() {
|
|||
// Start chat server actor in separate thread
|
||||
let server = ChatServer::default().start();
|
||||
// Create Http server with websocket support
|
||||
|
||||
HttpServer::new(move || {
|
||||
App::new()
|
||||
.data(server.clone())
|
||||
|
@ -197,6 +199,8 @@ 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(nodeinfo::node_info))
|
||||
.route("/.well-known/nodeinfo", web::get().to(nodeinfo::node_info_well_known))
|
||||
})
|
||||
.bind("0.0.0.0:8536")
|
||||
.unwrap()
|
||||
|
|
47
server/src/nodeinfo.rs
Normal file
47
server/src/nodeinfo.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
use crate::db::community_view::SiteView;
|
||||
use crate::db::establish_connection;
|
||||
use crate::version;
|
||||
use crate::Settings;
|
||||
use actix_web::HttpResponse;
|
||||
use actix_web::body::Body;
|
||||
use serde_json::json;
|
||||
|
||||
pub fn node_info_well_known() -> HttpResponse<Body> {
|
||||
let json = json!({
|
||||
"links": {
|
||||
"rel": "http://nodeinfo.diaspora.software/ns/schema/2.0",
|
||||
"href": format!("https://{}/nodeinfo/2.0.json", Settings::get().hostname),
|
||||
}
|
||||
});
|
||||
|
||||
return HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(json.to_string());
|
||||
}
|
||||
|
||||
pub fn node_info() -> HttpResponse<Body> {
|
||||
let conn = establish_connection();
|
||||
let site_view = match SiteView::read(&conn) {
|
||||
Ok(site_view) => site_view,
|
||||
Err(_e) => return HttpResponse::InternalServerError().finish(),
|
||||
};
|
||||
let json = json!({
|
||||
"version": "2.0",
|
||||
"software": {
|
||||
"name": "lemmy",
|
||||
"version": version::VERSION,
|
||||
},
|
||||
"protocols": [],
|
||||
"usage": {
|
||||
"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 HttpResponse::Ok()
|
||||
.content_type("application/json")
|
||||
.body(json.to_string());
|
||||
}
|
1
server/src/version.rs
Normal file
1
server/src/version.rs
Normal file
|
@ -0,0 +1 @@
|
|||
pub const VERSION: &'static str = "v0.4.0.2-7-g7c052f5";
|
11
ui/set_version.js
vendored
11
ui/set_version.js
vendored
|
@ -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()
|
2
ui/src/version.ts
vendored
2
ui/src/version.ts
vendored
|
@ -1 +1 @@
|
|||
export let version: string = 'v0.4.0.2-0-g062d7f2';
|
||||
export let version: string = 'v0.4.0.2-7-g7c052f5';
|
||||
|
|
Loading…
Reference in a new issue