diff --git a/upub/cli/src/fetch.rs b/upub/cli/src/fetch.rs index cac0a66..3c63623 100644 --- a/upub/cli/src/fetch.rs +++ b/upub/cli/src/fetch.rs @@ -34,7 +34,7 @@ pub async fn fetch(ctx: upub::Context, uri: String, save: bool, actor: Option>().into(), @@ -382,12 +380,12 @@ impl AP { following_count: actor.following_count().unwrap_or(0) as i32, followers_count: actor.followers_count().unwrap_or(0) as i32, statuses_count: actor.statuses_count().unwrap_or(0) as i32, - public_key: actor.public_key().get().ok_or(apb::FieldErr("publicKey"))?.public_key_pem().to_string(), + public_key: actor.public_key().inner()?.public_key_pem().to_string(), private_key: None, // there's no way to transport privkey over AP json, must come from DB fields: actor.attachment() .flat() .into_iter() - .filter_map(|x| Some(crate::model::actor::Field::from(x.extract()?))) + .filter_map(|x| Some(crate::model::actor::Field::from(x.into_inner().ok()?))) .collect::>() .into(), }) diff --git a/upub/core/src/traits/process.rs b/upub/core/src/traits/process.rs index 3ed020b..cdd6964 100644 --- a/upub/core/src/traits/process.rs +++ b/upub/core/src/traits/process.rs @@ -55,7 +55,7 @@ impl Processor for crate::Context { } pub async fn create(ctx: &crate::Context, activity: impl apb::Activity, tx: &DatabaseTransaction) -> Result<(), ProcessorError> { - let Some(object_node) = activity.object().extract() else { + let Ok(object_node) = activity.object().into_inner() else { // TODO we could process non-embedded activities or arrays but im lazy rn tracing::error!("refusing to process activity without embedded object"); return Err(ProcessorError::Unprocessable(activity.id()?.to_string())); @@ -356,7 +356,7 @@ pub async fn delete(ctx: &crate::Context, activity: impl apb::Activity, tx: &Dat pub async fn update(ctx: &crate::Context, activity: impl apb::Activity, tx: &DatabaseTransaction) -> Result<(), ProcessorError> { // TODO when attachments get updated we do nothing!!!!!!!!!! - let Some(object_node) = activity.object().extract() else { + let Ok(object_node) = activity.object().into_inner() else { tracing::error!("refusing to process activity without embedded object"); return Err(ProcessorError::Unprocessable(activity.id()?.to_string())); }; @@ -415,9 +415,7 @@ pub async fn update(ctx: &crate::Context, activity: impl apb::Activity, tx: &Dat pub async fn undo(ctx: &crate::Context, activity: impl apb::Activity, tx: &DatabaseTransaction) -> Result<(), ProcessorError> { // TODO in theory we could work with just object_id but right now only accept embedded - let undone_activity = activity.object() - .extract() - .ok_or(apb::FieldErr("object"))?; + let undone_activity = activity.object().into_inner()?; let uid = activity.actor().id()?.to_string(); let internal_uid = crate::model::actor::Entity::ap_to_internal(&uid, tx) diff --git a/upub/worker/src/outbound.rs b/upub/worker/src/outbound.rs index a1117e8..ef4b76a 100644 --- a/upub/worker/src/outbound.rs +++ b/upub/worker/src/outbound.rs @@ -46,7 +46,7 @@ pub async fn process(ctx: Context, job: &model::job::Model) -> crate::JobResult< .set_published(Some(now)); if matches!(t, apb::ObjectType::Activity(apb::ActivityType::Undo)) { - let mut undone = activity.object().extract().ok_or(crate::JobError::MissingPayload)?; + let mut undone = activity.object().into_inner()?; if undone.id().is_err() { let undone_target = undone.object().id().str().ok_or(crate::JobError::MissingPayload)?; let undone_type = undone.activity_type().map_err(|_| crate::JobError::MissingPayload)?; @@ -74,7 +74,7 @@ pub async fn process(ctx: Context, job: &model::job::Model) -> crate::JobResult< } if matches!(t, apb::ObjectType::Activity(apb::ActivityType::Update)) { - let mut updated = activity.object().extract().ok_or(crate::JobError::MissingPayload)?; + let mut updated = activity.object().into_inner()?; match updated.object_type()? { apb::ObjectType::Actor(_) => { let mut prev = model::actor::Entity::find_by_ap_id(updated.id()?) @@ -95,7 +95,7 @@ pub async fn process(ctx: Context, job: &model::job::Model) -> crate::JobResult< prev.fields = updated.attachment() .flat() .into_iter() - .filter_map(|x| x.extract()) + .filter_map(|x| x.into_inner().ok()) .map(Field::from) .collect::>() .into(); @@ -133,7 +133,7 @@ pub async fn process(ctx: Context, job: &model::job::Model) -> crate::JobResult< let raw_oid = Context::new_id(); let oid = ctx.oid(&raw_oid); // object must be embedded, wont dereference here - let object = activity.object().extract().ok_or(apb::FieldErr("object"))?; + let object = activity.object().into_inner()?; // TODO regex hell here i come... let re = regex::Regex::new(r"@(.+)@([^ ]+)").expect("failed compiling regex pattern"); let mut content = object.content().map(|x| x.to_string()).ok();