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
84c790a154
commit
a83a14fc0c
4 changed files with 20 additions and 6 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -1423,6 +1423,7 @@ dependencies = [
|
|||
"bytes",
|
||||
"futures-util",
|
||||
"image",
|
||||
"lazy_static",
|
||||
"libwebp-sys",
|
||||
"mimalloc",
|
||||
"once_cell",
|
||||
|
|
|
@ -26,6 +26,7 @@ regex = "1.10.3"
|
|||
blake3 = { version = "1.5.0", optional = true }
|
||||
bytes = "1.5.0"
|
||||
futures-util = "0.3.30"
|
||||
lazy_static = "1.4.0"
|
||||
|
||||
[features]
|
||||
default = ["webp", "mimalloc", "reqwest-rustls", "qhash"]
|
||||
|
@ -42,5 +43,7 @@ optimized = ["libwebp-sys?/sse41", "libwebp-sys?/avx2", "libwebp-sys?/neon"]
|
|||
|
||||
qhash = ["blake3"]
|
||||
|
||||
prefix-path = []
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
|
|
|
@ -511,4 +511,4 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
|
|||
|
||||
// Stream response
|
||||
Ok(response.streaming(resp.bytes_stream()))
|
||||
}
|
||||
}
|
||||
|
|
20
src/utils.rs
20
src/utils.rs
|
@ -1,11 +1,22 @@
|
|||
use once_cell::sync::Lazy;
|
||||
use lazy_static::lazy_static;
|
||||
use qstring::QString;
|
||||
use reqwest::Url;
|
||||
use std::borrow::Cow;
|
||||
use std::collections::BTreeMap;
|
||||
use std::env;
|
||||
|
||||
static PREFIX_PATH: Lazy<String> = Lazy::new(|| String::from(env::var("PREFIX_PATH").unwrap_or_else(|_| "".to_string())));
|
||||
#[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)
|
||||
};
|
||||
}
|
||||
|
||||
pub fn read_buf(buf: &[u8], pos: &mut usize) -> u8 {
|
||||
let byte = buf[*pos];
|
||||
|
@ -17,7 +28,6 @@ fn finalize_url(path: &str, query: BTreeMap<String, String>) -> String {
|
|||
#[cfg(feature = "qhash")]
|
||||
{
|
||||
use std::collections::BTreeSet;
|
||||
use std::env;
|
||||
|
||||
let qhash = {
|
||||
let secret = env::var("HASH_SECRET");
|
||||
|
@ -50,12 +60,12 @@ 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_str(), path, query);
|
||||
return format!("{}{}?{}", PREFIX_PATH.as_ref().unwrap().to_string(), path, query);
|
||||
}
|
||||
}
|
||||
|
||||
let query = QString::new(query.into_iter().collect::<Vec<_>>());
|
||||
format!("{}{}?{}", PREFIX_PATH.as_str(), path, query)
|
||||
format!("{}{}?{}", PREFIX_PATH.as_ref().unwrap().to_string(), path, query)
|
||||
}
|
||||
|
||||
pub fn localize_url(url: &str, host: &str) -> String {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue