diff --git a/.gitignore b/.gitignore index c41cc9e..a617a21 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -/target \ No newline at end of file +/target +/.env \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 3c8cc76..20ee975 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -715,6 +715,12 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" +[[package]] +name = "dotenv" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77c90badedccf4105eca100756a0b1289e191f6fcbdadd3cee1d2f614f97da8f" + [[package]] name = "dtoa" version = "0.4.8" @@ -1204,8 +1210,10 @@ dependencies = [ "actix-web-actors", "base64", "clap", + "dotenv", "env_logger", "futures", + "lazy_static", "openssl", "rand 0.8.3", "serde", diff --git a/Cargo.toml b/Cargo.toml index 014eff3..9535c99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,11 +17,14 @@ actix-ratelimit = "0.3.1" env_logger = "0.8.3" openssl = "0.10.28" +dotenv = "0.15.0" clap = "2.33.3" +lazy_static = "1.4.0" + serde = "1.0.123" serde_json = "1.0.62" rand = "0.8.3" futures = "0.3.12" sha1 = "0.6.0" -base64 = "0.13.0" \ No newline at end of file +base64 = "0.13.0" diff --git a/src/main.rs b/src/main.rs index 40f75fd..89e8fec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,10 @@ //! |--> ws_sansad3 <---- / //! |--> ws_sansad4 <----/ //! + +#[macro_use] +extern crate lazy_static; + use actix_web::{ App, Error, HttpRequest, HttpResponse, HttpServer, middleware::Logger, web, client::{Client, Connector} @@ -24,8 +28,15 @@ mod broker_messages; mod ws_sansad; mod chat_pinnd; mod validator; + +lazy_static! { + pub static ref SALT: String = std::env::var("SALT").unwrap(); + pub static ref TENOR_API_KEY: String = std::env::var("TENOR_API_KEY").unwrap(); +} + #[actix_web::main] async fn main() -> std::io::Result<()> { + dotenv::dotenv().ok(); std::env::set_var("RUST_LOG", "actix_web=info"); env_logger::init(); let store = MemoryStore::new(); @@ -63,7 +74,7 @@ async fn gif(req: HttpRequest) -> Result { .finish(); - let url = format!("https://g.tenor.com/v1/search?q={}&key=LIVDSRZULELA&limit=20&media_filter=tinygif", name); + let url = format!("https://g.tenor.com/v1/search?q={}&key={}&limit=20&media_filter=tinygif", name, TENOR_API_KEY.to_owned()); let response = client.get(url) .header("User-Agent", "actix-web/3.0") .send() diff --git a/src/ws_sansad/users.rs b/src/ws_sansad/users.rs index 7178f6c..7672b17 100644 --- a/src/ws_sansad/users.rs +++ b/src/ws_sansad/users.rs @@ -22,7 +22,7 @@ impl WsSansad { // kunjika to hash and base64 let mut m = sha1::Sha1::new(); m.update(format!("{}{}",kunjika, - std::env::var("SALT").unwrap_or("".to_owned())).as_bytes()); + crate::SALT.to_owned()).as_bytes()); let kunjika = base64::encode(m.digest().bytes())[..8].to_owned(); let name = match val.get("name") { @@ -139,7 +139,7 @@ impl WsSansad { // kunjika to hash and base64 let mut m = sha1::Sha1::new(); m.update(format!("{}{}",kunjika, - std::env::var("SALT").unwrap_or("".to_owned())).as_bytes()); + crate::SALT.to_owned()).as_bytes()); let kunjika = base64::encode(m.digest().bytes())[..8].to_owned(); let name = match val.get("name") { diff --git a/static/index.html b/static/index.html index 7a4a59c..958f309 100644 --- a/static/index.html +++ b/static/index.html @@ -48,7 +48,7 @@
- Pick a random kunjika(id)
Don't share it
+ Pick a random kunjika(id). Don't share it