mirror of https://github.com/LemmyNet/lemmy.git
Add hack to hot reload settings.
parent
e012380821
commit
d6b87dd687
|
@ -121,7 +121,7 @@ impl Perform for GetCaptcha {
|
||||||
context: &Data<LemmyContext>,
|
context: &Data<LemmyContext>,
|
||||||
_websocket_id: Option<ConnectionId>,
|
_websocket_id: Option<ConnectionId>,
|
||||||
) -> Result<Self::Response, LemmyError> {
|
) -> Result<Self::Response, LemmyError> {
|
||||||
let captcha_settings = context.settings().to_owned().captcha;
|
let captcha_settings = context.settings().captcha;
|
||||||
|
|
||||||
if !captcha_settings.enabled {
|
if !captcha_settings.enabled {
|
||||||
return Ok(GetCaptchaResponse { ok: None });
|
return Ok(GetCaptchaResponse { ok: None });
|
||||||
|
@ -757,7 +757,7 @@ impl Perform for PasswordReset {
|
||||||
email,
|
email,
|
||||||
&local_user_view.person.name,
|
&local_user_view.person.name,
|
||||||
html,
|
html,
|
||||||
context.settings(),
|
&context.settings(),
|
||||||
)
|
)
|
||||||
.map_err(|e| ApiError::err(&e))?;
|
.map_err(|e| ApiError::err(&e))?;
|
||||||
|
|
||||||
|
|
|
@ -181,7 +181,7 @@ impl Perform for Search {
|
||||||
let community_actor_id = data
|
let community_actor_id = data
|
||||||
.community_name
|
.community_name
|
||||||
.as_ref()
|
.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);
|
.unwrap_or(None);
|
||||||
let creator_id = data.creator_id;
|
let creator_id = data.creator_id;
|
||||||
match search_type {
|
match search_type {
|
||||||
|
|
|
@ -125,7 +125,7 @@ impl PerformCrud for CreateComment {
|
||||||
post,
|
post,
|
||||||
context.pool(),
|
context.pool(),
|
||||||
true,
|
true,
|
||||||
context.settings(),
|
&context.settings(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ impl PerformCrud for DeleteComment {
|
||||||
post,
|
post,
|
||||||
context.pool(),
|
context.pool(),
|
||||||
false,
|
false,
|
||||||
context.settings(),
|
&context.settings(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ impl PerformCrud for RemoveComment {
|
||||||
post,
|
post,
|
||||||
context.pool(),
|
context.pool(),
|
||||||
false,
|
false,
|
||||||
context.settings(),
|
&context.settings(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ impl PerformCrud for GetComments {
|
||||||
let community_actor_id = data
|
let community_actor_id = data
|
||||||
.community_name
|
.community_name
|
||||||
.as_ref()
|
.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);
|
.unwrap_or(None);
|
||||||
let saved_only = data.saved_only;
|
let saved_only = data.saved_only;
|
||||||
let page = data.page;
|
let page = data.page;
|
||||||
|
|
|
@ -83,7 +83,7 @@ impl PerformCrud for EditComment {
|
||||||
orig_comment.post,
|
orig_comment.post,
|
||||||
context.pool(),
|
context.pool(),
|
||||||
false,
|
false,
|
||||||
context.settings(),
|
&context.settings(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ impl PerformCrud for GetCommunity {
|
||||||
None => {
|
None => {
|
||||||
let name = data.name.to_owned().unwrap_or_else(|| "main".to_string());
|
let name = data.name.to_owned().unwrap_or_else(|| "main".to_string());
|
||||||
let community_actor_id =
|
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| {
|
blocking(context.pool(), move |conn| {
|
||||||
Community::read_from_apub_id(conn, &community_actor_id)
|
Community::read_from_apub_id(conn, &community_actor_id)
|
||||||
|
|
|
@ -54,7 +54,7 @@ impl PerformCrud for CreatePost {
|
||||||
// Fetch post links and pictrs cached image
|
// Fetch post links and pictrs cached image
|
||||||
let data_url = data.url.as_ref();
|
let data_url = data.url.as_ref();
|
||||||
let (metadata_res, pictrs_thumbnail) =
|
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
|
let (embed_title, embed_description, embed_html) = metadata_res
|
||||||
.map(|u| (u.title, u.description, u.html))
|
.map(|u| (u.title, u.description, u.html))
|
||||||
.unwrap_or((None, None, None));
|
.unwrap_or((None, None, None));
|
||||||
|
|
|
@ -135,7 +135,7 @@ impl PerformCrud for GetPosts {
|
||||||
let community_actor_id = data
|
let community_actor_id = data
|
||||||
.community_name
|
.community_name
|
||||||
.as_ref()
|
.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);
|
.unwrap_or(None);
|
||||||
let saved_only = data.saved_only;
|
let saved_only = data.saved_only;
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ impl PerformCrud for EditPost {
|
||||||
// Fetch post links and Pictrs cached image
|
// Fetch post links and Pictrs cached image
|
||||||
let data_url = data.url.as_ref();
|
let data_url = data.url.as_ref();
|
||||||
let (metadata_res, pictrs_thumbnail) =
|
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
|
let (embed_title, embed_description, embed_html) = metadata_res
|
||||||
.map(|u| (u.title, u.description, u.html))
|
.map(|u| (u.title, u.description, u.html))
|
||||||
.unwrap_or((None, None, None));
|
.unwrap_or((None, None, None));
|
||||||
|
|
|
@ -105,7 +105,7 @@ impl PerformCrud for CreatePrivateMessage {
|
||||||
"Private Message from",
|
"Private Message from",
|
||||||
"Private Message",
|
"Private Message",
|
||||||
&content_slurs_removed,
|
&content_slurs_removed,
|
||||||
context.settings(),
|
&context.settings(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,7 @@ impl PerformCrud for GetPersonDetails {
|
||||||
.to_owned()
|
.to_owned()
|
||||||
.unwrap_or_else(|| "admin".to_string());
|
.unwrap_or_else(|| "admin".to_string());
|
||||||
let actor_id =
|
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| {
|
let person = blocking(context.pool(), move |conn| {
|
||||||
Person::read_from_apub_id(conn, &actor_id)
|
Person::read_from_apub_id(conn, &actor_id)
|
||||||
|
|
|
@ -90,7 +90,7 @@ impl ActivityHandler for CreateOrUpdateComment {
|
||||||
let community = extract_community(&self.cc, context, request_counter).await?;
|
let community = extract_community(&self.cc, context, request_counter).await?;
|
||||||
let community_id = ObjectId::new(community.actor_id());
|
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_person_in_community(&self.actor, &community_id, context, request_counter).await?;
|
||||||
verify_domains_match(self.actor.inner(), self.object.id_unchecked())?;
|
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
|
// TODO: should add a check that the correct community is in cc (probably needs changes to
|
||||||
|
|
|
@ -46,7 +46,7 @@ async fn get_notif_recipients(
|
||||||
post,
|
post,
|
||||||
context.pool(),
|
context.pool(),
|
||||||
true,
|
true,
|
||||||
context.settings(),
|
&context.settings(),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ impl ActivityHandler for AddMod {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> 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_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
verify_mod_action(&self.actor, self.cc[0].clone(), context).await?;
|
verify_mod_action(&self.actor, self.cc[0].clone(), context).await?;
|
||||||
verify_add_remove_moderator_target(&self.target, &self.cc[0])?;
|
verify_add_remove_moderator_target(&self.target, &self.cc[0])?;
|
||||||
|
|
|
@ -103,7 +103,7 @@ impl ActivityHandler for AnnounceActivity {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
verify_activity(self, context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
verify_community(&self.actor, context, request_counter).await?;
|
verify_community(&self.actor, context, request_counter).await?;
|
||||||
self.object.verify(context, request_counter).await?;
|
self.object.verify(context, request_counter).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -95,7 +95,7 @@ impl ActivityHandler for BlockUserFromCommunity {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> 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_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
verify_mod_action(&self.actor, self.cc[0].clone(), context).await?;
|
verify_mod_action(&self.actor, self.cc[0].clone(), context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -20,7 +20,7 @@ async fn list_community_follower_inboxes(
|
||||||
Ok(
|
Ok(
|
||||||
vec![
|
vec![
|
||||||
community
|
community
|
||||||
.get_follower_inboxes(context.pool(), context.settings())
|
.get_follower_inboxes(context.pool(), &context.settings())
|
||||||
.await?,
|
.await?,
|
||||||
additional_inboxes,
|
additional_inboxes,
|
||||||
]
|
]
|
||||||
|
@ -28,7 +28,7 @@ async fn list_community_follower_inboxes(
|
||||||
.flatten()
|
.flatten()
|
||||||
.unique()
|
.unique()
|
||||||
.filter(|inbox| inbox.host_str() != Some(&context.settings().hostname))
|
.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())
|
.map(|inbox| inbox.to_owned())
|
||||||
.collect(),
|
.collect(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -86,7 +86,7 @@ impl ActivityHandler for RemoveMod {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
verify_activity(self, context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
if let Some(target) = &self.target {
|
if let Some(target) = &self.target {
|
||||||
verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
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_mod_action(&self.actor, self.cc[0].clone(), context).await?;
|
||||||
|
|
|
@ -82,7 +82,7 @@ impl ActivityHandler for UndoBlockUserFromCommunity {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> 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_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
verify_mod_action(&self.actor, self.cc[0].clone(), context).await?;
|
verify_mod_action(&self.actor, self.cc[0].clone(), context).await?;
|
||||||
self.object.verify(context, request_counter).await?;
|
self.object.verify(context, request_counter).await?;
|
||||||
|
|
|
@ -82,7 +82,7 @@ impl ActivityHandler for UpdateCommunity {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> 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_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
verify_mod_action(&self.actor, self.cc[0].clone(), context).await?;
|
verify_mod_action(&self.actor, self.cc[0].clone(), context).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -102,7 +102,7 @@ impl ActivityHandler for UpdateCommunity {
|
||||||
let updated_community = Group::from_apub_to_form(
|
let updated_community = Group::from_apub_to_form(
|
||||||
&self.object,
|
&self.object,
|
||||||
&community.actor_id.clone().into(),
|
&community.actor_id.clone().into(),
|
||||||
context.settings(),
|
&context.settings(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let cf = CommunityForm {
|
let cf = CommunityForm {
|
||||||
|
|
|
@ -87,7 +87,7 @@ impl ActivityHandler for Delete {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
verify_activity(self, context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
verify_delete_activity(
|
verify_delete_activity(
|
||||||
&self.object,
|
&self.object,
|
||||||
self,
|
self,
|
||||||
|
|
|
@ -59,7 +59,7 @@ impl ActivityHandler for UndoDelete {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
verify_activity(self, context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
self.object.verify(context, request_counter).await?;
|
self.object.verify(context, request_counter).await?;
|
||||||
verify_delete_activity(
|
verify_delete_activity(
|
||||||
&self.object.object,
|
&self.object.object,
|
||||||
|
|
|
@ -80,7 +80,7 @@ impl ActivityHandler for AcceptFollowCommunity {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> 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.to.inner(), self.object.actor())?;
|
||||||
verify_urls_match(self.actor(), self.object.to.inner())?;
|
verify_urls_match(self.actor(), self.object.to.inner())?;
|
||||||
verify_community(&self.actor, context, request_counter).await?;
|
verify_community(&self.actor, context, request_counter).await?;
|
||||||
|
|
|
@ -91,7 +91,7 @@ impl ActivityHandler for FollowCommunity {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
verify_activity(self, context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
verify_urls_match(self.to.inner(), self.object.inner())?;
|
verify_urls_match(self.to.inner(), self.object.inner())?;
|
||||||
verify_person(&self.actor, context, request_counter).await?;
|
verify_person(&self.actor, context, request_counter).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -74,7 +74,7 @@ impl ActivityHandler for UndoFollowCommunity {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> 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.to.inner(), self.object.object.inner())?;
|
||||||
verify_urls_match(self.actor(), self.object.actor())?;
|
verify_urls_match(self.actor(), self.object.actor())?;
|
||||||
verify_person(&self.actor, context, request_counter).await?;
|
verify_person(&self.actor, context, request_counter).await?;
|
||||||
|
|
|
@ -86,7 +86,7 @@ impl ActivityHandler for CreateOrUpdatePost {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
verify_activity(self, context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
let community = self.cc[0].dereference(context, request_counter).await?;
|
let community = self.cc[0].dereference(context, request_counter).await?;
|
||||||
verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
verify_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
match self.kind {
|
match self.kind {
|
||||||
|
|
|
@ -66,7 +66,7 @@ impl ActivityHandler for CreateOrUpdatePrivateMessage {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
verify_activity(self, context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
verify_person(&self.actor, context, request_counter).await?;
|
verify_person(&self.actor, context, request_counter).await?;
|
||||||
verify_domains_match(self.actor.inner(), self.object.id_unchecked())?;
|
verify_domains_match(self.actor.inner(), self.object.id_unchecked())?;
|
||||||
self.object.verify(context, request_counter).await?;
|
self.object.verify(context, request_counter).await?;
|
||||||
|
|
|
@ -77,7 +77,7 @@ impl ActivityHandler for DeletePrivateMessage {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
verify_activity(self, context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
verify_person(&self.actor, context, request_counter).await?;
|
verify_person(&self.actor, context, request_counter).await?;
|
||||||
verify_domains_match(self.actor.inner(), &self.object)?;
|
verify_domains_match(self.actor.inner(), &self.object)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -76,7 +76,7 @@ impl ActivityHandler for UndoDeletePrivateMessage {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
verify_activity(self, context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
verify_person(&self.actor, context, request_counter).await?;
|
verify_person(&self.actor, context, request_counter).await?;
|
||||||
verify_urls_match(self.actor(), self.object.actor())?;
|
verify_urls_match(self.actor(), self.object.actor())?;
|
||||||
verify_domains_match(self.actor(), &self.object.object)?;
|
verify_domains_match(self.actor(), &self.object.object)?;
|
||||||
|
|
|
@ -43,7 +43,7 @@ impl ActivityHandler for UndoRemovePostCommentOrCommunity {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
verify_activity(self, context.settings())?;
|
verify_activity(self, &context.settings())?;
|
||||||
self.object.verify(context, request_counter).await?;
|
self.object.verify(context, request_counter).await?;
|
||||||
|
|
||||||
verify_delete_activity(
|
verify_delete_activity(
|
||||||
|
|
|
@ -91,7 +91,7 @@ impl ActivityHandler for UndoVote {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> 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_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
verify_urls_match(self.actor(), self.object.actor())?;
|
verify_urls_match(self.actor(), self.object.actor())?;
|
||||||
self.object.verify(context, request_counter).await?;
|
self.object.verify(context, request_counter).await?;
|
||||||
|
|
|
@ -117,7 +117,7 @@ impl ActivityHandler for Vote {
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<(), LemmyError> {
|
) -> 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_person_in_community(&self.actor, &self.cc[0], context, request_counter).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ pub(crate) async fn fetch_community_outbox(
|
||||||
) -> Result<(), LemmyError> {
|
) -> Result<(), LemmyError> {
|
||||||
let outbox = fetch_remote_object::<OrderedCollection>(
|
let outbox = fetch_remote_object::<OrderedCollection>(
|
||||||
context.client(),
|
context.client(),
|
||||||
context.settings(),
|
&context.settings(),
|
||||||
outbox,
|
outbox,
|
||||||
recursion_counter,
|
recursion_counter,
|
||||||
)
|
)
|
||||||
|
@ -105,7 +105,7 @@ async fn fetch_community_mods(
|
||||||
if let Some(mods_url) = &group.moderators {
|
if let Some(mods_url) = &group.moderators {
|
||||||
let mods = fetch_remote_object::<OrderedCollection>(
|
let mods = fetch_remote_object::<OrderedCollection>(
|
||||||
context.client(),
|
context.client(),
|
||||||
context.settings(),
|
&context.settings(),
|
||||||
mods_url,
|
mods_url,
|
||||||
recursion_counter,
|
recursion_counter,
|
||||||
)
|
)
|
||||||
|
|
|
@ -34,7 +34,7 @@ pub(crate) async fn get_or_fetch_and_insert_post(
|
||||||
debug!("Fetching and creating remote post: {}", post_ap_id);
|
debug!("Fetching and creating remote post: {}", post_ap_id);
|
||||||
let page = fetch_remote_object::<Page>(
|
let page = fetch_remote_object::<Page>(
|
||||||
context.client(),
|
context.client(),
|
||||||
context.settings(),
|
&context.settings(),
|
||||||
post_ap_id,
|
post_ap_id,
|
||||||
recursion_counter,
|
recursion_counter,
|
||||||
)
|
)
|
||||||
|
@ -71,7 +71,7 @@ pub(crate) async fn get_or_fetch_and_insert_comment(
|
||||||
);
|
);
|
||||||
let comment = fetch_remote_object::<Note>(
|
let comment = fetch_remote_object::<Note>(
|
||||||
context.client(),
|
context.client(),
|
||||||
context.settings(),
|
&context.settings(),
|
||||||
comment_ap_id,
|
comment_ap_id,
|
||||||
recursion_counter,
|
recursion_counter,
|
||||||
)
|
)
|
||||||
|
|
|
@ -33,7 +33,7 @@ pub(crate) async fn get_or_fetch_and_upsert_person(
|
||||||
debug!("Fetching and updating from remote person: {}", apub_id);
|
debug!("Fetching and updating from remote person: {}", apub_id);
|
||||||
let person = fetch_remote_object::<ApubPerson>(
|
let person = fetch_remote_object::<ApubPerson>(
|
||||||
context.client(),
|
context.client(),
|
||||||
context.settings(),
|
&context.settings(),
|
||||||
apub_id,
|
apub_id,
|
||||||
recursion_counter,
|
recursion_counter,
|
||||||
)
|
)
|
||||||
|
@ -65,7 +65,7 @@ pub(crate) async fn get_or_fetch_and_upsert_person(
|
||||||
debug!("Fetching and creating remote person: {}", apub_id);
|
debug!("Fetching and creating remote person: {}", apub_id);
|
||||||
let person = fetch_remote_object::<ApubPerson>(
|
let person = fetch_remote_object::<ApubPerson>(
|
||||||
context.client(),
|
context.client(),
|
||||||
context.settings(),
|
&context.settings(),
|
||||||
apub_id,
|
apub_id,
|
||||||
recursion_counter,
|
recursion_counter,
|
||||||
)
|
)
|
||||||
|
|
|
@ -98,7 +98,7 @@ where
|
||||||
if is_activity_already_known(context.pool(), activity.id_unchecked()).await? {
|
if is_activity_already_known(context.pool(), activity.id_unchecked()).await? {
|
||||||
return Ok(HttpResponse::Ok().finish());
|
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());
|
info!("Verifying activity {}", activity.id_unchecked().to_string());
|
||||||
activity.verify(context, request_counter).await?;
|
activity.verify(context, request_counter).await?;
|
||||||
assert_activity_not_local(&activity, &context.settings().hostname)?;
|
assert_activity_not_local(&activity, &context.settings().hostname)?;
|
||||||
|
|
|
@ -178,7 +178,7 @@ impl FromApub for Community {
|
||||||
expected_domain: &Url,
|
expected_domain: &Url,
|
||||||
request_counter: &mut i32,
|
request_counter: &mut i32,
|
||||||
) -> Result<Community, LemmyError> {
|
) -> Result<Community, LemmyError> {
|
||||||
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??;
|
let community = blocking(context.pool(), move |conn| Community::upsert(conn, &form)).await??;
|
||||||
update_community_mods(group, &community, context, request_counter).await?;
|
update_community_mods(group, &community, context, request_counter).await?;
|
||||||
|
|
|
@ -155,7 +155,7 @@ impl FromApub for DbPerson {
|
||||||
check_slurs_opt(&display_name, slur_regex)?;
|
check_slurs_opt(&display_name, slur_regex)?;
|
||||||
check_slurs_opt(&bio, 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 {
|
let person_form = PersonForm {
|
||||||
name,
|
name,
|
||||||
|
|
|
@ -191,7 +191,7 @@ impl FromApub for Post {
|
||||||
|
|
||||||
let thumbnail_url: Option<Url> = page.image.clone().map(|i| i.url);
|
let thumbnail_url: Option<Url> = page.image.clone().map(|i| i.url);
|
||||||
let (metadata_res, pictrs_thumbnail) = if let Some(url) = &page.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 {
|
} else {
|
||||||
(None, thumbnail_url)
|
(None, thumbnail_url)
|
||||||
};
|
};
|
||||||
|
|
|
@ -59,10 +59,7 @@ async fn upload(
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut client_req = client.request_from(
|
let mut client_req = client.request_from(
|
||||||
format!(
|
format!("{}/image", pictrs_url(context.settings().pictrs_url)?),
|
||||||
"{}/image",
|
|
||||||
pictrs_url(context.settings().to_owned().pictrs_url)?
|
|
||||||
),
|
|
||||||
req.head(),
|
req.head(),
|
||||||
);
|
);
|
||||||
// remove content-encoding header so that pictrs doesnt send gzipped response
|
// remove content-encoding header so that pictrs doesnt send gzipped response
|
||||||
|
@ -92,7 +89,7 @@ async fn full_res(
|
||||||
let name = &filename.into_inner();
|
let name = &filename.into_inner();
|
||||||
|
|
||||||
// If there are no query params, the URL is original
|
// 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() {
|
let url = if params.format.is_none() && params.thumbnail.is_none() {
|
||||||
format!(
|
format!(
|
||||||
"{}/image/original/{}",
|
"{}/image/original/{}",
|
||||||
|
@ -160,7 +157,7 @@ async fn delete(
|
||||||
|
|
||||||
let url = format!(
|
let url = format!(
|
||||||
"{}/image/delete/{}/{}",
|
"{}/image/delete/{}/{}",
|
||||||
pictrs_url(context.settings().to_owned().pictrs_url)?,
|
pictrs_url(context.settings().pictrs_url)?,
|
||||||
&token,
|
&token,
|
||||||
&file
|
&file
|
||||||
);
|
);
|
||||||
|
|
|
@ -2,12 +2,17 @@ use crate::{location_info, settings::structs::Settings, LemmyError};
|
||||||
use anyhow::{anyhow, Context};
|
use anyhow::{anyhow, Context};
|
||||||
use deser_hjson::from_str;
|
use deser_hjson::from_str;
|
||||||
use regex::{Regex, RegexBuilder};
|
use regex::{Regex, RegexBuilder};
|
||||||
use std::{env, fs, io::Error};
|
use std::{env, fs, io::Error, sync::RwLock};
|
||||||
|
|
||||||
pub mod structs;
|
pub mod structs;
|
||||||
|
|
||||||
static CONFIG_FILE: &str = "config/config.hjson";
|
static CONFIG_FILE: &str = "config/config.hjson";
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref SETTINGS: RwLock<Settings> =
|
||||||
|
RwLock::new(Settings::init().expect("Failed to load settings file"));
|
||||||
|
}
|
||||||
|
|
||||||
impl Settings {
|
impl Settings {
|
||||||
/// Reads config from configuration file.
|
/// Reads config from configuration file.
|
||||||
///
|
///
|
||||||
|
@ -35,6 +40,11 @@ impl Settings {
|
||||||
Ok(config)
|
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 {
|
pub fn get_database_url(&self) -> String {
|
||||||
let conf = &self.database;
|
let conf = &self.database;
|
||||||
format!(
|
format!(
|
||||||
|
@ -83,6 +93,15 @@ impl Settings {
|
||||||
|
|
||||||
pub fn save_config_file(data: &str) -> Result<String, LemmyError> {
|
pub fn save_config_file(data: &str) -> Result<String, LemmyError> {
|
||||||
fs::write(CONFIG_FILE, data)?;
|
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()?)
|
Ok(Self::read_config_file()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,8 +55,9 @@ impl LemmyContext {
|
||||||
pub fn activity_queue(&self) -> &QueueHandle {
|
pub fn activity_queue(&self) -> &QueueHandle {
|
||||||
&self.activity_queue
|
&self.activity_queue
|
||||||
}
|
}
|
||||||
pub fn settings(&self) -> &Settings {
|
pub fn settings(&self) -> Settings {
|
||||||
&self.settings
|
// TODO hacky solution to be able to hotload the settings.
|
||||||
|
Settings::get()
|
||||||
}
|
}
|
||||||
pub fn secret(&self) -> &Secret {
|
pub fn secret(&self) -> &Secret {
|
||||||
&self.secret
|
&self.secret
|
||||||
|
|
Loading…
Reference in New Issue