chore: refactor generic web server code into quark
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/// Configure logging and common Rust variables
|
||||
pub fn setup_logging() -> sentry::ClientInitGuard {
|
||||
pub fn setup_logging(release: &'static str) -> sentry::ClientInitGuard {
|
||||
dotenv::dotenv().ok();
|
||||
|
||||
if std::env::var("RUST_LOG").is_err() {
|
||||
@@ -11,12 +11,24 @@ pub fn setup_logging() -> sentry::ClientInitGuard {
|
||||
}
|
||||
|
||||
pretty_env_logger::init();
|
||||
info!("Starting {release}");
|
||||
|
||||
sentry::init((
|
||||
"https://62fd0e02c5354905b4e286757f4beb16@sentry.insert.moe/4",
|
||||
sentry::ClientOptions {
|
||||
release: sentry::release_name!(),
|
||||
release: Some(release.into()),
|
||||
..Default::default()
|
||||
},
|
||||
))
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! configure {
|
||||
() => {
|
||||
let _sentry = revolt_quark::util::log::setup_logging(concat!(
|
||||
env!("CARGO_PKG_NAME"),
|
||||
"@",
|
||||
env!("CARGO_PKG_VERSION")
|
||||
));
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
pub mod log;
|
||||
pub mod manipulation;
|
||||
pub mod pfp;
|
||||
pub mod rauth;
|
||||
pub mod r#ref;
|
||||
pub mod result;
|
||||
pub mod value;
|
||||
|
||||
13
crates/quark/src/util/pfp.rs
Normal file
13
crates/quark/src/util/pfp.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
pub fn avatar(v: char) -> Vec<u8> {
|
||||
match v {
|
||||
// 0123456789ABCDEFGHJKMNPQRSTVWXYZ
|
||||
'0' | '1' | '2' | '3' | 'S' | 'Z' => include_bytes!(crate::asset!("user/2.png")).to_vec(),
|
||||
'4' | '5' | '6' | '7' | 'T' => include_bytes!(crate::asset!("user/3.png")).to_vec(),
|
||||
'8' | '9' | 'A' | 'B' => include_bytes!(crate::asset!("user/4.png")).to_vec(),
|
||||
'C' | 'D' | 'E' | 'F' | 'V' => include_bytes!(crate::asset!("user/5.png")).to_vec(),
|
||||
'G' | 'H' | 'J' | 'K' | 'W' => include_bytes!(crate::asset!("user/6.png")).to_vec(),
|
||||
'M' | 'N' | 'P' | 'Q' | 'X' => include_bytes!(crate::asset!("user/7.png")).to_vec(),
|
||||
/*'0' | '1' | '2' | '3' | 'R' | 'Y'*/
|
||||
_ => include_bytes!(crate::asset!("user/1.png")).to_vec(),
|
||||
}
|
||||
}
|
||||
57
crates/quark/src/util/rauth.rs
Normal file
57
crates/quark/src/util/rauth.rs
Normal file
@@ -0,0 +1,57 @@
|
||||
use super::variables::delta::{
|
||||
APP_URL, HCAPTCHA_KEY, INVITE_ONLY, SMTP_FROM, SMTP_HOST, SMTP_PASSWORD, SMTP_USERNAME,
|
||||
USE_EMAIL, USE_HCAPTCHA,
|
||||
};
|
||||
|
||||
use crate::rauth::config::{
|
||||
Captcha, Config, EmailVerificationConfig, SMTPSettings, Template, Templates,
|
||||
};
|
||||
|
||||
pub fn config() -> Config {
|
||||
let mut config = Config {
|
||||
email_verification: if *USE_EMAIL {
|
||||
EmailVerificationConfig::Enabled {
|
||||
smtp: SMTPSettings {
|
||||
from: (*SMTP_FROM).to_string(),
|
||||
host: (*SMTP_HOST).to_string(),
|
||||
username: (*SMTP_USERNAME).to_string(),
|
||||
password: (*SMTP_PASSWORD).to_string(),
|
||||
reply_to: Some("support@revolt.chat".into()),
|
||||
port: None,
|
||||
use_tls: None,
|
||||
},
|
||||
expiry: Default::default(),
|
||||
templates: Templates {
|
||||
verify: Template {
|
||||
title: "Verify your Revolt account.".into(),
|
||||
text: include_str!(crate::asset!("templates/verify.txt")).into(),
|
||||
url: format!("{}/login/verify/", *APP_URL),
|
||||
html: None,
|
||||
},
|
||||
reset: Template {
|
||||
title: "Reset your Revolt password.".into(),
|
||||
text: include_str!(crate::asset!("templates/reset.txt")).into(),
|
||||
url: format!("{}/login/reset/", *APP_URL),
|
||||
html: None,
|
||||
},
|
||||
welcome: None,
|
||||
},
|
||||
}
|
||||
} else {
|
||||
EmailVerificationConfig::Disabled
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
if *INVITE_ONLY {
|
||||
config.invite_only = true;
|
||||
}
|
||||
|
||||
if *USE_HCAPTCHA {
|
||||
config.captcha = Captcha::HCaptcha {
|
||||
secret: HCAPTCHA_KEY.clone(),
|
||||
};
|
||||
}
|
||||
|
||||
config
|
||||
}
|
||||
@@ -1,8 +1,5 @@
|
||||
use std::env;
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
use log::warn;
|
||||
|
||||
lazy_static! {
|
||||
// Application Settings
|
||||
pub static ref PUBLIC_URL: String =
|
||||
|
||||
Reference in New Issue
Block a user