fix: proper delivery check

this should be THE filter, previous one should just be an
optimization...
This commit is contained in:
əlemi 2024-12-31 17:10:22 +01:00
parent 6482483791
commit d6f188de23
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -1,11 +1,18 @@
use reqwest::Method;
use apb::{LD, ActivityMut}; use apb::{LD, ActivityMut};
use upub::{Context, model, traits::Fetcher}; use upub::{Context, model, traits::Fetcher};
#[allow(clippy::manual_map)] // TODO can Update code be improved? #[allow(clippy::manual_map)] // TODO can Update code be improved?
pub async fn process(ctx: Context, job: &model::job::Model) -> crate::JobResult<()> { pub async fn process(ctx: Context, job: &model::job::Model) -> crate::JobResult<()> {
tracing::info!("delivering {} to {:?}", job.activity, job.target); let Some(ref target) = job.target else {
return Err(crate::JobError::Malformed(apb::FieldErr("target"))); // TODO not best error to use..
};
if upub::ext::is_blacklisted(target, &ctx.cfg().reject.delivery) {
tracing::warn!("aborting delivery to {target} due to rejection policies: {:?}", job.payload);
return Ok(());
}
tracing::info!("delivering {} to {target}", job.activity);
let Some(activity) = model::activity::Entity::find_by_ap_id(&job.activity) let Some(activity) = model::activity::Entity::find_by_ap_id(&job.activity)
.one(ctx.db()) .one(ctx.db())
@ -60,7 +67,7 @@ pub async fn process(ctx: Context, job: &model::job::Model) -> crate::JobResult<
}; };
Context::request( Context::request(
Method::POST, job.target.as_deref().unwrap_or(""), reqwest::Method::POST, target,
Some(&serde_json::to_string(&payload.ld_context()).unwrap()), Some(&serde_json::to_string(&payload.ld_context()).unwrap()),
&job.actor, &key, ctx.domain() &job.actor, &key, ctx.domain()
).await?; ).await?;