From 507d3e6183a0af7822212cfeb72715fcca875bc3 Mon Sep 17 00:00:00 2001 From: Bat Date: Tue, 26 Jun 2018 16:21:58 +0200 Subject: [PATCH] Use USE_HTTPS to compute AP URLs Instead of relying on cfg(debug_assertions) --- plume-common/src/activity_pub/mod.rs | 10 ---------- plume-models/src/comments.rs | 4 ++-- plume-models/src/instance.rs | 2 +- plume-models/src/lib.rs | 9 +++++++++ plume-models/src/posts.rs | 4 ++-- plume-models/src/users.rs | 4 ++-- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/plume-common/src/activity_pub/mod.rs b/plume-common/src/activity_pub/mod.rs index 5b35ff6..93c8b09 100644 --- a/plume-common/src/activity_pub/mod.rs +++ b/plume-common/src/activity_pub/mod.rs @@ -17,16 +17,6 @@ pub mod sign; pub const CONTEXT_URL: &'static str = "https://www.w3.org/ns/activitystreams"; pub const PUBLIC_VISIBILTY: &'static str = "https://www.w3.org/ns/activitystreams#Public"; -#[cfg(debug_assertions)] -pub fn ap_url(url: String) -> String { - format!("http://{}", url) -} - -#[cfg(not(debug_assertions))] -pub fn ap_url(url: String) -> String { - format!("https://{}", url) -} - pub fn context() -> serde_json::Value { json!([ CONTEXT_URL, diff --git a/plume-models/src/comments.rs b/plume-models/src/comments.rs index 1500006..a76b101 100644 --- a/plume-models/src/comments.rs +++ b/plume-models/src/comments.rs @@ -8,11 +8,11 @@ use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods, dsl:: use serde_json; use plume_common::activity_pub::{ - ap_url, Id, IntoId, PUBLIC_VISIBILTY, + Id, IntoId, PUBLIC_VISIBILTY, inbox::{FromActivity, Notify} }; use plume_common::utils; -use get_next_id; +use {get_next_id, ap_url}; use instance::Instance; use mentions::Mention; use notifications::*; diff --git a/plume-models/src/instance.rs b/plume-models/src/instance.rs index 7ac5b2e..8eef225 100644 --- a/plume-models/src/instance.rs +++ b/plume-models/src/instance.rs @@ -2,7 +2,7 @@ use chrono::NaiveDateTime; use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection}; use std::iter::Iterator; -use plume_common::activity_pub::ap_url; +use ap_url; use users::User; use schema::{instances, users}; diff --git a/plume-models/src/lib.rs b/plume-models/src/lib.rs index 8c35e42..3123937 100644 --- a/plume-models/src/lib.rs +++ b/plume-models/src/lib.rs @@ -92,6 +92,15 @@ lazy_static! { pub static ref USE_HTTPS: bool = env::var("USE_HTTPS").map(|val| val == "1").unwrap_or(true); } +pub fn ap_url(url: &str) -> String { + let scheme = if *USE_HTTPS { + "https" + } else { + "http" + }; + format!("{}://{}", scheme, url) +} + pub mod blog_authors; pub mod blogs; pub mod comments; diff --git a/plume-models/src/posts.rs b/plume-models/src/posts.rs index 4278855..856ec34 100644 --- a/plume-models/src/posts.rs +++ b/plume-models/src/posts.rs @@ -8,11 +8,11 @@ use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods, Belon use heck::KebabCase; use serde_json; -use BASE_URL; use plume_common::activity_pub::{ - PUBLIC_VISIBILTY, ap_url, Id, IntoId, + PUBLIC_VISIBILTY, Id, IntoId, inbox::FromActivity }; +use {BASE_URL, ap_url}; use blogs::Blog; use instance::Instance; use likes::Like; diff --git a/plume-models/src/users.rs b/plume-models/src/users.rs index ce51610..f3e41bd 100644 --- a/plume-models/src/users.rs +++ b/plume-models/src/users.rs @@ -13,7 +13,7 @@ use openssl::{ sign }; use plume_common::activity_pub::{ - ap_url, ActivityStream, Id, IntoId, ApSignature, PublicKey, + ActivityStream, Id, IntoId, ApSignature, PublicKey, inbox::WithInbox, sign::{Signer, gen_keypair} }; @@ -30,7 +30,7 @@ use serde_json; use url::Url; use webfinger::*; -use {BASE_URL, USE_HTTPS}; +use {BASE_URL, USE_HTTPS, ap_url}; use db_conn::DbConn; use blogs::Blog; use blog_authors::BlogAuthor;