forward all POSTs to redis

This commit is contained in:
Astro 2023-10-12 23:38:26 +02:00
parent 2980a15eb6
commit 7f91afa35e

View file

@ -143,6 +143,18 @@ async fn post_relay(
).into_response(); ).into_response();
} }
}; };
if let Some((redis, in_topic)) = &state.redis {
if let Ok(data) = serde_json::to_vec(&endpoint.payload) {
if let Err(e) = redis::Cmd::publish(in_topic.as_ref(), data)
.query_async::<_, redis::Value>(&mut redis.clone())
.await
{
tracing::error!("redis publish: {}", e);
}
}
}
let action = match serde_json::from_value::<activitypub::Action<serde_json::Value>>(endpoint.payload.clone()) { let action = match serde_json::from_value::<activitypub::Action<serde_json::Value>>(endpoint.payload.clone()) {
Ok(action) => action, Ok(action) => action,
Err(e) => { Err(e) => {
@ -229,29 +241,12 @@ async fn post_relay(
).into_response() ).into_response()
} }
} }
} else if action.action_type == "Create" || action.action_type == "Announce" { } else {
tracing::trace!("Received on {} from {}: {} {:?}", target.uri(), endpoint.remote_actor_uri, action.action_type, action.object); track_request("POST", "relay", "unrecognized");
if let Some((redis, in_topic)) = &state.redis {
if let Some(data) = &action.object
.and_then(|o| serde_json::to_vec(&o).ok())
{
if let Err(e) = redis::Cmd::publish(in_topic.as_ref(), data)
.query_async::<_, redis::Value>(&mut redis.clone())
.await
{
tracing::error!("redis publish: {}", e);
}
}
}
(StatusCode::ACCEPTED, (StatusCode::ACCEPTED,
[("content-type", "application/activity+json")], [("content-type", "application/activity+json")],
"{}" "{}"
).into_response() ).into_response()
} else {
tracing::error!("Unrecognized action type {:?}", action.action_type);
track_request("POST", "relay", "unrecognized");
(StatusCode::BAD_REQUEST, "Not a recognized request").into_response()
} }
} }