From: Felix Ableitner Date: Wed, 8 Apr 2020 16:22:44 +0000 (+0200) Subject: Use instance struct instead of raw string X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%22https:/nerdica.net/%7Biframely.url%7D?a=commitdiff_plain;h=5706b533fd73a797009ac56056ab44e6ddccf4c3;p=lemmy.git Use instance struct instead of raw string --- diff --git a/server/src/apub/mod.rs b/server/src/apub/mod.rs index cbfbe735..c9d5e0e5 100644 --- a/server/src/apub/mod.rs +++ b/server/src/apub/mod.rs @@ -16,6 +16,17 @@ type PersonExt = Ext; static APUB_JSON_CONTENT_TYPE: &str = "application/activity+json"; +pub enum EndpointType { + Community, + User, + Post, + Comment, +} + +pub struct Instance { + domain: String, +} + fn create_apub_response(json: &T) -> HttpResponse where T: serde::ser::Serialize, @@ -25,13 +36,6 @@ where .json(json) } -pub enum EndpointType { - Community, - User, - Post, - Comment, -} - // TODO: we will probably need to change apub endpoint urls so that html and activity+json content // types are handled at the same endpoint, so that you can copy the url into mastodon search // and have it fetch the object. @@ -93,10 +97,13 @@ pub fn format_community_name(name: &str, instance: &str) -> String { } } -pub fn get_following_instances() -> Vec<&'static str> { +pub fn get_following_instances() -> Vec { Settings::get() .federation .followed_instances .split(',') + .map(|i| Instance { + domain: i.to_string(), + }) .collect() } diff --git a/server/src/apub/puller.rs b/server/src/apub/puller.rs index 4dacf60f..7610d464 100644 --- a/server/src/apub/puller.rs +++ b/server/src/apub/puller.rs @@ -17,11 +17,11 @@ use serde::Deserialize; use std::time::Duration; use url::Url; -fn fetch_node_info(domain: &str) -> Result { +fn fetch_node_info(instance: &Instance) -> Result { let well_known_uri = Url::parse(&format!( "{}://{}/.well-known/nodeinfo", get_apub_protocol_string(), - domain + instance.domain ))?; let well_known = fetch_remote_object::(&well_known_uri)?; Ok(fetch_remote_object::(&well_known.links.href)?) @@ -75,17 +75,17 @@ where } fn fetch_remote_community_posts( - instance: &str, + instance: &Instance, community: &Community, conn: &PgConnection, ) -> Result, Error> { + // TODO: need to add outbox field to Community let endpoint = Url::parse(&format!( "http://{}/federation/c/{}", - instance, community.name + instance.domain, community.name ))?; let group = fetch_remote_object::(&endpoint)?; let outbox_uri = Url::parse(&group.extension.get_outbox().to_string())?; - // TODO: outbox url etc should be stored in local db let outbox = fetch_remote_object::(&outbox_uri)?; let items = outbox.collection_props.get_many_items_base_boxes(); @@ -134,7 +134,7 @@ pub fn fetch_all(conn: &PgConnection) -> Result<(), Error> { } else { warn!( "{} is not a Lemmy instance, federation is not supported", - instance + instance.domain ); } }