mirror of
https://github.com/redlib-org/redlib.git
synced 2025-05-15 06:22:50 +00:00
Added Percent Encoding Support
This commit is contained in:
parent
8f157c0b40
commit
9a6430656d
11 changed files with 63 additions and 16570 deletions
23
src/proxy.rs
23
src/proxy.rs
|
@ -1,18 +1,27 @@
|
|||
use actix_web::{get, web, HttpResponse, Result, client::Client, Error};
|
||||
use actix_web::{client::Client, get, web, Error, HttpResponse, Result};
|
||||
|
||||
#[cfg(feature = "proxy")]
|
||||
use percent_encoding::percent_decode_str;
|
||||
|
||||
#[get("/imageproxy/{url:.*}")]
|
||||
async fn handler(web::Path(url): web::Path<String>) -> Result<HttpResponse> {
|
||||
if cfg!(feature = "proxy") {
|
||||
dbg!(&url);
|
||||
#[cfg(feature = "proxy")]
|
||||
let media: String = percent_decode_str(url.as_str()).decode_utf8()?.to_string();
|
||||
|
||||
#[cfg(not(feature = "proxy"))]
|
||||
let media: String = url;
|
||||
|
||||
dbg!(&media);
|
||||
|
||||
let client = Client::default();
|
||||
client.get(url)
|
||||
client
|
||||
.get(media)
|
||||
.send()
|
||||
.await
|
||||
.map_err(Error::from)
|
||||
.and_then(|res| {
|
||||
Ok(HttpResponse::build(res.status()).streaming(res))
|
||||
})
|
||||
.and_then(|res| Ok(HttpResponse::build(res.status()).streaming(res)))
|
||||
} else {
|
||||
Ok(HttpResponse::Ok().body(""))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue