Skip to content

Commit

Permalink
fix: fix plexamp (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
lostb1t authored Sep 16, 2023
1 parent 8b7f0f9 commit 1e9df69
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@ pub fn route() -> Router {

let mut router = Router::with_hoop(Cors::permissive().into_handler())
.hoop(Logger::new())
.hoop(should_skip)
.hoop(Timeout::new(Duration::from_secs(30)))
.hoop(Compression::new().enable_gzip(CompressionLevel::Fastest))
//.hoop(max_concurrency(300))
.hoop(affix::insert("proxy", Arc::new(proxy.clone())));
// .hoop(affix::inject(Arc::new(proxy.clone())));
// .hoop(affix::insert("proxy", Arc::new(proxy.clone())));
.hoop(affix::insert("proxy", proxy.clone()));
// .hoop(affix::insert("script_engine", Arc::new(script_engine)));

if config.redirect_streams {
Expand Down Expand Up @@ -186,6 +189,34 @@ pub fn route() -> Router {
router
}

#[handler]
async fn should_skip(
req: &mut Request,
res: &mut Response,
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.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))
.build()
.unwrap(),
);

proxy.handle(req, depot, res, ctrl).await;
ctrl.skip_rest();
}
}


#[handler]
async fn redirect_stream(
req: &mut Request,
Expand Down

0 comments on commit 1e9df69

Please sign in to comment.