2022-02-07 19:23:12 +00:00
|
|
|
use crate::{
|
|
|
|
activity_lists::SiteInboxActivities,
|
2023-03-21 15:03:05 +00:00
|
|
|
http::create_apub_response,
|
2022-06-02 14:33:41 +00:00
|
|
|
objects::{instance::ApubSite, person::ApubPerson},
|
2022-02-07 19:23:12 +00:00
|
|
|
protocol::collections::empty_outbox::EmptyOutbox,
|
|
|
|
};
|
2023-03-21 15:03:05 +00:00
|
|
|
use activitypub_federation::{
|
|
|
|
actix_web::inbox::receive_activity,
|
|
|
|
config::Data,
|
|
|
|
protocol::context::WithContext,
|
|
|
|
traits::Object,
|
|
|
|
};
|
|
|
|
use actix_web::{web::Bytes, HttpRequest, HttpResponse};
|
2022-11-28 14:29:33 +00:00
|
|
|
use lemmy_api_common::context::LemmyContext;
|
2022-10-27 09:24:07 +00:00
|
|
|
use lemmy_db_views::structs::SiteView;
|
2022-06-22 20:24:54 +00:00
|
|
|
use lemmy_utils::error::LemmyError;
|
2022-02-07 19:23:12 +00:00
|
|
|
use url::Url;
|
|
|
|
|
|
|
|
pub(crate) async fn get_apub_site_http(
|
2023-03-21 15:03:05 +00:00
|
|
|
context: Data<LemmyContext>,
|
2022-02-07 19:23:12 +00:00
|
|
|
) -> Result<HttpResponse, LemmyError> {
|
2023-07-01 03:04:38 +00:00
|
|
|
let site: ApubSite = SiteView::read_local(context.conn().await?)
|
2023-06-30 18:24:06 +00:00
|
|
|
.await?
|
|
|
|
.site
|
|
|
|
.into();
|
2022-02-07 19:23:12 +00:00
|
|
|
|
2023-03-21 15:03:05 +00:00
|
|
|
let apub = site.into_json(&context).await?;
|
2023-04-13 00:17:23 +00:00
|
|
|
create_apub_response(&apub)
|
2022-02-07 19:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[tracing::instrument(skip_all)]
|
2022-06-22 20:24:54 +00:00
|
|
|
pub(crate) async fn get_apub_site_outbox(
|
2023-03-21 15:03:05 +00:00
|
|
|
context: Data<LemmyContext>,
|
2022-06-22 20:24:54 +00:00
|
|
|
) -> Result<HttpResponse, LemmyError> {
|
2022-02-07 19:23:12 +00:00
|
|
|
let outbox_id = format!(
|
|
|
|
"{}/site_outbox",
|
2022-06-22 20:24:54 +00:00
|
|
|
context.settings().get_protocol_and_hostname()
|
2022-02-07 19:23:12 +00:00
|
|
|
);
|
2022-11-24 16:38:00 +00:00
|
|
|
let outbox = EmptyOutbox::new(Url::parse(&outbox_id)?)?;
|
2023-04-13 00:17:23 +00:00
|
|
|
create_apub_response(&outbox)
|
2022-02-07 19:23:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[tracing::instrument(skip_all)]
|
|
|
|
pub async fn get_apub_site_inbox(
|
|
|
|
request: HttpRequest,
|
2023-03-21 15:03:05 +00:00
|
|
|
body: Bytes,
|
|
|
|
data: Data<LemmyContext>,
|
2022-02-07 19:23:12 +00:00
|
|
|
) -> Result<HttpResponse, LemmyError> {
|
2023-03-21 15:03:05 +00:00
|
|
|
receive_activity::<WithContext<SiteInboxActivities>, ApubPerson, LemmyContext>(
|
|
|
|
request, body, &data,
|
|
|
|
)
|
|
|
|
.await
|
2022-02-07 19:23:12 +00:00
|
|
|
}
|