diff --git a/crates/core/database/src/models/admin_migrations/ops/mongodb/scripts.rs b/crates/core/database/src/models/admin_migrations/ops/mongodb/scripts.rs index 6b822380..bed5a6bb 100644 --- a/crates/core/database/src/models/admin_migrations/ops/mongodb/scripts.rs +++ b/crates/core/database/src/models/admin_migrations/ops/mongodb/scripts.rs @@ -830,7 +830,8 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 { claimed.insert(format!("{}#{}", info.username, discriminator)); info!( - "({i}/{}) Migrating user \"{}\" to #{} - compliant", + "({}/{}) Migrating user \"{}\" to #{} - compliant", + i + 1, users.len(), info.username, discriminator @@ -874,7 +875,8 @@ pub async fn run_migrations(db: &MongoDb, revision: i32) -> i32 { claimed.insert(format!("{}#{}", sanitised, discriminator)); info!( - "({i}/{}) Migrating user \"{}\" to #{} - sanitised: \"{}\"", + "({}/{}) Migrating user \"{}\" to #{} - sanitised: \"{}\"", + i + 1, users.len(), info.username, discriminator, diff --git a/crates/delta/src/routes/mod.rs b/crates/delta/src/routes/mod.rs index 4ae56abf..7b3f3e4c 100644 --- a/crates/delta/src/routes/mod.rs +++ b/crates/delta/src/routes/mod.rs @@ -1,3 +1,4 @@ +use revolt_quark::variables::delta::IS_STAGING; use revolt_rocket_okapi::{revolt_okapi::openapi3::OpenApi, settings::OpenApiSettings}; pub use rocket::http::Status; pub use rocket::response::Redirect; @@ -20,26 +21,48 @@ mod webhooks; pub fn mount(mut rocket: Rocket) -> Rocket { let settings = OpenApiSettings::default(); - mount_endpoints_and_merged_docs! { - rocket, "/".to_owned(), settings, - "/" => (vec![], custom_openapi_spec()), - "" => openapi_get_routes_spec![root::root, root::ping], - "/admin" => admin::routes(), - "/users" => users::routes(), - "/bots" => bots::routes(), - "/channels" => channels::routes(), - "/servers" => servers::routes(), - "/invites" => invites::routes(), - "/custom" => customisation::routes(), - "/safety" => safety::routes(), - "/auth/account" => rocket_authifier::routes::account::routes(), - "/auth/session" => rocket_authifier::routes::session::routes(), - "/auth/mfa" => rocket_authifier::routes::mfa::routes(), - "/onboard" => onboard::routes(), - "/push" => push::routes(), - "/sync" => sync::routes(), - "/webhooks" => webhooks::routes() - }; + if *IS_STAGING { + mount_endpoints_and_merged_docs! { + rocket, "/".to_owned(), settings, + "/" => (vec![], custom_openapi_spec()), + "" => openapi_get_routes_spec![root::root, root::ping], + "/admin" => admin::routes(), + "/users" => users::routes(), + "/bots" => bots::routes(), + "/channels" => channels::routes(), + "/servers" => servers::routes(), + "/invites" => invites::routes(), + "/custom" => customisation::routes(), + "/safety" => safety::routes(), + "/auth/account" => rocket_authifier::routes::account::routes(), + "/auth/session" => rocket_authifier::routes::session::routes(), + "/auth/mfa" => rocket_authifier::routes::mfa::routes(), + "/onboard" => onboard::routes(), + "/push" => push::routes(), + "/sync" => sync::routes(), + "/webhooks" => webhooks::routes() + }; + } else { + mount_endpoints_and_merged_docs! { + rocket, "/".to_owned(), settings, + "/" => (vec![], custom_openapi_spec()), + "" => openapi_get_routes_spec![root::root, root::ping], + "/admin" => admin::routes(), + "/users" => users::routes(), + "/bots" => bots::routes(), + "/channels" => channels::routes(), + "/servers" => servers::routes(), + "/invites" => invites::routes(), + "/custom" => customisation::routes(), + "/safety" => safety::routes(), + "/auth/account" => rocket_authifier::routes::account::routes(), + "/auth/session" => rocket_authifier::routes::session::routes(), + "/auth/mfa" => rocket_authifier::routes::mfa::routes(), + "/onboard" => onboard::routes(), + "/push" => push::routes(), + "/sync" => sync::routes() + }; + } rocket } @@ -298,11 +321,9 @@ fn custom_openapi_spec() -> OpenApi { }, Tag { name: "Webhooks".to_owned(), - description: Some( - "Send messages from 3rd party services".to_owned(), - ), + description: Some("Send messages from 3rd party services".to_owned()), ..Default::default() - } + }, ], ..Default::default() } diff --git a/crates/quark/src/util/variables/delta.rs b/crates/quark/src/util/variables/delta.rs index 1ae35fc2..0b920b1a 100644 --- a/crates/quark/src/util/variables/delta.rs +++ b/crates/quark/src/util/variables/delta.rs @@ -1,56 +1,141 @@ -use std::env; use once_cell::sync::Lazy; +use std::env; // Application Settings -pub static PUBLIC_URL: Lazy = Lazy::new(|| env::var("REVOLT_PUBLIC_URL").expect("Missing REVOLT_PUBLIC_URL environment variable.")); -pub static APP_URL: Lazy = Lazy::new(|| env::var("REVOLT_APP_URL").expect("Missing REVOLT_APP_URL environment variable.")); -pub static EXTERNAL_WS_URL: Lazy = Lazy::new(|| env::var("REVOLT_EXTERNAL_WS_URL").expect("Missing REVOLT_EXTERNAL_WS_URL environment variable.")); +pub static PUBLIC_URL: Lazy = Lazy::new(|| { + env::var("REVOLT_PUBLIC_URL").expect("Missing REVOLT_PUBLIC_URL environment variable.") +}); +pub static APP_URL: Lazy = + Lazy::new(|| env::var("REVOLT_APP_URL").expect("Missing REVOLT_APP_URL environment variable.")); +pub static EXTERNAL_WS_URL: Lazy = Lazy::new(|| { + env::var("REVOLT_EXTERNAL_WS_URL") + .expect("Missing REVOLT_EXTERNAL_WS_URL environment variable.") +}); -pub static AUTUMN_URL: Lazy = Lazy::new(|| env::var("AUTUMN_PUBLIC_URL").unwrap_or_else(|_| "https://example.com".to_string())); -pub static JANUARY_URL: Lazy = Lazy::new(|| env::var("JANUARY_PUBLIC_URL").unwrap_or_else(|_| "https://example.com".to_string())); -pub static JANUARY_CONCURRENT_CONNECTIONS: Lazy = Lazy::new(|| env::var("JANUARY_CONCURRENT_CONNECTIONS").map_or(50, |v| v.parse().unwrap())); -pub static VOSO_URL: Lazy = Lazy::new(|| env::var("VOSO_PUBLIC_URL").unwrap_or_else(|_| "https://example.com".to_string())); -pub static VOSO_WS_HOST: Lazy = Lazy::new(|| env::var("VOSO_WS_HOST").unwrap_or_else(|_| "wss://example.com".to_string())); -pub static VOSO_MANAGE_TOKEN: Lazy = Lazy::new(|| env::var("VOSO_MANAGE_TOKEN").unwrap_or_else(|_| "0".to_string())); +pub static AUTUMN_URL: Lazy = Lazy::new(|| { + env::var("AUTUMN_PUBLIC_URL").unwrap_or_else(|_| "https://example.com".to_string()) +}); +pub static JANUARY_URL: Lazy = Lazy::new(|| { + env::var("JANUARY_PUBLIC_URL").unwrap_or_else(|_| "https://example.com".to_string()) +}); +pub static JANUARY_CONCURRENT_CONNECTIONS: Lazy = + Lazy::new(|| env::var("JANUARY_CONCURRENT_CONNECTIONS").map_or(50, |v| v.parse().unwrap())); +pub static VOSO_URL: Lazy = + Lazy::new(|| env::var("VOSO_PUBLIC_URL").unwrap_or_else(|_| "https://example.com".to_string())); +pub static VOSO_WS_HOST: Lazy = + Lazy::new(|| env::var("VOSO_WS_HOST").unwrap_or_else(|_| "wss://example.com".to_string())); +pub static VOSO_MANAGE_TOKEN: Lazy = + Lazy::new(|| env::var("VOSO_MANAGE_TOKEN").unwrap_or_else(|_| "0".to_string())); -pub static HCAPTCHA_KEY: Lazy = Lazy::new(|| env::var("REVOLT_HCAPTCHA_KEY").unwrap_or_else(|_| "0x0000000000000000000000000000000000000000".to_string())); -pub static HCAPTCHA_SITEKEY: Lazy = Lazy::new(|| env::var("REVOLT_HCAPTCHA_SITEKEY").unwrap_or_else(|_| "10000000-ffff-ffff-ffff-000000000001".to_string())); -pub static VAPID_PRIVATE_KEY: Lazy = Lazy::new(|| env::var("REVOLT_VAPID_PRIVATE_KEY").expect("Missing REVOLT_VAPID_PRIVATE_KEY environment variable.")); -pub static VAPID_PUBLIC_KEY: Lazy = Lazy::new(|| env::var("REVOLT_VAPID_PUBLIC_KEY").expect("Missing REVOLT_VAPID_PUBLIC_KEY environment variable.")); -pub static AUTHIFIER_SHIELD_KEY: Lazy> = Lazy::new(|| env::var("REVOLT_AUTHIFIER_SHIELD_KEY").ok()); +pub static HCAPTCHA_KEY: Lazy = Lazy::new(|| { + env::var("REVOLT_HCAPTCHA_KEY") + .unwrap_or_else(|_| "0x0000000000000000000000000000000000000000".to_string()) +}); +pub static HCAPTCHA_SITEKEY: Lazy = Lazy::new(|| { + env::var("REVOLT_HCAPTCHA_SITEKEY") + .unwrap_or_else(|_| "10000000-ffff-ffff-ffff-000000000001".to_string()) +}); +pub static VAPID_PRIVATE_KEY: Lazy = Lazy::new(|| { + env::var("REVOLT_VAPID_PRIVATE_KEY") + .expect("Missing REVOLT_VAPID_PRIVATE_KEY environment variable.") +}); +pub static VAPID_PUBLIC_KEY: Lazy = Lazy::new(|| { + env::var("REVOLT_VAPID_PUBLIC_KEY") + .expect("Missing REVOLT_VAPID_PUBLIC_KEY environment variable.") +}); +pub static AUTHIFIER_SHIELD_KEY: Lazy> = + Lazy::new(|| env::var("REVOLT_AUTHIFIER_SHIELD_KEY").ok()); // Application Flags -pub static INVITE_ONLY: Lazy = Lazy::new(|| env::var("REVOLT_INVITE_ONLY").map_or(false, |v| v == "1")); -pub static USE_EMAIL: Lazy = Lazy::new(|| env::var("REVOLT_USE_EMAIL_VERIFICATION").map_or( - env::var("REVOLT_SMTP_HOST").is_ok() - && env::var("REVOLT_SMTP_USERNAME").is_ok() - && env::var("REVOLT_SMTP_PASSWORD").is_ok() - && env::var("REVOLT_SMTP_FROM").is_ok(), - |v| v == *"1" -)); +pub static INVITE_ONLY: Lazy = + Lazy::new(|| env::var("REVOLT_INVITE_ONLY").map_or(false, |v| v == "1")); +pub static USE_EMAIL: Lazy = Lazy::new(|| { + env::var("REVOLT_USE_EMAIL_VERIFICATION").map_or( + env::var("REVOLT_SMTP_HOST").is_ok() + && env::var("REVOLT_SMTP_USERNAME").is_ok() + && env::var("REVOLT_SMTP_PASSWORD").is_ok() + && env::var("REVOLT_SMTP_FROM").is_ok(), + |v| v == *"1", + ) +}); pub static USE_HCAPTCHA: Lazy = Lazy::new(|| env::var("REVOLT_HCAPTCHA_KEY").is_ok()); pub static USE_AUTUMN: Lazy = Lazy::new(|| env::var("AUTUMN_PUBLIC_URL").is_ok()); pub static USE_JANUARY: Lazy = Lazy::new(|| env::var("JANUARY_PUBLIC_URL").is_ok()); -pub static USE_VOSO: Lazy = Lazy::new(|| env::var("VOSO_PUBLIC_URL").is_ok() && env::var("VOSO_MANAGE_TOKEN").is_ok()); +pub static USE_VOSO: Lazy = + Lazy::new(|| env::var("VOSO_PUBLIC_URL").is_ok() && env::var("VOSO_MANAGE_TOKEN").is_ok()); // SMTP Settings -pub static SMTP_HOST: Lazy = Lazy::new(|| env::var("REVOLT_SMTP_HOST").unwrap_or_else(|_| "".to_string())); -pub static SMTP_USERNAME: Lazy = Lazy::new(|| env::var("REVOLT_SMTP_USERNAME").unwrap_or_else(|_| "".to_string())); -pub static SMTP_PASSWORD: Lazy = Lazy::new(|| env::var("REVOLT_SMTP_PASSWORD").unwrap_or_else(|_| "".to_string())); -pub static SMTP_FROM: Lazy = Lazy::new(|| env::var("REVOLT_SMTP_FROM").unwrap_or_else(|_| "".to_string())); +pub static SMTP_HOST: Lazy = + Lazy::new(|| env::var("REVOLT_SMTP_HOST").unwrap_or_else(|_| "".to_string())); +pub static SMTP_USERNAME: Lazy = + Lazy::new(|| env::var("REVOLT_SMTP_USERNAME").unwrap_or_else(|_| "".to_string())); +pub static SMTP_PASSWORD: Lazy = + Lazy::new(|| env::var("REVOLT_SMTP_PASSWORD").unwrap_or_else(|_| "".to_string())); +pub static SMTP_FROM: Lazy = + Lazy::new(|| env::var("REVOLT_SMTP_FROM").unwrap_or_else(|_| "".to_string())); // Application Logic Settings -pub static MAX_GROUP_SIZE: Lazy = Lazy::new(|| env::var("REVOLT_MAX_GROUP_SIZE").unwrap_or_else(|_| "50".to_string()).parse().unwrap()); -pub static MAX_BOT_COUNT: Lazy = Lazy::new(|| env::var("REVOLT_MAX_BOT_COUNT").unwrap_or_else(|_| "10".to_string()).parse().unwrap()); -pub static MAX_EMBED_COUNT: Lazy = Lazy::new(|| env::var("REVOLT_MAX_EMBED_COUNT").unwrap_or_else(|_| "5".to_string()).parse().unwrap()); -pub static MAX_SERVER_COUNT: Lazy = Lazy::new(|| env::var("REVOLT_MAX_SERVER_COUNT").unwrap_or_else(|_| "100".to_string()).parse().unwrap()); -pub static MAX_CHANNEL_COUNT: Lazy = Lazy::new(|| env::var("REVOLT_MAX_CHANNEL_COUNT").unwrap_or_else(|_| "200".to_string()).parse().unwrap()); -pub static MAX_ROLE_COUNT: Lazy = Lazy::new(|| env::var("REVOLT_MAX_ROLE_COUNT").unwrap_or_else(|_| "200".to_string()).parse().unwrap()); -pub static MAX_EMOJI_COUNT: Lazy = Lazy::new(|| env::var("REVOLT_MAX_EMOJI_COUNT").unwrap_or_else(|_| "100".to_string()).parse().unwrap()); -pub static MAX_ATTACHMENT_COUNT: Lazy = Lazy::new(|| env::var("REVOLT_MAX_ATTACHMENT_COUNT").unwrap_or_else(|_| "5".to_string()).parse().unwrap()); -pub static MAX_REPLY_COUNT: Lazy = Lazy::new(|| env::var("REVOLT_MAX_REPLY_COUNT").unwrap_or_else(|_| "5".to_string()).parse().unwrap()); +pub static MAX_GROUP_SIZE: Lazy = Lazy::new(|| { + env::var("REVOLT_MAX_GROUP_SIZE") + .unwrap_or_else(|_| "50".to_string()) + .parse() + .unwrap() +}); +pub static MAX_BOT_COUNT: Lazy = Lazy::new(|| { + env::var("REVOLT_MAX_BOT_COUNT") + .unwrap_or_else(|_| "10".to_string()) + .parse() + .unwrap() +}); +pub static MAX_EMBED_COUNT: Lazy = Lazy::new(|| { + env::var("REVOLT_MAX_EMBED_COUNT") + .unwrap_or_else(|_| "5".to_string()) + .parse() + .unwrap() +}); +pub static MAX_SERVER_COUNT: Lazy = Lazy::new(|| { + env::var("REVOLT_MAX_SERVER_COUNT") + .unwrap_or_else(|_| "100".to_string()) + .parse() + .unwrap() +}); +pub static MAX_CHANNEL_COUNT: Lazy = Lazy::new(|| { + env::var("REVOLT_MAX_CHANNEL_COUNT") + .unwrap_or_else(|_| "200".to_string()) + .parse() + .unwrap() +}); +pub static MAX_ROLE_COUNT: Lazy = Lazy::new(|| { + env::var("REVOLT_MAX_ROLE_COUNT") + .unwrap_or_else(|_| "200".to_string()) + .parse() + .unwrap() +}); +pub static MAX_EMOJI_COUNT: Lazy = Lazy::new(|| { + env::var("REVOLT_MAX_EMOJI_COUNT") + .unwrap_or_else(|_| "100".to_string()) + .parse() + .unwrap() +}); +pub static MAX_ATTACHMENT_COUNT: Lazy = Lazy::new(|| { + env::var("REVOLT_MAX_ATTACHMENT_COUNT") + .unwrap_or_else(|_| "5".to_string()) + .parse() + .unwrap() +}); +pub static MAX_REPLY_COUNT: Lazy = Lazy::new(|| { + env::var("REVOLT_MAX_REPLY_COUNT") + .unwrap_or_else(|_| "5".to_string()) + .parse() + .unwrap() +}); -pub static EARLY_ADOPTER_BADGE: Lazy = Lazy::new(|| env::var("REVOLT_EARLY_ADOPTER_BADGE").unwrap_or_else(|_| "0".to_string()).parse().unwrap()); +pub static EARLY_ADOPTER_BADGE: Lazy = Lazy::new(|| { + env::var("REVOLT_EARLY_ADOPTER_BADGE") + .unwrap_or_else(|_| "0".to_string()) + .parse() + .unwrap() +}); pub fn preflight_checks() { format!("url = {}", *APP_URL); @@ -80,3 +165,7 @@ pub fn preflight_checks() { warn!("No Captcha key specified! Remember to add hCaptcha key."); } } + +// Production / staging configuration +pub static IS_STAGING: Lazy = + Lazy::new(|| env::var("REVOLT_IS_STAGING").map_or(false, |v| v == "1"));