1 use crate::APUB_JSON_CONTENT_TYPE;
2 use actix_web::{body::Body, web, HttpResponse};
4 use lemmy_api_structs::blocking;
5 use lemmy_db_queries::source::activity::Activity_;
6 use lemmy_db_schema::source::activity::Activity;
7 use lemmy_utils::{settings::structs::Settings, LemmyError};
8 use lemmy_websocket::LemmyContext;
9 use serde::{Deserialize, Serialize};
17 /// Convert the data to json and turn it into an HTTP Response with the correct ActivityPub
19 fn create_apub_response<T>(data: &T) -> HttpResponse<Body>
24 .content_type(APUB_JSON_CONTENT_TYPE)
28 fn create_apub_tombstone_response<T>(data: &T) -> HttpResponse<Body>
33 .content_type(APUB_JSON_CONTENT_TYPE)
34 .status(StatusCode::GONE)
38 #[derive(Deserialize)]
39 pub struct CommunityQuery {
44 /// Return the ActivityPub json representation of a local community over HTTP.
45 pub async fn get_activity(
46 info: web::Path<CommunityQuery>,
47 context: web::Data<LemmyContext>,
48 ) -> Result<HttpResponse<Body>, LemmyError> {
49 let settings = Settings::get();
50 let activity_id = Url::parse(&format!(
51 "{}/activities/{}/{}",
52 settings.get_protocol_and_hostname(),
57 let activity = blocking(context.pool(), move |conn| {
58 Activity::read_from_apub_id(&conn, &activity_id)
62 let sensitive = activity.sensitive.unwrap_or(true);
63 if !activity.local || sensitive {
64 Ok(HttpResponse::NotFound().finish())
66 Ok(create_apub_response(&activity.data))