mirror of
https://github.com/TeamPiped/piped-proxy.git
synced 2024-08-14 23:50:45 +00:00
cr fixes
This commit is contained in:
parent
a9e34cb678
commit
67369a494a
3 changed files with 25 additions and 16 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1369,7 +1369,6 @@ dependencies = [
|
|||
"bytes",
|
||||
"futures-util",
|
||||
"image",
|
||||
"lazy_static",
|
||||
"libwebp-sys",
|
||||
"mimalloc",
|
||||
"once_cell",
|
||||
|
|
|
@ -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"]
|
||||
|
|
31
src/utils.rs
31
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<String> = Some(String::from(""));
|
||||
}
|
||||
|
||||
#[cfg(feature = "prefix-path")]
|
||||
lazy_static! {
|
||||
static ref PREFIX_PATH: Option<String> = match env::var("PREFIX_PATH") {
|
||||
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];
|
||||
|
@ -60,13 +53,31 @@ 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()));
|
||||
#[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<_>>());
|
||||
#[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 {
|
||||
if url.starts_with("https://") {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue