mirror of
https://github.com/TeamPiped/piped-proxy.git
synced 2024-08-14 23:50:45 +00:00
replace lazy_static with once_cell
This commit is contained in:
parent
10a9acd99c
commit
86f5b67f2f
3 changed files with 254 additions and 280 deletions
501
Cargo.lock
generated
501
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -8,7 +8,7 @@ version = "0.1.0"
|
|||
[dependencies]
|
||||
actix-web = "4.3.1"
|
||||
image = "0.24.6"
|
||||
lazy_static = "1.4.0"
|
||||
once_cell = "1.17.1"
|
||||
qstring = "0.7.2"
|
||||
regex = "1.7.3"
|
||||
reqwest = {version = "0.11.15", features = ["rustls-tls", "stream", "brotli", "gzip"], default-features = false}
|
||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -4,7 +4,7 @@ use std::error::Error;
|
|||
use actix_web::{App, HttpRequest, HttpResponse, HttpResponseBuilder, HttpServer, web};
|
||||
use actix_web::http::Method;
|
||||
use image::EncodableLayout;
|
||||
use lazy_static::lazy_static;
|
||||
use once_cell::sync::Lazy;
|
||||
use qstring::QString;
|
||||
use regex::Regex;
|
||||
use reqwest::{Client, Request, Url};
|
||||
|
@ -27,27 +27,24 @@ async fn main() -> std::io::Result<()> {
|
|||
}.run().await
|
||||
}
|
||||
|
||||
lazy_static!(
|
||||
static ref RE_DOMAIN: Regex = Regex::new(r"^(?:[a-z\d\.-]*\.)?((?:[a-z\d-]*)\.(?:[a-z\d-]*))$").unwrap();
|
||||
static ref RE_MANIFEST: Regex = Regex::new("(?m)URI=\"([^\"]+)\"").unwrap();
|
||||
static ref RE_DASH_MANIFEST: Regex = Regex::new("BaseURL>(https://[^<]+)</BaseURL").unwrap();
|
||||
);
|
||||
static RE_DOMAIN: Lazy<Regex> = Lazy::new(|| Regex::new(r"^(?:[a-z\d.-]*\.)?((?:[a-z\d-]*)\.(?:[a-z\d-]*))$").unwrap());
|
||||
static RE_MANIFEST: Lazy<Regex> = Lazy::new(|| Regex::new("(?m)URI=\"([^\"]+)\"").unwrap());
|
||||
static RE_DASH_MANIFEST: Lazy<Regex> = Lazy::new(|| Regex::new("BaseURL>(https://[^<]+)</BaseURL").unwrap());
|
||||
|
||||
lazy_static!(
|
||||
static ref CLIENT: Client = {
|
||||
let builder = Client::builder()
|
||||
.user_agent("Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0");
|
||||
|
||||
if env::var("IPV4_ONLY").is_ok() {
|
||||
builder
|
||||
static CLIENT: Lazy<Client> = Lazy::new(|| {
|
||||
let builder = Client::builder()
|
||||
.user_agent("Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0");
|
||||
|
||||
if env::var("IPV4_ONLY").is_ok() {
|
||||
builder
|
||||
.local_address(Some("0.0.0.0".parse().unwrap()))
|
||||
.build()
|
||||
.unwrap()
|
||||
} else {
|
||||
builder.build().unwrap()
|
||||
}
|
||||
};
|
||||
);
|
||||
} else {
|
||||
builder.build().unwrap()
|
||||
}
|
||||
});
|
||||
|
||||
const ALLOWED_DOMAINS: [&str; 7] = [
|
||||
"youtube.com",
|
||||
|
|
Loading…
Reference in a new issue