diff --git a/plume-models/src/instance.rs b/plume-models/src/instance.rs index bf3d3929..f77447d5 100644 --- a/plume-models/src/instance.rs +++ b/plume-models/src/instance.rs @@ -42,6 +42,7 @@ pub struct NewInstance { lazy_static! { static ref LOCAL_INSTANCE: RwLock> = RwLock::new(None); + static ref INSTANCE_USER: RwLock> = RwLock::new(None); } impl Instance { @@ -57,6 +58,14 @@ impl Instance { .ok_or(Error::NotFound) } + pub fn set_local_user(u: User) { + INSTANCE_USER.write().unwrap().replace(u); + } + + pub fn get_local_user() -> Result { + INSTANCE_USER.read().unwrap().clone().ok_or(Error::NotFound) + } + pub fn get_local_uncached(conn: &Connection) -> Result { instances::table .filter(instances::local.eq(true)) diff --git a/plume-models/src/schema.rs b/plume-models/src/schema.rs index dc6d77fd..adde25e7 100644 --- a/plume-models/src/schema.rs +++ b/plume-models/src/schema.rs @@ -29,7 +29,6 @@ table! { is_owner -> Bool, } } - table! { blogs (id) { id -> Int4, diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index 37e27885..d087ef8c 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -230,20 +230,28 @@ impl User { } fn fetch(url: &str) -> Result { + let mut headers = plume_common::activity_pub::request::headers(); + headers.insert( + ACCEPT, + HeaderValue::from_str( + &ap_accept_header() + .into_iter() + .collect::>() + .join(", "), + )?, + ); + let lu = Instance::get_local_user()?; let mut res = ClientBuilder::new() .connect_timeout(Some(std::time::Duration::from_secs(5))) .build()? .get(url) + .headers(headers.clone()) .header( - ACCEPT, - HeaderValue::from_str( - &ap_accept_header() - .into_iter() - .collect::>() - .join(", "), - )?, + "Signature", + plume_common::activity_pub::request::signature(&lu, &headers).expect(""), ) .send()?; + let text = &res.text()?; // without this workaround, publicKey is not correctly deserialized let ap_sign = serde_json::from_str::(text)?;