From: Dessalines Date: Tue, 11 Aug 2020 14:58:32 +0000 (-0400) Subject: Add a simple linked instances page. Fixes #1070 (#1071) X-Git-Url: http://these/git/%22https:/nerdica.net/%7B%60%24%7BwebArchiveUrl%7D/save/static/git-logo.png?a=commitdiff_plain;h=bc523abd629071cc411ffa24cfac690b06ff0a4a;p=lemmy.git Add a simple linked instances page. Fixes #1070 (#1071) * Add a simple linked instances page. Fixes #1070 * Changing allowed_instances to federated_instances. --- diff --git a/server/lemmy_utils/src/settings.rs b/server/lemmy_utils/src/settings.rs index 6a566de7..55b6cbb3 100644 --- a/server/lemmy_utils/src/settings.rs +++ b/server/lemmy_utils/src/settings.rs @@ -133,6 +133,20 @@ impl Settings { fs::read_to_string(CONFIG_FILE) } + pub fn get_allowed_instances(&self) -> Vec { + let mut allowed_instances: Vec = self + .federation + .allowed_instances + .split(',') + .map(|d| d.to_string()) + .collect(); + + // The defaults.hjson config always returns a [""] + allowed_instances.retain(|d| !d.eq("")); + + allowed_instances + } + pub fn save_config_file(data: &str) -> Result { fs::write(CONFIG_FILE, data)?; diff --git a/server/src/api/site.rs b/server/src/api/site.rs index dcbd6216..515c3e5b 100644 --- a/server/src/api/site.rs +++ b/server/src/api/site.rs @@ -130,6 +130,7 @@ pub struct GetSiteResponse { pub online: usize, version: String, my_user: Option, + federated_instances: Vec, } #[derive(Serialize, Deserialize)] @@ -433,6 +434,7 @@ impl Perform for Oper { online, version: version::VERSION.to_string(), my_user, + federated_instances: Settings::get().get_allowed_instances(), }) } } @@ -659,6 +661,7 @@ impl Perform for Oper { online: 0, version: version::VERSION.to_string(), my_user: Some(user), + federated_instances: Settings::get().get_allowed_instances(), }) } } diff --git a/server/src/apub/mod.rs b/server/src/apub/mod.rs index f6747198..49176268 100644 --- a/server/src/apub/mod.rs +++ b/server/src/apub/mod.rs @@ -76,12 +76,8 @@ fn check_is_apub_id_valid(apub_id: &Url) -> Result<(), LemmyError> { return Err(anyhow!("invalid apub id scheme: {:?}", apub_id.scheme()).into()); } - let mut allowed_instances: Vec = Settings::get() - .federation - .allowed_instances - .split(',') - .map(|d| d.to_string()) - .collect(); + let mut allowed_instances: Vec = Settings::get().get_allowed_instances(); + // need to allow this explicitly because apub activities might contain objects from our local // instance. replace is needed to remove the port in our federation test setup. let settings = Settings::get(); diff --git a/server/src/routes/index.rs b/server/src/routes/index.rs index b579a195..88a36c39 100644 --- a/server/src/routes/index.rs +++ b/server/src/routes/index.rs @@ -40,7 +40,8 @@ pub fn config(cfg: &mut web::ServiceConfig) { ) .route("/search", web::get().to(index)) .route("/sponsors", web::get().to(index)) - .route("/password_change/{token}", web::get().to(index)); + .route("/password_change/{token}", web::get().to(index)) + .route("/instances", web::get().to(index)); } async fn index() -> Result { diff --git a/ui/src/components/admin-settings.tsx b/ui/src/components/admin-settings.tsx index 8157d4a3..fe50b1e9 100644 --- a/ui/src/components/admin-settings.tsx +++ b/ui/src/components/admin-settings.tsx @@ -48,6 +48,7 @@ export class AdminSettings extends Component { banned: [], online: null, version: null, + federated_instances: null, }, siteConfigForm: { config_hjson: null, diff --git a/ui/src/components/footer.tsx b/ui/src/components/footer.tsx index e911370f..6e7acb7a 100644 --- a/ui/src/components/footer.tsx +++ b/ui/src/components/footer.tsx @@ -51,6 +51,11 @@ export class Footer extends Component { {i18n.t('modlog')} +