diff --git a/Cargo.lock b/Cargo.lock index 3fcff40..19000f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -131,7 +131,7 @@ checksum = "c980ee35e870bd1a4d2c8294d4c04d0499e67bca1e4b5cefcc693c2fa00caea9" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.47", ] [[package]] @@ -397,7 +397,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.47", ] [[package]] @@ -636,7 +636,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.47", ] [[package]] @@ -824,7 +824,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.47", ] [[package]] @@ -906,20 +906,18 @@ dependencies = [ "html-escape", "mail-send", "md-5", + "rand", "sailfish", "serde", "serde-inline-default", "serde_default", - "serde_json", "sqlx", "teloxide", - "thiserror", "tokio", "tokio-rustls 0.25.0", "toml", "tracing", "tracing-subscriber", - "uuid", ] [[package]] @@ -1729,7 +1727,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.47", ] [[package]] @@ -1840,7 +1838,7 @@ checksum = "4359fd9c9171ec6e8c62926d6faaf553a8dc3f64e1507e76da7911b4f6a04405" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.47", ] [[package]] @@ -1920,9 +1918,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.74" +version = "1.0.75" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2de98502f212cfcea8d0bb305bd0f49d7ebdd75b64ba0a68f937d888f4e0d6db" +checksum = "907a61bd0f64c2f29cd1cf1dc34d05176426a3f504a78010f08416ddb7b13708" dependencies = [ "unicode-ident", ] @@ -2235,7 +2233,7 @@ dependencies = [ "proc-macro2", "quote", "serde", - "syn 2.0.46", + "syn 2.0.47", "toml", ] @@ -2343,7 +2341,7 @@ checksum = "a3385e45322e8f9931410f01b3031ec534c3947d0e94c18049af4d9f9907d4e0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.47", ] [[package]] @@ -2753,9 +2751,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.46" +version = "2.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89456b690ff72fddcecf231caedbe615c59480c93358a93dfae7fc29e3ebbf0e" +checksum = "1726efe18f42ae774cc644f330953a5e7b3c3003d3edcecf18850fe9d4dd9afb" dependencies = [ "proc-macro2", "quote", @@ -2900,7 +2898,7 @@ checksum = "fa0faa943b50f3db30a20aa7e265dbc66076993efed8463e8de414e5d06d3471" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.47", ] [[package]] @@ -2972,7 +2970,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.47", ] [[package]] @@ -3113,7 +3111,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.47", ] [[package]] @@ -3254,7 +3252,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e395fcf16a7a3d8127ec99782007af141946b4795001f876d54fb0d55978560" dependencies = [ "getrandom", - "rand", ] [[package]] @@ -3311,7 +3308,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.47", "wasm-bindgen-shared", ] @@ -3345,7 +3342,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.47", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3605,7 +3602,7 @@ checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" dependencies = [ "proc-macro2", "quote", - "syn 2.0.46", + "syn 2.0.47", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index 5f6a745..f39aa18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,14 +15,13 @@ edition = "2021" # core tracing = "0.1" tracing-subscriber = "0.3" -thiserror = "1" +rand = "0.8" md-5 = "0.10" toml = "0.8" -uuid = { version = "1.6", features = ["v4", "fast-rng"] } chrono = { version = "0.4", features = ["serde"] } serde = { version = "1", features = ["derive"] } -serde_json = "1" serde-inline-default = "0.1" # TODO this hopefully won't be needed anymore soon +serde_default = "0.1" async-trait = "0.1" html-escape = "0.2" clap = { version = "4.4", features = ["derive", "cargo"] } @@ -37,7 +36,6 @@ tokio-rustls = { version = "0.25", optional = true } # frontend sailfish = { version = "0.8", optional = true } axum-extra = { version = "0.9", optional = true } -serde_default = "0.1.0" [features] default = ["mysql", "sqlite", "postgres", "telegram", "email", "web"] # all features by default diff --git a/src/model.rs b/src/model.rs index c72e401..462530b 100644 --- a/src/model.rs +++ b/src/model.rs @@ -1,8 +1,8 @@ use md5::{Md5, Digest}; +use rand::{distributions::Alphanumeric, Rng}; use serde::{Serialize, Deserialize}; use chrono::{DateTime, Utc}; use sqlx::Row; -use uuid::Uuid; use crate::config::ConfigOverrides; @@ -52,7 +52,7 @@ pub struct PageView { impl From<&Page> for PageView { fn from(page: &Page) -> Self { let mut hasher = Md5::new(); - hasher.update(page.contact.as_deref().unwrap_or(&Uuid::new_v4().to_string()).as_bytes()); + hasher.update(page.contact.as_deref().unwrap_or(&random_string(36)).as_bytes()); let avatar = format!("{:x}", hasher.finalize()); let url = match page.contact.as_deref() { @@ -127,3 +127,11 @@ fn _non_empty_string(input: String) -> Option { false => Some(input), } } + +fn random_string(len: usize) -> String { + rand::thread_rng() + .sample_iter(&Alphanumeric) + .take(len) + .map(char::from) + .collect() +}