diff --git a/crates/api/src/local_user.rs b/crates/api/src/local_user.rs index fe1c8b117..c69ea48d3 100644 --- a/crates/api/src/local_user.rs +++ b/crates/api/src/local_user.rs @@ -121,7 +121,7 @@ impl Perform for GetCaptcha { context: &Data, _websocket_id: Option, ) -> Result { - let captcha_settings = context.settings().to_owned().captcha; + let captcha_settings = context.settings().captcha; if !captcha_settings.enabled { return Ok(GetCaptchaResponse { ok: None }); @@ -757,7 +757,7 @@ impl Perform for PasswordReset { email, &local_user_view.person.name, html, - context.settings(), + &context.settings(), ) .map_err(|e| ApiError::err(&e))?; diff --git a/crates/api/src/site.rs b/crates/api/src/site.rs index 1c601b264..01f7b45f1 100644 --- a/crates/api/src/site.rs +++ b/crates/api/src/site.rs @@ -181,7 +181,7 @@ impl Perform for Search { let community_actor_id = data .community_name .as_ref() - .map(|t| build_actor_id_from_shortname(EndpointType::Community, t, context.settings()).ok()) + .map(|t| build_actor_id_from_shortname(EndpointType::Community, t, &context.settings()).ok()) .unwrap_or(None); let creator_id = data.creator_id; match search_type { diff --git a/crates/api_crud/src/comment/create.rs b/crates/api_crud/src/comment/create.rs index bb7728e9c..fb175179a 100644 --- a/crates/api_crud/src/comment/create.rs +++ b/crates/api_crud/src/comment/create.rs @@ -125,7 +125,7 @@ impl PerformCrud for CreateComment { post, context.pool(), true, - context.settings(), + &context.settings(), ) .await?; diff --git a/crates/api_crud/src/comment/delete.rs b/crates/api_crud/src/comment/delete.rs index c84ec621e..0b44f4ebb 100644 --- a/crates/api_crud/src/comment/delete.rs +++ b/crates/api_crud/src/comment/delete.rs @@ -77,7 +77,7 @@ impl PerformCrud for DeleteComment { post, context.pool(), false, - context.settings(), + &context.settings(), ) .await?; @@ -172,7 +172,7 @@ impl PerformCrud for RemoveComment { post, context.pool(), false, - context.settings(), + &context.settings(), ) .await?; diff --git a/crates/api_crud/src/comment/read.rs b/crates/api_crud/src/comment/read.rs index f63104bc5..8ee9eb628 100644 --- a/crates/api_crud/src/comment/read.rs +++ b/crates/api_crud/src/comment/read.rs @@ -32,7 +32,7 @@ impl PerformCrud for GetComments { let community_actor_id = data .community_name .as_ref() - .map(|t| build_actor_id_from_shortname(EndpointType::Community, t, context.settings()).ok()) + .map(|t| build_actor_id_from_shortname(EndpointType::Community, t, &context.settings()).ok()) .unwrap_or(None); let saved_only = data.saved_only; let page = data.page; diff --git a/crates/api_crud/src/comment/update.rs b/crates/api_crud/src/comment/update.rs index ab9b9faaf..24e2ddbdd 100644 --- a/crates/api_crud/src/comment/update.rs +++ b/crates/api_crud/src/comment/update.rs @@ -83,7 +83,7 @@ impl PerformCrud for EditComment { orig_comment.post, context.pool(), false, - context.settings(), + &context.settings(), ) .await?; diff --git a/crates/api_crud/src/community/read.rs b/crates/api_crud/src/community/read.rs index 3bbac9241..b29f5f0a0 100644 --- a/crates/api_crud/src/community/read.rs +++ b/crates/api_crud/src/community/read.rs @@ -36,7 +36,7 @@ impl PerformCrud for GetCommunity { None => { let name = data.name.to_owned().unwrap_or_else(|| "main".to_string()); let community_actor_id = - build_actor_id_from_shortname(EndpointType::Community, &name, context.settings())?; + build_actor_id_from_shortname(EndpointType::Community, &name, &context.settings())?; blocking(context.pool(), move |conn| { Community::read_from_apub_id(conn, &community_actor_id) diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index 524c305d3..11896875c 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -54,7 +54,7 @@ impl PerformCrud for CreatePost { // Fetch post links and pictrs cached image let data_url = data.url.as_ref(); let (metadata_res, pictrs_thumbnail) = - fetch_site_data(context.client(), context.settings(), data_url).await; + fetch_site_data(context.client(), &context.settings(), data_url).await; let (embed_title, embed_description, embed_html) = metadata_res .map(|u| (u.title, u.description, u.html)) .unwrap_or((None, None, None)); diff --git a/crates/api_crud/src/post/read.rs b/crates/api_crud/src/post/read.rs index 413f641c1..1cfcbaf8c 100644 --- a/crates/api_crud/src/post/read.rs +++ b/crates/api_crud/src/post/read.rs @@ -135,7 +135,7 @@ impl PerformCrud for GetPosts { let community_actor_id = data .community_name .as_ref() - .map(|t| build_actor_id_from_shortname(EndpointType::Community, t, context.settings()).ok()) + .map(|t| build_actor_id_from_shortname(EndpointType::Community, t, &context.settings()).ok()) .unwrap_or(None); let saved_only = data.saved_only; diff --git a/crates/api_crud/src/post/update.rs b/crates/api_crud/src/post/update.rs index c1215830d..b94786826 100644 --- a/crates/api_crud/src/post/update.rs +++ b/crates/api_crud/src/post/update.rs @@ -54,7 +54,7 @@ impl PerformCrud for EditPost { // Fetch post links and Pictrs cached image let data_url = data.url.as_ref(); let (metadata_res, pictrs_thumbnail) = - fetch_site_data(context.client(), context.settings(), data_url).await; + fetch_site_data(context.client(), &context.settings(), data_url).await; let (embed_title, embed_description, embed_html) = metadata_res .map(|u| (u.title, u.description, u.html)) .unwrap_or((None, None, None)); diff --git a/crates/api_crud/src/private_message/create.rs b/crates/api_crud/src/private_message/create.rs index a0b12fb32..10d77da45 100644 --- a/crates/api_crud/src/private_message/create.rs +++ b/crates/api_crud/src/private_message/create.rs @@ -105,7 +105,7 @@ impl PerformCrud for CreatePrivateMessage { "Private Message from", "Private Message", &content_slurs_removed, - context.settings(), + &context.settings(), ); } diff --git a/crates/api_crud/src/user/read.rs b/crates/api_crud/src/user/read.rs index bb45d4731..b029f2998 100644 --- a/crates/api_crud/src/user/read.rs +++ b/crates/api_crud/src/user/read.rs @@ -43,7 +43,7 @@ impl PerformCrud for GetPersonDetails { .to_owned() .unwrap_or_else(|| "admin".to_string()); let actor_id = - build_actor_id_from_shortname(EndpointType::Person, &name, context.settings())?; + build_actor_id_from_shortname(EndpointType::Person, &name, &context.settings())?; let person = blocking(context.pool(), move |conn| { Person::read_from_apub_id(conn, &actor_id) diff --git a/crates/apub/src/activities/comment/create_or_update.rs b/crates/apub/src/activities/comment/create_or_update.rs index cca9942f5..130623ff7 100644 --- a/crates/apub/src/activities/comment/create_or_update.rs +++ b/crates/apub/src/activities/comment/create_or_update.rs @@ -90,7 +90,7 @@ impl ActivityHandler for CreateOrUpdateComment { let community = extract_community(&self.cc, context, request_counter).await?; let community_id = ObjectId::new(community.actor_id()); - verify_activity(self, context.settings())?; + verify_activity(self, &context.settings())?; verify_person_in_community(&self.actor, &community_id, context, request_counter).await?; verify_domains_match(self.actor.inner(), self.object.id_unchecked())?; // TODO: should add a check that the correct community is in cc (probably needs changes to diff --git a/crates/apub/src/activities/comment/mod.rs b/crates/apub/src/activities/comment/mod.rs index 1810a38ac..58524cb5f 100644 --- a/crates/apub/src/activities/comment/mod.rs +++ b/crates/apub/src/activities/comment/mod.rs @@ -46,7 +46,7 @@ async fn get_notif_recipients( post, context.pool(), true, - context.settings(), + &context.settings(), ) .await } diff --git a/crates/apub/src/activities/community/add_mod.rs b/crates/apub/src/activities/community/add_mod.rs index 6c6e56f48..a71414dd2 100644 --- a/crates/apub/src/activities/community/add_mod.rs +++ b/crates/apub/src/activities/community/add_mod.rs @@ -84,7 +84,7 @@ impl ActivityHandler for AddMod { context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - verify_activity(self, context.settings())?; + verify_activity(self, &context.settings())?; verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?; verify_mod_action(&self.actor, self.cc[0].clone(), context).await?; verify_add_remove_moderator_target(&self.target, &self.cc[0])?; diff --git a/crates/apub/src/activities/community/announce.rs b/crates/apub/src/activities/community/announce.rs index 87e51edaf..dae37b60e 100644 --- a/crates/apub/src/activities/community/announce.rs +++ b/crates/apub/src/activities/community/announce.rs @@ -103,7 +103,7 @@ impl ActivityHandler for AnnounceActivity { context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - verify_activity(self, context.settings())?; + verify_activity(self, &context.settings())?; verify_community(&self.actor, context, request_counter).await?; self.object.verify(context, request_counter).await?; Ok(()) diff --git a/crates/apub/src/activities/community/block_user.rs b/crates/apub/src/activities/community/block_user.rs index 8dddc1c73..ad9999884 100644 --- a/crates/apub/src/activities/community/block_user.rs +++ b/crates/apub/src/activities/community/block_user.rs @@ -95,7 +95,7 @@ impl ActivityHandler for BlockUserFromCommunity { context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - verify_activity(self, context.settings())?; + verify_activity(self, &context.settings())?; verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?; verify_mod_action(&self.actor, self.cc[0].clone(), context).await?; Ok(()) diff --git a/crates/apub/src/activities/community/mod.rs b/crates/apub/src/activities/community/mod.rs index 776ef8701..642f83645 100644 --- a/crates/apub/src/activities/community/mod.rs +++ b/crates/apub/src/activities/community/mod.rs @@ -20,7 +20,7 @@ async fn list_community_follower_inboxes( Ok( vec![ community - .get_follower_inboxes(context.pool(), context.settings()) + .get_follower_inboxes(context.pool(), &context.settings()) .await?, additional_inboxes, ] @@ -28,7 +28,7 @@ async fn list_community_follower_inboxes( .flatten() .unique() .filter(|inbox| inbox.host_str() != Some(&context.settings().hostname)) - .filter(|inbox| check_is_apub_id_valid(inbox, false, context.settings()).is_ok()) + .filter(|inbox| check_is_apub_id_valid(inbox, false, &context.settings()).is_ok()) .map(|inbox| inbox.to_owned()) .collect(), ) diff --git a/crates/apub/src/activities/community/remove_mod.rs b/crates/apub/src/activities/community/remove_mod.rs index 5edb14b2c..2da9bbdbb 100644 --- a/crates/apub/src/activities/community/remove_mod.rs +++ b/crates/apub/src/activities/community/remove_mod.rs @@ -86,7 +86,7 @@ impl ActivityHandler for RemoveMod { context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - verify_activity(self, context.settings())?; + verify_activity(self, &context.settings())?; if let Some(target) = &self.target { verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?; verify_mod_action(&self.actor, self.cc[0].clone(), context).await?; diff --git a/crates/apub/src/activities/community/undo_block_user.rs b/crates/apub/src/activities/community/undo_block_user.rs index a078afe30..29aa83f5b 100644 --- a/crates/apub/src/activities/community/undo_block_user.rs +++ b/crates/apub/src/activities/community/undo_block_user.rs @@ -82,7 +82,7 @@ impl ActivityHandler for UndoBlockUserFromCommunity { context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - verify_activity(self, context.settings())?; + verify_activity(self, &context.settings())?; verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?; verify_mod_action(&self.actor, self.cc[0].clone(), context).await?; self.object.verify(context, request_counter).await?; diff --git a/crates/apub/src/activities/community/update.rs b/crates/apub/src/activities/community/update.rs index 52da00554..d217e2561 100644 --- a/crates/apub/src/activities/community/update.rs +++ b/crates/apub/src/activities/community/update.rs @@ -82,7 +82,7 @@ impl ActivityHandler for UpdateCommunity { context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - verify_activity(self, context.settings())?; + verify_activity(self, &context.settings())?; verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?; verify_mod_action(&self.actor, self.cc[0].clone(), context).await?; Ok(()) @@ -102,7 +102,7 @@ impl ActivityHandler for UpdateCommunity { let updated_community = Group::from_apub_to_form( &self.object, &community.actor_id.clone().into(), - context.settings(), + &context.settings(), ) .await?; let cf = CommunityForm { diff --git a/crates/apub/src/activities/deletion/delete.rs b/crates/apub/src/activities/deletion/delete.rs index 8caa551d8..9e957a8ee 100644 --- a/crates/apub/src/activities/deletion/delete.rs +++ b/crates/apub/src/activities/deletion/delete.rs @@ -87,7 +87,7 @@ impl ActivityHandler for Delete { context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - verify_activity(self, context.settings())?; + verify_activity(self, &context.settings())?; verify_delete_activity( &self.object, self, diff --git a/crates/apub/src/activities/deletion/undo_delete.rs b/crates/apub/src/activities/deletion/undo_delete.rs index b5ff2df5d..f74c34c90 100644 --- a/crates/apub/src/activities/deletion/undo_delete.rs +++ b/crates/apub/src/activities/deletion/undo_delete.rs @@ -59,7 +59,7 @@ impl ActivityHandler for UndoDelete { context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - verify_activity(self, context.settings())?; + verify_activity(self, &context.settings())?; self.object.verify(context, request_counter).await?; verify_delete_activity( &self.object.object, diff --git a/crates/apub/src/activities/following/accept.rs b/crates/apub/src/activities/following/accept.rs index c0210e962..86b0d2093 100644 --- a/crates/apub/src/activities/following/accept.rs +++ b/crates/apub/src/activities/following/accept.rs @@ -80,7 +80,7 @@ impl ActivityHandler for AcceptFollowCommunity { context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - verify_activity(self, context.settings())?; + verify_activity(self, &context.settings())?; verify_urls_match(self.to.inner(), self.object.actor())?; verify_urls_match(self.actor(), self.object.to.inner())?; verify_community(&self.actor, context, request_counter).await?; diff --git a/crates/apub/src/activities/following/follow.rs b/crates/apub/src/activities/following/follow.rs index 236b27a8f..21446eb12 100644 --- a/crates/apub/src/activities/following/follow.rs +++ b/crates/apub/src/activities/following/follow.rs @@ -91,7 +91,7 @@ impl ActivityHandler for FollowCommunity { context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - verify_activity(self, context.settings())?; + verify_activity(self, &context.settings())?; verify_urls_match(self.to.inner(), self.object.inner())?; verify_person(&self.actor, context, request_counter).await?; Ok(()) diff --git a/crates/apub/src/activities/following/undo.rs b/crates/apub/src/activities/following/undo.rs index 0ff09ddd7..cc103075d 100644 --- a/crates/apub/src/activities/following/undo.rs +++ b/crates/apub/src/activities/following/undo.rs @@ -74,7 +74,7 @@ impl ActivityHandler for UndoFollowCommunity { context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - verify_activity(self, context.settings())?; + verify_activity(self, &context.settings())?; verify_urls_match(self.to.inner(), self.object.object.inner())?; verify_urls_match(self.actor(), self.object.actor())?; verify_person(&self.actor, context, request_counter).await?; diff --git a/crates/apub/src/activities/post/create_or_update.rs b/crates/apub/src/activities/post/create_or_update.rs index 1a0a9c884..ae93f0988 100644 --- a/crates/apub/src/activities/post/create_or_update.rs +++ b/crates/apub/src/activities/post/create_or_update.rs @@ -86,7 +86,7 @@ impl ActivityHandler for CreateOrUpdatePost { context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - verify_activity(self, context.settings())?; + verify_activity(self, &context.settings())?; let community = self.cc[0].dereference(context, request_counter).await?; verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?; match self.kind { diff --git a/crates/apub/src/activities/private_message/create_or_update.rs b/crates/apub/src/activities/private_message/create_or_update.rs index b51e5d7ca..f3b1c91fb 100644 --- a/crates/apub/src/activities/private_message/create_or_update.rs +++ b/crates/apub/src/activities/private_message/create_or_update.rs @@ -66,7 +66,7 @@ impl ActivityHandler for CreateOrUpdatePrivateMessage { context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - verify_activity(self, context.settings())?; + verify_activity(self, &context.settings())?; verify_person(&self.actor, context, request_counter).await?; verify_domains_match(self.actor.inner(), self.object.id_unchecked())?; self.object.verify(context, request_counter).await?; diff --git a/crates/apub/src/activities/private_message/delete.rs b/crates/apub/src/activities/private_message/delete.rs index 9fb346ec7..bf12f9d1e 100644 --- a/crates/apub/src/activities/private_message/delete.rs +++ b/crates/apub/src/activities/private_message/delete.rs @@ -77,7 +77,7 @@ impl ActivityHandler for DeletePrivateMessage { context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - verify_activity(self, context.settings())?; + verify_activity(self, &context.settings())?; verify_person(&self.actor, context, request_counter).await?; verify_domains_match(self.actor.inner(), &self.object)?; Ok(()) diff --git a/crates/apub/src/activities/private_message/undo_delete.rs b/crates/apub/src/activities/private_message/undo_delete.rs index 759084b0b..5aa6dbed4 100644 --- a/crates/apub/src/activities/private_message/undo_delete.rs +++ b/crates/apub/src/activities/private_message/undo_delete.rs @@ -76,7 +76,7 @@ impl ActivityHandler for UndoDeletePrivateMessage { context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - verify_activity(self, context.settings())?; + verify_activity(self, &context.settings())?; verify_person(&self.actor, context, request_counter).await?; verify_urls_match(self.actor(), self.object.actor())?; verify_domains_match(self.actor(), &self.object.object)?; diff --git a/crates/apub/src/activities/undo_remove.rs b/crates/apub/src/activities/undo_remove.rs index 10e3fe6e3..422d0deea 100644 --- a/crates/apub/src/activities/undo_remove.rs +++ b/crates/apub/src/activities/undo_remove.rs @@ -43,7 +43,7 @@ impl ActivityHandler for UndoRemovePostCommentOrCommunity { context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - verify_activity(self, context.settings())?; + verify_activity(self, &context.settings())?; self.object.verify(context, request_counter).await?; verify_delete_activity( diff --git a/crates/apub/src/activities/voting/undo_vote.rs b/crates/apub/src/activities/voting/undo_vote.rs index b306692aa..963292fa5 100644 --- a/crates/apub/src/activities/voting/undo_vote.rs +++ b/crates/apub/src/activities/voting/undo_vote.rs @@ -91,7 +91,7 @@ impl ActivityHandler for UndoVote { context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - verify_activity(self, context.settings())?; + verify_activity(self, &context.settings())?; verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?; verify_urls_match(self.actor(), self.object.actor())?; self.object.verify(context, request_counter).await?; diff --git a/crates/apub/src/activities/voting/vote.rs b/crates/apub/src/activities/voting/vote.rs index acec272a2..e74dea108 100644 --- a/crates/apub/src/activities/voting/vote.rs +++ b/crates/apub/src/activities/voting/vote.rs @@ -117,7 +117,7 @@ impl ActivityHandler for Vote { context: &LemmyContext, request_counter: &mut i32, ) -> Result<(), LemmyError> { - verify_activity(self, context.settings())?; + verify_activity(self, &context.settings())?; verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?; Ok(()) } diff --git a/crates/apub/src/fetcher/community.rs b/crates/apub/src/fetcher/community.rs index 6bffe04bd..174741128 100644 --- a/crates/apub/src/fetcher/community.rs +++ b/crates/apub/src/fetcher/community.rs @@ -75,7 +75,7 @@ pub(crate) async fn fetch_community_outbox( ) -> Result<(), LemmyError> { let outbox = fetch_remote_object::( context.client(), - context.settings(), + &context.settings(), outbox, recursion_counter, ) @@ -105,7 +105,7 @@ async fn fetch_community_mods( if let Some(mods_url) = &group.moderators { let mods = fetch_remote_object::( context.client(), - context.settings(), + &context.settings(), mods_url, recursion_counter, ) diff --git a/crates/apub/src/fetcher/objects.rs b/crates/apub/src/fetcher/objects.rs index 3453fd389..c222776d5 100644 --- a/crates/apub/src/fetcher/objects.rs +++ b/crates/apub/src/fetcher/objects.rs @@ -34,7 +34,7 @@ pub(crate) async fn get_or_fetch_and_insert_post( debug!("Fetching and creating remote post: {}", post_ap_id); let page = fetch_remote_object::( context.client(), - context.settings(), + &context.settings(), post_ap_id, recursion_counter, ) @@ -71,7 +71,7 @@ pub(crate) async fn get_or_fetch_and_insert_comment( ); let comment = fetch_remote_object::( context.client(), - context.settings(), + &context.settings(), comment_ap_id, recursion_counter, ) diff --git a/crates/apub/src/fetcher/person.rs b/crates/apub/src/fetcher/person.rs index 887e3c276..54c3163a6 100644 --- a/crates/apub/src/fetcher/person.rs +++ b/crates/apub/src/fetcher/person.rs @@ -33,7 +33,7 @@ pub(crate) async fn get_or_fetch_and_upsert_person( debug!("Fetching and updating from remote person: {}", apub_id); let person = fetch_remote_object::( context.client(), - context.settings(), + &context.settings(), apub_id, recursion_counter, ) @@ -65,7 +65,7 @@ pub(crate) async fn get_or_fetch_and_upsert_person( debug!("Fetching and creating remote person: {}", apub_id); let person = fetch_remote_object::( context.client(), - context.settings(), + &context.settings(), apub_id, recursion_counter, ) diff --git a/crates/apub/src/http/mod.rs b/crates/apub/src/http/mod.rs index 347f56428..a70ed6f00 100644 --- a/crates/apub/src/http/mod.rs +++ b/crates/apub/src/http/mod.rs @@ -98,7 +98,7 @@ where if is_activity_already_known(context.pool(), activity.id_unchecked()).await? { return Ok(HttpResponse::Ok().finish()); } - check_is_apub_id_valid(activity.actor(), false, context.settings())?; + check_is_apub_id_valid(activity.actor(), false, &context.settings())?; info!("Verifying activity {}", activity.id_unchecked().to_string()); activity.verify(context, request_counter).await?; assert_activity_not_local(&activity, &context.settings().hostname)?; diff --git a/crates/apub/src/objects/community.rs b/crates/apub/src/objects/community.rs index 7238c0c42..c8ddd2972 100644 --- a/crates/apub/src/objects/community.rs +++ b/crates/apub/src/objects/community.rs @@ -178,7 +178,7 @@ impl FromApub for Community { expected_domain: &Url, request_counter: &mut i32, ) -> Result { - let form = Group::from_apub_to_form(group, expected_domain, context.settings()).await?; + let form = Group::from_apub_to_form(group, expected_domain, &context.settings()).await?; let community = blocking(context.pool(), move |conn| Community::upsert(conn, &form)).await??; update_community_mods(group, &community, context, request_counter).await?; diff --git a/crates/apub/src/objects/person.rs b/crates/apub/src/objects/person.rs index 2c563b9dc..5bf7a5897 100644 --- a/crates/apub/src/objects/person.rs +++ b/crates/apub/src/objects/person.rs @@ -155,7 +155,7 @@ impl FromApub for DbPerson { check_slurs_opt(&display_name, slur_regex)?; check_slurs_opt(&bio, slur_regex)?; - check_is_apub_id_valid(&person.id, false, context.settings())?; + check_is_apub_id_valid(&person.id, false, &context.settings())?; let person_form = PersonForm { name, diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index 0cad7ec49..451ce0554 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -191,7 +191,7 @@ impl FromApub for Post { let thumbnail_url: Option = page.image.clone().map(|i| i.url); let (metadata_res, pictrs_thumbnail) = if let Some(url) = &page.url { - fetch_site_data(context.client(), context.settings(), Some(url)).await + fetch_site_data(context.client(), &context.settings(), Some(url)).await } else { (None, thumbnail_url) }; diff --git a/crates/routes/src/images.rs b/crates/routes/src/images.rs index 035514f21..e5e33489d 100644 --- a/crates/routes/src/images.rs +++ b/crates/routes/src/images.rs @@ -59,10 +59,7 @@ async fn upload( }; let mut client_req = client.request_from( - format!( - "{}/image", - pictrs_url(context.settings().to_owned().pictrs_url)? - ), + format!("{}/image", pictrs_url(context.settings().pictrs_url)?), req.head(), ); // remove content-encoding header so that pictrs doesnt send gzipped response @@ -92,7 +89,7 @@ async fn full_res( let name = &filename.into_inner(); // If there are no query params, the URL is original - let pictrs_url_settings = context.settings().to_owned().pictrs_url; + let pictrs_url_settings = context.settings().pictrs_url; let url = if params.format.is_none() && params.thumbnail.is_none() { format!( "{}/image/original/{}", @@ -160,7 +157,7 @@ async fn delete( let url = format!( "{}/image/delete/{}/{}", - pictrs_url(context.settings().to_owned().pictrs_url)?, + pictrs_url(context.settings().pictrs_url)?, &token, &file ); diff --git a/crates/utils/src/settings/mod.rs b/crates/utils/src/settings/mod.rs index b75353aaf..d47cc5b4b 100644 --- a/crates/utils/src/settings/mod.rs +++ b/crates/utils/src/settings/mod.rs @@ -2,12 +2,17 @@ use crate::{location_info, settings::structs::Settings, LemmyError}; use anyhow::{anyhow, Context}; use deser_hjson::from_str; use regex::{Regex, RegexBuilder}; -use std::{env, fs, io::Error}; +use std::{env, fs, io::Error, sync::RwLock}; pub mod structs; static CONFIG_FILE: &str = "config/config.hjson"; +lazy_static! { + static ref SETTINGS: RwLock = + RwLock::new(Settings::init().expect("Failed to load settings file")); +} + impl Settings { /// Reads config from configuration file. /// @@ -35,6 +40,11 @@ impl Settings { Ok(config) } + /// Returns the config as a struct. + pub fn get() -> Self { + SETTINGS.read().expect("read config").to_owned() + } + pub fn get_database_url(&self) -> String { let conf = &self.database; format!( @@ -83,6 +93,15 @@ impl Settings { pub fn save_config_file(data: &str) -> Result { fs::write(CONFIG_FILE, data)?; + + // Reload the new settings + // From https://stackoverflow.com/questions/29654927/how-do-i-assign-a-string-to-a-mutable-static-variable/47181804#47181804 + let mut new_settings = SETTINGS.write().expect("write config"); + *new_settings = match Settings::init() { + Ok(c) => c, + Err(e) => panic!("{}", e), + }; + Ok(Self::read_config_file()?) } diff --git a/crates/websocket/src/lib.rs b/crates/websocket/src/lib.rs index a91a66812..366512eb9 100644 --- a/crates/websocket/src/lib.rs +++ b/crates/websocket/src/lib.rs @@ -55,8 +55,9 @@ impl LemmyContext { pub fn activity_queue(&self) -> &QueueHandle { &self.activity_queue } - pub fn settings(&self) -> &Settings { - &self.settings + pub fn settings(&self) -> Settings { + // TODO hacky solution to be able to hotload the settings. + Settings::get() } pub fn secret(&self) -> &Secret { &self.secret