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())]))