Make it possible to test the federation locally

And explain how to do it in the README
This commit is contained in:
Bat
2018-05-02 13:47:46 +01:00
parent 5f43f783b6
commit ac1a111d7b
7 changed files with 46 additions and 10 deletions
+6 -5
View File
@@ -1,7 +1,8 @@
use diesel::PgConnection;
use reqwest::Client;
use activity_pub::{activity_pub, ActivityPub, context};
use BASE_URL;
use activity_pub::{activity_pub, ActivityPub, context, ap_url};
use activity_pub::activity::Activity;
use models::instance::Instance;
@@ -40,7 +41,7 @@ pub trait Actor: Sized {
"summary": "",
"url": self.compute_id(conn),
"endpoints": {
"sharedInbox": "https://plu.me/inbox"
"sharedInbox": ap_url(format!("{}/inbox", BASE_URL.as_str()))
}
}))
}
@@ -58,12 +59,12 @@ pub trait Actor: Sized {
}
fn compute_id(&self, conn: &PgConnection) -> String {
format!(
"https://{instance}/{prefix}/{user}",
ap_url(format!(
"{instance}/{prefix}/{user}",
instance = self.get_instance(conn).public_domain,
prefix = Self::get_box_prefix(),
user = self.get_actor_id()
)
))
}
fn send_to_inbox(&self, conn: &PgConnection, act: Activity) {
+11
View File
@@ -16,6 +16,17 @@ pub type ActivityPub = Content<Json>;
pub const CONTEXT_URL: &'static str = "https://www.w3.org/ns/activitystreams";
pub const PUBLIC_VISIBILTY: &'static str = "https://www.w3.org/ns/activitystreams#Public";
#[cfg(debug_assertions)]
pub fn ap_url(url: String) -> String {
format!("http://{}", url)
}
#[cfg(not(debug_assertions))]
pub fn ap_url(url: String) -> String {
format!("https://{}", url)
}
pub fn context() -> serde_json::Value {
json!([
CONTEXT_URL,
+3 -1
View File
@@ -4,6 +4,8 @@ use reqwest::header::{Accept, qitem};
use reqwest::mime::Mime;
use serde_json;
use activity_pub::ap_url;
pub trait Webfinger {
fn webfinger_subject(&self, conn: &PgConnection) -> String;
fn webfinger_aliases(&self, conn: &PgConnection) -> Vec<String>;
@@ -26,7 +28,7 @@ pub trait Webfinger {
pub fn resolve(acct: String) -> Result<String, String> {
let instance = acct.split("@").last().unwrap();
let url = format!("https://{}/.well-known/webfinger?resource=acct:{}", instance, acct);
let url = ap_url(format!("{}/.well-known/webfinger?resource=acct:{}", instance, acct));
Client::new()
.get(&url[..])
.header(Accept(vec![qitem("application/jrd+json".parse::<Mime>().unwrap())]))
+1 -1
View File
@@ -40,7 +40,7 @@ lazy_static! {
.unwrap_or(format!("127.0.0.1:{}", env::var("ROCKET_PORT").unwrap_or(String::from("8000"))));
pub static ref DB_URL: String = env::var("DB_URL")
.unwrap_or(format!("DATABASE_URL=postgres://plume:plume@localhost/{}", env::var("DB_TABLE").unwrap_or(String::from("plume"))));
.unwrap_or(format!("postgres://plume:plume@localhost/{}", env::var("DB_NAME").unwrap_or(String::from("plume"))));
}
type PgPool = Pool<ConnectionManager<PgConnection>>;
+3 -2
View File
@@ -2,6 +2,7 @@ use rocket::http::ContentType;
use rocket::response::Content;
use BASE_URL;
use activity_pub::ap_url;
use activity_pub::webfinger::Webfinger;
use db_conn::DbConn;
use models::blogs::Blog;
@@ -12,9 +13,9 @@ fn host_meta() -> String {
format!(r#"
<?xml version="1.0"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
<Link rel="lrdd" type="application/xrd+xml" template="https://{domain}/.well-known/webfinger?resource={{uri}}"/>
<Link rel="lrdd" type="application/xrd+xml" template="{url}"/>
</XRD>
"#, domain = BASE_URL.as_str())
"#, url = ap_url(format!("{domain}/.well-known/webfinger?resource={{uri}}", domain = BASE_URL.as_str())))
}
#[derive(FromForm)]