diff --git a/src/server/context.rs b/src/server/context.rs index 5c664d09..3e170312 100644 --- a/src/server/context.rs +++ b/src/server/context.rs @@ -23,7 +23,7 @@ struct ContextInner { #[macro_export] macro_rules! url { ($ctx:expr, $($args: tt)*) => { - format!("{}{}{}", $ctx.protocol(), $ctx.base(), format!($($args)*)) + format!("{}{}{}", $ctx.protocol(), $ctx.domain(), format!($($args)*)) }; } @@ -75,7 +75,7 @@ impl Context { &self.0.db } - pub fn base(&self) -> &str { + pub fn domain(&self) -> &str { &self.0.domain } @@ -83,6 +83,10 @@ impl Context { &self.0.protocol } + pub fn base(&self) -> String { + format!("{}{}", self.0.protocol, self.0.domain) + } + pub fn uri(&self, entity: &str, id: String) -> String { if id.starts_with("http") { id } else { format!("{}{}/{}/{}", self.0.protocol, self.0.domain, entity, id) @@ -182,7 +186,7 @@ impl Context { let mut deliveries = Vec::new(); for target in targets.iter() .filter(|to| !to.is_empty()) - .filter(|to| Context::server(to) != self.base()) + .filter(|to| Context::server(to) != self.domain()) .filter(|to| to != &apb::target::PUBLIC) { // TODO fetch concurrently diff --git a/src/server/fetcher.rs b/src/server/fetcher.rs index 7434ea3c..8d98fdd9 100644 --- a/src/server/fetcher.rs +++ b/src/server/fetcher.rs @@ -88,7 +88,7 @@ impl Fetcher for Context { } let user = Self::request( - Method::GET, id, None, &format!("https://{}", self.base()), &self.app().private_key, self.base(), + Method::GET, id, None, &format!("https://{}", self.domain()), &self.app().private_key, self.domain(), ).await?.json::().await?; let user_model = model::user::Model::new(&user)?; @@ -104,7 +104,7 @@ impl Fetcher for Context { } let activity = Self::request( - Method::GET, id, None, &format!("https://{}", self.base()), &self.app().private_key, self.base(), + Method::GET, id, None, &format!("https://{}", self.domain()), &self.app().private_key, self.domain(), ).await?.json::().await?; let addressed = activity.addressed(); @@ -125,7 +125,7 @@ impl Fetcher for Context { } let object = Self::request( - Method::GET, id, None, &format!("https://{}", self.base()), &self.app().private_key, self.base(), + Method::GET, id, None, &format!("https://{}", self.domain()), &self.app().private_key, self.domain(), ).await?.json::().await?; let addressed = object.addressed(); @@ -170,9 +170,9 @@ pub trait Fetchable : Sync + Send { impl Fetchable for apb::Node { async fn fetch(&mut self, ctx: &crate::server::Context) -> crate::Result<&mut Self> { if let apb::Node::Link(uri) = self { - let from = format!("{}{}", ctx.protocol(), ctx.base()); // TODO helper to avoid this? + let from = format!("{}{}", ctx.protocol(), ctx.domain()); // TODO helper to avoid this? let pkey = &ctx.app().private_key; - *self = Context::request(Method::GET, uri.href(), None, &from, pkey, ctx.base()) + *self = Context::request(Method::GET, uri.href(), None, &from, pkey, ctx.domain()) .await? .json::() .await?