chore: new helper, renamed base->domain
This commit is contained in:
parent
4d4cbe0ef8
commit
1ca97668a1
2 changed files with 12 additions and 8 deletions
|
@ -23,7 +23,7 @@ struct ContextInner {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! url {
|
macro_rules! url {
|
||||||
($ctx:expr, $($args: tt)*) => {
|
($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
|
&self.0.db
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn base(&self) -> &str {
|
pub fn domain(&self) -> &str {
|
||||||
&self.0.domain
|
&self.0.domain
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,6 +83,10 @@ impl Context {
|
||||||
&self.0.protocol
|
&self.0.protocol
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn base(&self) -> String {
|
||||||
|
format!("{}{}", self.0.protocol, self.0.domain)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn uri(&self, entity: &str, id: String) -> String {
|
pub fn uri(&self, entity: &str, id: String) -> String {
|
||||||
if id.starts_with("http") { id } else {
|
if id.starts_with("http") { id } else {
|
||||||
format!("{}{}/{}/{}", self.0.protocol, self.0.domain, entity, id)
|
format!("{}{}/{}/{}", self.0.protocol, self.0.domain, entity, id)
|
||||||
|
@ -182,7 +186,7 @@ impl Context {
|
||||||
let mut deliveries = Vec::new();
|
let mut deliveries = Vec::new();
|
||||||
for target in targets.iter()
|
for target in targets.iter()
|
||||||
.filter(|to| !to.is_empty())
|
.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)
|
.filter(|to| to != &apb::target::PUBLIC)
|
||||||
{
|
{
|
||||||
// TODO fetch concurrently
|
// TODO fetch concurrently
|
||||||
|
|
|
@ -88,7 +88,7 @@ impl Fetcher for Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
let user = Self::request(
|
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::<serde_json::Value>().await?;
|
).await?.json::<serde_json::Value>().await?;
|
||||||
let user_model = model::user::Model::new(&user)?;
|
let user_model = model::user::Model::new(&user)?;
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ impl Fetcher for Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
let activity = Self::request(
|
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::<serde_json::Value>().await?;
|
).await?.json::<serde_json::Value>().await?;
|
||||||
|
|
||||||
let addressed = activity.addressed();
|
let addressed = activity.addressed();
|
||||||
|
@ -125,7 +125,7 @@ impl Fetcher for Context {
|
||||||
}
|
}
|
||||||
|
|
||||||
let object = Self::request(
|
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::<serde_json::Value>().await?;
|
).await?.json::<serde_json::Value>().await?;
|
||||||
|
|
||||||
let addressed = object.addressed();
|
let addressed = object.addressed();
|
||||||
|
@ -170,9 +170,9 @@ pub trait Fetchable : Sync + Send {
|
||||||
impl Fetchable for apb::Node<serde_json::Value> {
|
impl Fetchable for apb::Node<serde_json::Value> {
|
||||||
async fn fetch(&mut self, ctx: &crate::server::Context) -> crate::Result<&mut Self> {
|
async fn fetch(&mut self, ctx: &crate::server::Context) -> crate::Result<&mut Self> {
|
||||||
if let apb::Node::Link(uri) = 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;
|
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?
|
.await?
|
||||||
.json::<serde_json::Value>()
|
.json::<serde_json::Value>()
|
||||||
.await?
|
.await?
|
||||||
|
|
Loading…
Reference in a new issue