diff --git a/Cargo.toml b/Cargo.toml index 7315b72..7f22b92 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,4 +15,4 @@ serde = { version = "1.0", features = ["derive"] } comrak = "0.24.1" tera = "1.19.1" isbot = "0.1.3" -lazy_static = "1.4.0" +once_cell = "1.19.0" diff --git a/src/main.rs b/src/main.rs index 11cbe2f..c177675 100644 --- a/src/main.rs +++ b/src/main.rs @@ -14,17 +14,20 @@ use comrak::{markdown_to_html, Options}; use controllers::posts; use dotenv::dotenv; use isbot::Bots; -use lazy_static::lazy_static; use rocket::fs::{FileServer, NamedFile}; use rocket::http::Status; use rocket::request::{FromRequest, Outcome, Request}; use rocket::response::content::RawXml; +use rocket::tokio::sync::OnceCell; use rocket_dyn_templates::Template; use std::path::Path; use std::vec::Vec; -lazy_static! { - static ref ISBOT: Bots = Bots::default(); +static BOTS: OnceCell = OnceCell::const_new(); + +async fn is_bot(ua: &String) -> bool { + let bots = BOTS.get_or_init(|| async { Bots::default() }).await; + bots.is_bot(ua) } struct Headers { @@ -98,13 +101,13 @@ fn atom_feed() -> RawXml