Skip to content

Commit

Permalink
cr fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aspacca committed Apr 6, 2024
1 parent a9e34cb commit 67369a4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
39 changes: 25 additions & 14 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -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<String> = Some(String::from(""));
}

#[cfg(feature = "prefix-path")]
lazy_static! {
static ref PREFIX_PATH: Option<String> = match env::var("PREFIX_PATH") {
Ok(v) => Some(String::from(v)),
Err(e) => panic!("$PREFIX_PATH is not set ({})", e)
};
}
static PREFIX_PATH: Lazy<Option<String>> = 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];
Expand Down Expand Up @@ -60,12 +53,30 @@ fn finalize_url(path: &str, query: BTreeMap<String, String>) -> String {
if qhash.is_some() {
let mut query = QString::new(query.into_iter().collect::<Vec<_>>());
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::<Vec<_>>());
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 {
Expand Down

0 comments on commit 67369a4

Please sign in to comment.