-/// Generates an apub endpoint for a given domain, IE xyz.tld
-fn generate_apub_endpoint_for_domain(
- 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())
-}
-
-/// Generates the ActivityPub ID for a given object type and ID.
-pub fn generate_apub_endpoint(
- endpoint_type: EndpointType,
- name: &str,
- protocol_and_hostname: &str,
-) -> Result<DbUrl, ParseError> {
- generate_apub_endpoint_for_domain(endpoint_type, name, protocol_and_hostname)
-}
-
-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_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 {
- "".to_string()
- },
- );
- Ok(Url::parse(&url)?.into())
-}
-
-fn generate_moderators_url(community_id: &DbUrl) -> Result<DbUrl, LemmyError> {
- Ok(Url::parse(&format!("{}/moderators", community_id))?.into())
-}
-
-/// Takes in a shortname of the type dessalines@xyz.tld or dessalines (assumed to be local), and outputs the actor id.
-/// Used in the API for communities and users.
-pub fn build_actor_id_from_shortname(
- endpoint_type: EndpointType,
- short_name: &str,
- settings: &Settings,
-) -> Result<DbUrl, ParseError> {
- let split = short_name.split('@').collect::<Vec<&str>>();
-
- let name = split[0];
-
- // If there's no @, its local
- let domain = if split.len() == 1 {
- settings.get_protocol_and_hostname()
- } else {
- format!("{}://{}", settings.get_protocol_string(), split[1])
- };
+pub(crate) async fn check_apub_id_valid_with_strictness(
+ apub_id: &Url,
+ is_strict: bool,
+ context: &LemmyContext,
+) -> Result<(), LemmyError> {
+ let domain = apub_id.domain().expect("apud id has domain").to_string();
+ let local_instance = context
+ .settings()
+ .get_hostname_without_port()
+ .expect("local hostname is valid");
+ if domain == local_instance {
+ return Ok(());
+ }