2020-12-15 13:35:04 +13:00
|
|
|
use actix_web::{client::Client, web, Error, HttpResponse, Result};
|
2020-11-30 15:50:29 +13:00
|
|
|
|
|
|
|
#[cfg(feature = "proxy")]
|
2020-12-01 17:33:55 +13:00
|
|
|
use base64::decode;
|
2020-11-23 17:22:51 +13:00
|
|
|
|
2020-12-15 13:35:04 +13:00
|
|
|
pub async fn handler(web::Path(url): web::Path<String>) -> Result<HttpResponse> {
|
2020-11-24 13:57:37 +13:00
|
|
|
if cfg!(feature = "proxy") {
|
2020-12-29 17:49:15 +13:00
|
|
|
#[cfg(feature = "proxy")]
|
2020-12-01 17:33:55 +13:00
|
|
|
let media: String;
|
2020-11-30 15:50:29 +13:00
|
|
|
|
|
|
|
#[cfg(not(feature = "proxy"))]
|
2020-12-01 17:33:55 +13:00
|
|
|
let media = url;
|
|
|
|
|
|
|
|
#[cfg(feature = "proxy")]
|
|
|
|
match decode(url) {
|
|
|
|
Ok(bytes) => media = String::from_utf8(bytes).unwrap(),
|
|
|
|
Err(_e) => return Ok(HttpResponse::Ok().body("")),
|
|
|
|
};
|
2020-11-30 15:50:29 +13:00
|
|
|
|
2020-11-24 13:57:37 +13:00
|
|
|
let client = Client::default();
|
2020-11-30 15:50:29 +13:00
|
|
|
client
|
2020-12-01 17:33:55 +13:00
|
|
|
.get(media.replace("&", "&"))
|
2020-11-24 13:57:37 +13:00
|
|
|
.send()
|
|
|
|
.await
|
|
|
|
.map_err(Error::from)
|
2020-11-30 15:50:29 +13:00
|
|
|
.and_then(|res| Ok(HttpResponse::build(res.status()).streaming(res)))
|
2020-11-24 13:57:37 +13:00
|
|
|
} else {
|
|
|
|
Ok(HttpResponse::Ok().body(""))
|
|
|
|
}
|
2020-11-30 15:50:29 +13:00
|
|
|
}
|