1
0
Fork 0
forked from alemi/upub

chore: new helper, renamed base->domain

This commit is contained in:
əlemi 2024-04-20 04:26:16 +02:00
parent 4d4cbe0ef8
commit 1ca97668a1
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 12 additions and 8 deletions

View file

@ -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

View file

@ -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::<serde_json::Value>().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::<serde_json::Value>().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::<serde_json::Value>().await?;
let addressed = object.addressed();
@ -170,9 +170,9 @@ pub trait Fetchable : Sync + Send {
impl Fetchable for apb::Node<serde_json::Value> {
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::<serde_json::Value>()
.await?