|
|
|
@ -6,18 +6,16 @@ use activitypub_federation::{
|
|
|
|
|
LocalInstance,
|
|
|
|
|
UrlVerifier,
|
|
|
|
|
};
|
|
|
|
|
use anyhow::Context;
|
|
|
|
|
use async_trait::async_trait;
|
|
|
|
|
use lemmy_api_common::LemmyContext;
|
|
|
|
|
use lemmy_db_schema::{
|
|
|
|
|
newtypes::DbUrl,
|
|
|
|
|
source::{activity::Activity, instance::Instance, local_site::LocalSite},
|
|
|
|
|
utils::DbPool,
|
|
|
|
|
};
|
|
|
|
|
use lemmy_utils::{error::LemmyError, location_info, settings::structs::Settings};
|
|
|
|
|
use lemmy_utils::{error::LemmyError, settings::structs::Settings};
|
|
|
|
|
use once_cell::sync::Lazy;
|
|
|
|
|
use tokio::sync::OnceCell;
|
|
|
|
|
use url::{ParseError, Url};
|
|
|
|
|
use url::Url;
|
|
|
|
|
|
|
|
|
|
pub mod activities;
|
|
|
|
|
pub(crate) mod activity_lists;
|
|
|
|
@ -193,68 +191,6 @@ pub(crate) fn check_apub_id_valid_with_strictness(
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub enum EndpointType {
|
|
|
|
|
Community,
|
|
|
|
|
Person,
|
|
|
|
|
Post,
|
|
|
|
|
Comment,
|
|
|
|
|
PrivateMessage,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Generates an apub endpoint for a given domain, IE xyz.tld
|
|
|
|
|
pub fn generate_local_apub_endpoint(
|
|
|
|
|
endpoint_type: EndpointType,
|
|
|
|
|
name: &str,
|
|
|
|
|
domain: &str,
|
|
|
|
|
) -> Result<DbUrl, ParseError> {
|
|
|
|
|
let point = match endpoint_type {
|
|
|
|
|
EndpointType::Community => "c",
|
|
|
|
|
EndpointType::Person => "u",
|
|
|
|
|
EndpointType::Post => "post",
|
|
|
|
|
EndpointType::Comment => "comment",
|
|
|
|
|
EndpointType::PrivateMessage => "private_message",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Ok(Url::parse(&format!("{}/{}/{}", domain, point, name))?.into())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn generate_followers_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
|
|
|
|
|
Ok(Url::parse(&format!("{}/followers", actor_id))?.into())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn generate_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
|
|
|
|
|
Ok(Url::parse(&format!("{}/inbox", actor_id))?.into())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn generate_site_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
|
|
|
|
|
let mut actor_id: Url = actor_id.clone().into();
|
|
|
|
|
actor_id.set_path("site_inbox");
|
|
|
|
|
Ok(actor_id.into())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn generate_shared_inbox_url(actor_id: &DbUrl) -> Result<DbUrl, LemmyError> {
|
|
|
|
|
let actor_id: Url = actor_id.clone().into();
|
|
|
|
|
let url = format!(
|
|
|
|
|
"{}://{}{}/inbox",
|
|
|
|
|
&actor_id.scheme(),
|
|
|
|
|
&actor_id.host_str().context(location_info!())?,
|
|
|
|
|
if let Some(port) = actor_id.port() {
|
|
|
|
|
format!(":{}", port)
|
|
|
|
|
} else {
|
|
|
|
|
String::new()
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
Ok(Url::parse(&url)?.into())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn generate_outbox_url(actor_id: &DbUrl) -> Result<DbUrl, ParseError> {
|
|
|
|
|
Ok(Url::parse(&format!("{}/outbox", actor_id))?.into())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn generate_moderators_url(community_id: &DbUrl) -> Result<DbUrl, LemmyError> {
|
|
|
|
|
Ok(Url::parse(&format!("{}/moderators", community_id))?.into())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Store a sent or received activity in the database, for logging purposes. These records are not
|
|
|
|
|
/// persistent.
|
|
|
|
|
#[tracing::instrument(skip(pool))]
|
|
|
|
|