Add hook for incoming activities
This commit is contained in:
parent
7e876dd5ce
commit
9f56f5390c
1 changed files with 6 additions and 1 deletions
|
|
@ -10,14 +10,16 @@ use crate::{
|
|||
};
|
||||
use actix_web::{web::Bytes, HttpRequest, HttpResponse};
|
||||
use serde::de::DeserializeOwned;
|
||||
use std::future::Future;
|
||||
use tracing::debug;
|
||||
|
||||
/// Handles incoming activities, verifying HTTP signatures and other checks
|
||||
///
|
||||
/// After successful validation, activities are passed to respective [trait@ActivityHandler].
|
||||
pub async fn receive_activity<Activity, ActorT, Datatype>(
|
||||
pub async fn receive_activity<Activity, ActorT, Datatype, Fut>(
|
||||
request: HttpRequest,
|
||||
body: Bytes,
|
||||
hook: impl FnOnce(&Activity, &ActorT) -> Fut,
|
||||
data: &Data<Datatype>,
|
||||
) -> Result<HttpResponse, <Activity as ActivityHandler>::Error>
|
||||
where
|
||||
|
|
@ -27,6 +29,7 @@ where
|
|||
<Activity as ActivityHandler>::Error: From<Error> + From<<ActorT as Object>::Error>,
|
||||
<ActorT as Object>::Error: From<Error>,
|
||||
Datatype: Clone,
|
||||
Fut: Future<Output = Result<(), <Activity as ActivityHandler>::Error>>,
|
||||
{
|
||||
let digest_header = request
|
||||
.headers()
|
||||
|
|
@ -41,6 +44,8 @@ where
|
|||
let uri = http_compat::uri(request.uri());
|
||||
verify_signature(&headers, &method, &uri, actor.public_key_pem())?;
|
||||
|
||||
hook(&activity, &actor).await?;
|
||||
|
||||
debug!("Receiving activity {}", activity.id().to_string());
|
||||
activity.verify(data).await?;
|
||||
activity.receive(data).await?;
|
||||
|
|
|
|||
Loading…
Reference in a new issue