From 67369a494a00ae3404d517f52fa850a94efff95c Mon Sep 17 00:00:00 2001 From: Andrea Spacca Date: Sun, 7 Apr 2024 08:59:36 +0900 Subject: [PATCH] cr fixes --- Cargo.lock | 1 - Cargo.toml | 1 - src/utils.rs | 39 +++++++++++++++++++++++++-------------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 428c2d0..0645208 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1369,7 +1369,6 @@ dependencies = [ "bytes", "futures-util", "image", - "lazy_static", "libwebp-sys", "mimalloc", "once_cell", diff --git a/Cargo.toml b/Cargo.toml index c413696..1c9d347 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,6 @@ regex = "1.10.4" blake3 = { version = "1.5.1", optional = true } bytes = "1.6.0" futures-util = "0.3.30" -lazy_static = "1.4.0" [features] default = ["webp", "mimalloc", "reqwest-rustls", "qhash"] diff --git a/src/utils.rs b/src/utils.rs index b659c41..5f733d5 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,22 +1,15 @@ -use lazy_static::lazy_static; +use once_cell::sync::Lazy; use qstring::QString; use reqwest::Url; use std::borrow::Cow; use std::collections::BTreeMap; use std::env; -#[cfg(not(feature = "prefix-path"))] -lazy_static! { - static ref PREFIX_PATH: Option = Some(String::from("")); -} - #[cfg(feature = "prefix-path")] -lazy_static! { - static ref PREFIX_PATH: Option = match env::var("PREFIX_PATH") { - Ok(v) => Some(String::from(v)), - Err(e) => panic!("$PREFIX_PATH is not set ({})", e) - }; -} +static PREFIX_PATH: Lazy> = Lazy::new(|| match env::var("PREFIX_PATH") { + Ok(v) => Some(String::from(v)), + Err(e) => panic!("$PREFIX_PATH is not set ({})", e) +}); pub fn read_buf(buf: &[u8], pos: &mut usize) -> u8 { let byte = buf[*pos]; @@ -60,12 +53,30 @@ fn finalize_url(path: &str, query: BTreeMap) -> String { if qhash.is_some() { let mut query = QString::new(query.into_iter().collect::>()); query.add_pair(("qhash", qhash.unwrap())); - return format!("{}{}?{}", PREFIX_PATH.as_ref().unwrap().to_string(), path, query); + #[cfg(not(feature = "prefix-path"))] + { + return format!("{}?{}", path, query); + } + + + #[cfg(feature = "prefix-path")] + { + return format!("{}{}?{}", PREFIX_PATH.as_ref().unwrap().to_string(), path, query); + } } } let query = QString::new(query.into_iter().collect::>()); - format!("{}{}?{}", PREFIX_PATH.as_ref().unwrap().to_string(), path, query) + #[cfg(not(feature = "prefix-path"))] + { + format!("{}?{}", path, query) + } + + + #[cfg(feature = "prefix-path")] + { + format!("{}{}?{}", PREFIX_PATH.as_ref().unwrap().to_string(), path, query) + } } pub fn localize_url(url: &str, host: &str) -> String {