remove lazy_static from storyteller-web

This commit is contained in:
Brandon Thomas committed 2024-07-07 18:38:42 -04:00
1 parent 7bfd38a382
commit 17a4cf774d
16 files changed
+45 -59

No files matched your search

Generated
-1
View File
@@ -6802,7 +6802,6 @@ dependencies = [
"idempotency",
"infer 0.16.0",
"language-tags",
"lazy_static",
"lexical-sort",
"limitation",
"log",
@@ -81,7 +81,6 @@ chrono = { version = "0.4.22", features = ["serde"] }
derive_more = "0.99.17"
dotenv = "0.15.0"
hostname = "0.4.0"
lazy_static = "1.4.0" # Regex caching (TODO: Use OnceCell instead)
lexical-sort = "0.3.1"
log = "0.4.14"
once_cell = "1.18.0"
@@ -14,7 +14,6 @@
#![allow(dead_code)]
#![allow(non_snake_case)]
#[macro_use] extern crate lazy_static;
#[macro_use] extern crate magic_crypt;
#[macro_use] extern crate serde_derive;
@@ -14,7 +14,6 @@
#![allow(dead_code)]
#![allow(non_snake_case)]
#[macro_use] extern crate lazy_static;
#[macro_use] extern crate magic_crypt;
#[macro_use] extern crate serde_derive;
@@ -3,10 +3,10 @@ use std::ops::Deref;
use chrono::Utc;
use reusable_types::server_environment::ServerEnvironment;
use crate::http_server::session::lookup::user_session_extended::UserSessionExtended;
use crate::configs::plans::plan::Plan;
use crate::configs::plans::plan_list::{DEVELOPMENT_PREMIUM_PLANS_BY_SLUG, FREE_LOGGED_IN_PLAN, FREE_LOGGED_OUT_PLAN, LOYALTY_PLANS_BY_SLUG, PRODUCTION_PREMIUM_PLANS_BY_SLUG};
use crate::http_server::session::lookup::user_session_extended::UserSessionExtended;
/// Look up the most appropriate plan for the session.
/// This will probably grow to include a lot of factors.
@@ -68,10 +68,10 @@ pub mod tests {
use chrono::{Duration, Utc};
use reusable_types::server_environment::ServerEnvironment;
use users_component::session::lookup::user_session_extended::{UserSessionExtended, UserSessionSubscriptionPlan};
use crate::configs::plans::get_correct_plan_for_session::get_correct_plan_for_session;
use crate::configs::plans::plan_list::{ALL_PLANS_BY_SLUG, FREE_LOGGED_IN_PLAN, FREE_LOGGED_OUT_PLAN};
use crate::http_server::session::lookup::user_session_extended::{UserSessionExtended, UserSessionSubscriptionPlan};
#[test]
fn test_free_logged_out_plan() {
@@ -107,7 +107,7 @@ impl UserDefaultAvatarInfo {
mod tests {
use tokens::tokens::users::UserToken;
use crate::common_responses::user_details_lite::UserDetailsLight;
use crate::http_server::common_responses::user_details_lite::UserDetailsLight;
#[test]
fn test_from_optional_db_fields() {
@@ -69,7 +69,7 @@ impl AvtCookiePayload {
mod tests {
use tokens::tokens::anonymous_visitor_tracking::AnonymousVisitorTrackingToken;
use crate::cookies::anonymous_visitor_tracking::avt_cookie_payload::AvtCookiePayload;
use crate::http_server::cookies::anonymous_visitor_tracking::avt_cookie_payload::AvtCookiePayload;
#[test]
fn test_new() {
@@ -1,16 +1,16 @@
use std::collections::HashSet;
use once_cell::sync::Lazy;
use crate::configs::reserved_names::RESERVED_SUBSTRINGS;
use crate::configs::reserved_names::RESERVED_USERNAMES;
pub fn is_reserved_username(username: &str) -> bool {
lazy_static! {
static ref RESERVED_USERNAMES_SET : HashSet<String> = RESERVED_USERNAMES.lines()
.map(|line| line.trim())
.filter(|line| !(line.starts_with("#") || line.is_empty()))
.map(|line| line.to_string())
.collect::<HashSet<String>>();
}
static RESERVED_USERNAMES_SET : Lazy<HashSet<String>> = Lazy::new(|| RESERVED_USERNAMES.lines()
.map(|line| line.trim())
.filter(|line| !(line.starts_with("#") || line.is_empty()))
.map(|line| line.to_string())
.collect::<HashSet<String>>());
if RESERVED_USERNAMES_SET.contains(username) {
return true;
@@ -20,13 +20,11 @@ pub fn is_reserved_username(username: &str) -> bool {
}
fn is_reserved_substring(username: &str) -> bool {
lazy_static! {
static ref RESERVED_SUBSTRINGS_LIST : Vec<String> = RESERVED_SUBSTRINGS.lines()
.map(|line| line.trim())
.filter(|line| !(line.starts_with("#") || line.is_empty()))
.map(|line| line.to_string())
.collect::<Vec<String>>();
}
static RESERVED_SUBSTRINGS_LIST : Lazy<Vec<String>> = Lazy::new(|| RESERVED_SUBSTRINGS.lines()
.map(|line| line.trim())
.filter(|line| !(line.starts_with("#") || line.is_empty()))
.map(|line| line.to_string())
.collect::<Vec<String>>());
let undashed = username.replace("_", "").replace("-", "");
@@ -1,11 +1,10 @@
use once_cell::sync::Lazy;
use regex::Regex;
pub fn validate_profile_cashapp_username(username: &str) -> Result<(), String> {
lazy_static! {
static ref CASHAPP_USERNAME_REGEX: Regex = {
Regex::new(r"^\$?.{1,20}$").expect("should be valid regex")
};
}
static CASHAPP_USERNAME_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^\$?.{1,20}$").expect("should be valid regex")
});
if username.starts_with("$") {
if username.len() < 2 {
@@ -1,11 +1,10 @@
use once_cell::sync::Lazy;
use regex::Regex;
pub fn validate_profile_discord_username(username: &str) -> Result<(), String> {
lazy_static! {
static ref DISCORD_USERNAME_REGEX: Regex = {
Regex::new(r"^@?[^#@:]{2,32}#[0-9]{4}$").expect("should be valid regex")
};
}
static DISCORD_USERNAME_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^@?[^#@:]{2,32}#[0-9]{4}$").expect("should be valid regex")
});
if username.len() < 2 {
return Err("discord username is too short".to_string());
@@ -1,12 +1,11 @@
use once_cell::sync::Lazy;
use regex::Regex;
pub fn validate_profile_github_username(username: &str) -> Result<(), String> {
lazy_static! {
// TODO: https://github.com/shinnn/github-username-regex
static ref GITHUB_USERNAME_REGEX: Regex = {
Regex::new(r"^[a-zA-Z0-9\-]{1,39}$").expect("should be valid regex")
};
}
// TODO: https://github.com/shinnn/github-username-regex
static GITHUB_USERNAME_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^[a-zA-Z0-9\-]{1,39}$").expect("should be valid regex")
});
if username.len() < 1 {
return Err("github username is too short".to_string());
@@ -1,11 +1,10 @@
use once_cell::sync::Lazy;
use regex::Regex;
pub fn validate_profile_twitch_username(username: &str) -> Result<(), String> {
lazy_static! {
static ref TWITCH_USERNAME_REGEX: Regex = {
Regex::new(r"^[a-zA-Z0-9]{4,25}$").expect("should be valid regex")
};
}
static TWITCH_USERNAME_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^[a-zA-Z0-9]{4,25}$").expect("should be valid regex")
});
if username.len() < 4 {
return Err("twitch username is too short".to_string());
@@ -1,11 +1,10 @@
use once_cell::sync::Lazy;
use regex::Regex;
pub fn validate_profile_twitter_username(username: &str) -> Result<(), String> {
lazy_static! {
static ref TWITTER_USERNAME_REGEX: Regex = {
Regex::new("^@?[A-Za-z0-9_]{4,15}$").expect("should be valid regex")
};
}
static TWITTER_USERNAME_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new("^@?[A-Za-z0-9_]{4,15}$").expect("should be valid regex")
});
if username.starts_with("@") {
if username.len() < 5 {
@@ -1,11 +1,10 @@
use once_cell::sync::Lazy;
use regex::Regex;
pub fn validate_profile_website_url(website_url: &str) -> Result<(), String> {
lazy_static! {
static ref WEBSITE_URL_REGEX: Regex = {
Regex::new(r"^(https?:\\/\\/)?.*$").expect("should be valid regex")
};
}
static WEBSITE_URL_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^(https?:\\/\\/)?.*$").expect("should be valid regex")
});
if website_url.len() < 3 {
return Err("website url is too short".to_string());
@@ -1,11 +1,10 @@
use once_cell::sync::Lazy;
use regex::Regex;
pub fn validate_username(username: &str) -> Result<(), String> {
lazy_static! {
static ref USERNAME_REGEX: Regex = {
Regex::new(r"^[A-Za-z0-9_\-]{3,16}$").expect("should be valid regex")
};
}
static USERNAME_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(r"^[A-Za-z0-9_\-]{3,16}$").expect("should be valid regex")
});
if username.len() < 3 {
return Err("username is too short".to_string());
@@ -14,7 +14,6 @@
#![allow(dead_code)]
#![allow(non_snake_case)]
#[macro_use] extern crate lazy_static;
#[macro_use] extern crate magic_crypt;
#[macro_use] extern crate serde_derive;