mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-24 15:26:20 +00:00
got it working
This commit is contained in:
parent
fcf3252292
commit
4f116dc758
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 --long)';" > "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 --long)\";" > "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
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -5,13 +5,12 @@ 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;
|
||||
use lemmy_server::nodeinfo;
|
||||
|
||||
embed_migrations!();
|
||||
|
||||
|
@ -199,7 +198,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))
|
||||
.route("/nodeinfo/2.0.json", web::get().to(nodeinfo::node_info))
|
||||
})
|
||||
.bind("0.0.0.0:8536")
|
||||
.unwrap()
|
||||
|
@ -209,56 +208,6 @@ 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")?)
|
||||
}
|
||||
|
|
60
server/src/nodeinfo.rs
Normal file
60
server/src/nodeinfo.rs
Normal file
|
@ -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);
|
||||
}
|
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-6-gd767e94";
|
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()
|
Loading…
Reference in a new issue