Use more env vars for config

It will make it easier to test federation
This commit is contained in:
Bat
2018-05-02 12:53:42 +01:00
parent 9fdfb2b25e
commit 5f43f783b6
14 changed files with 30 additions and 31 deletions
+1 -4
View File
@@ -8,7 +8,6 @@ use schema::{instances, users};
#[derive(Identifiable, Queryable)]
pub struct Instance {
pub id: i32,
pub local_domain: String,
pub public_domain: String,
pub name: String,
pub local: bool,
@@ -19,7 +18,6 @@ pub struct Instance {
#[derive(Insertable)]
#[table_name = "instances"]
pub struct NewInstance {
pub local_domain: String,
pub public_domain: String,
pub name: String,
pub local: bool
@@ -44,10 +42,9 @@ impl Instance {
Instance::get_local(conn).unwrap().id
}
pub fn insert<'a>(conn: &PgConnection, loc_dom: String, pub_dom: String, name: String, local: bool) -> Instance {
pub fn insert<'a>(conn: &PgConnection, pub_dom: String, name: String, local: bool) -> Instance {
diesel::insert_into(instances::table)
.values(NewInstance {
local_domain: loc_dom,
public_domain: pub_dom,
name: name,
local: local
+3 -2
View File
@@ -10,6 +10,7 @@ use rocket::outcome::IntoOutcome;
use serde_json;
use url::Url;
use BASE_URL;
use activity_pub::activity::Activity;
use activity_pub::actor::{ActorType, Actor};
use activity_pub::inbox::Inbox;
@@ -138,7 +139,7 @@ impl User {
let instance = match Instance::get_by_domain(conn, inst.clone()) {
Some(instance) => instance,
None => {
Instance::insert(conn, String::from(""), inst.clone(), inst.clone(), false)
Instance::insert(conn, inst.clone(), inst.clone(), false)
}
};
User::insert(conn, NewUser {
@@ -249,7 +250,7 @@ impl Actor for User {
None => {
// The requested user was not in the DB
// We try to fetch it if it is remote
if Url::parse(url.as_ref()).unwrap().host_str().unwrap() != Instance::get_local(conn).unwrap().public_domain {
if Url::parse(url.as_ref()).unwrap().host_str().unwrap() != BASE_URL.as_str() {
Some(User::fetch_from_url(conn, url).unwrap())
} else {
None