Use USE_HTTPS to compute AP URLs

Instead of relying on cfg(debug_assertions)
This commit is contained in:
Bat 2018-06-26 16:21:58 +02:00
parent f805ec1d53
commit 507d3e6183
6 changed files with 16 additions and 17 deletions

View File

@ -17,16 +17,6 @@ pub mod sign;
pub const CONTEXT_URL: &'static str = "https://www.w3.org/ns/activitystreams"; 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"; 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 { pub fn context() -> serde_json::Value {
json!([ json!([
CONTEXT_URL, CONTEXT_URL,

View File

@ -8,11 +8,11 @@ use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods, dsl::
use serde_json; use serde_json;
use plume_common::activity_pub::{ use plume_common::activity_pub::{
ap_url, Id, IntoId, PUBLIC_VISIBILTY, Id, IntoId, PUBLIC_VISIBILTY,
inbox::{FromActivity, Notify} inbox::{FromActivity, Notify}
}; };
use plume_common::utils; use plume_common::utils;
use get_next_id; use {get_next_id, ap_url};
use instance::Instance; use instance::Instance;
use mentions::Mention; use mentions::Mention;
use notifications::*; use notifications::*;

View File

@ -2,7 +2,7 @@ use chrono::NaiveDateTime;
use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection}; use diesel::{self, QueryDsl, RunQueryDsl, ExpressionMethods, PgConnection};
use std::iter::Iterator; use std::iter::Iterator;
use plume_common::activity_pub::ap_url; use ap_url;
use users::User; use users::User;
use schema::{instances, users}; use schema::{instances, users};

View File

@ -92,6 +92,15 @@ lazy_static! {
pub static ref USE_HTTPS: bool = env::var("USE_HTTPS").map(|val| val == "1").unwrap_or(true); 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 blog_authors;
pub mod blogs; pub mod blogs;
pub mod comments; pub mod comments;

View File

@ -8,11 +8,11 @@ use diesel::{self, PgConnection, RunQueryDsl, QueryDsl, ExpressionMethods, Belon
use heck::KebabCase; use heck::KebabCase;
use serde_json; use serde_json;
use BASE_URL;
use plume_common::activity_pub::{ use plume_common::activity_pub::{
PUBLIC_VISIBILTY, ap_url, Id, IntoId, PUBLIC_VISIBILTY, Id, IntoId,
inbox::FromActivity inbox::FromActivity
}; };
use {BASE_URL, ap_url};
use blogs::Blog; use blogs::Blog;
use instance::Instance; use instance::Instance;
use likes::Like; use likes::Like;

View File

@ -13,7 +13,7 @@ use openssl::{
sign sign
}; };
use plume_common::activity_pub::{ use plume_common::activity_pub::{
ap_url, ActivityStream, Id, IntoId, ApSignature, PublicKey, ActivityStream, Id, IntoId, ApSignature, PublicKey,
inbox::WithInbox, inbox::WithInbox,
sign::{Signer, gen_keypair} sign::{Signer, gen_keypair}
}; };
@ -30,7 +30,7 @@ use serde_json;
use url::Url; use url::Url;
use webfinger::*; use webfinger::*;
use {BASE_URL, USE_HTTPS}; use {BASE_URL, USE_HTTPS, ap_url};
use db_conn::DbConn; use db_conn::DbConn;
use blogs::Blog; use blogs::Blog;
use blog_authors::BlogAuthor; use blog_authors::BlogAuthor;