From b62b461305cc10393ea3b1530fd7982d0acc091f Mon Sep 17 00:00:00 2001 From: alemi Date: Mon, 22 Apr 2024 04:23:11 +0200 Subject: [PATCH] fix: dispatcher fetch app key for app deliveries --- src/server/dispatcher.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/server/dispatcher.rs b/src/server/dispatcher.rs index 32ae7fc..7491ff6 100644 --- a/src/server/dispatcher.rs +++ b/src/server/dispatcher.rs @@ -84,13 +84,25 @@ async fn worker(db: DatabaseConnection, domain: String, poll_interval: u64, mut }, }; - let Some(model::user::Model{ private_key: Some(key), .. }) = model::user::Entity::find_by_id(&delivery.actor) - .one(&db).await? - else { - tracing::error!("can not dispatch activity for user without private key: {}", delivery.actor); - continue; + let key = if delivery.actor.ends_with(&domain) { + let Some(model::application::Model { private_key: key, .. }) = model::application::Entity::find() + .one(&db).await? + else { + tracing::error!("no private key configured for application"); + continue; + }; + key + } else { + let Some(model::user::Model{ private_key: Some(key), .. }) = model::user::Entity::find_by_id(&delivery.actor) + .one(&db).await? + else { + tracing::error!("can not dispatch activity for user without private key: {}", delivery.actor); + continue; + }; + key }; + if let Err(e) = Context::request( Method::POST, &delivery.target, Some(&serde_json::to_string(&payload).unwrap()),