Skip to content

Commit

Permalink
fix: fix #91
Browse files Browse the repository at this point in the history
  • Loading branch information
lostb1t committed Oct 30, 2023
1 parent 3c2777d commit c2e7bc2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 10 deletions.
6 changes: 6 additions & 0 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ rstest = "0.18.1"
#[features]
#test = []

[patch.crates-io]
salvo-proxy = { path = "../salvo/crates/proxy" }
salvo_core = { path = "../salvo/crates/core" }
# [patch.crates-io]
# salvo-proxy = { path = "../salvo/crates/proxy" }
# salvo_core = { path = "../salvo/crates/core" }
#salvo-cache = { path = "../salvo/crates/cache" }

[profile.release]
Expand Down
6 changes: 6 additions & 0 deletions src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ pub struct Resolution {
pub width: i64,
}

#[derive(Serialize, Deserialize, Debug, Default, Clone)]
pub struct PlexContextProduct {
#[serde(default, rename(deserialize = "x-plex-product"))]
pub product: Option<String>,
}

#[derive(Serialize, Deserialize, Debug, Extractible, Default, Clone)]
#[salvo(extract(
default_source(from = "query"),
Expand Down
22 changes: 15 additions & 7 deletions src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,19 +196,27 @@ async fn should_skip(
depot: &mut Depot,
ctrl: &mut FlowCtrl,
) {
// let proxy = depot.obtain::<Proxy<String>>().unwrap().clone().to_owned();
// let proxy = depot.get::<Proxy<String>>("proxy").unwrap().to_owned();
// let proxy = depot.obtain::<Proxy<String>>().unwrap().clone().to_owned();

let params: PlexContext = req.extract().await.unwrap();
if params.product.is_some()
&& params.product.clone().unwrap().to_lowercase() == "plexamp"
// We do this because of a bug in extract. Which taks the body which is needed for proy
let queries: PlexContextProduct = req.parse_queries().unwrap();
let headers: PlexContextProduct = req.parse_headers().unwrap();
let product: Option<String> = if queries.product.is_some() {
queries.product
} else if headers.product.is_some() {
headers.product
} else {
None
};

if product.is_some()
&& product.clone().unwrap().to_lowercase() == "plexamp"
{

let config: Config = Config::figment().extract().unwrap();
let proxy = Proxy::with_client(
config.host.clone().unwrap(),
reqwest::Client::builder()
.timeout(Duration::from_secs(30))
.timeout(Duration::from_secs(60 * 200))
.build()
.unwrap(),
);
Expand Down

0 comments on commit c2e7bc2

Please sign in to comment.