mirror of
https://github.com/redlib-org/redlib.git
synced 2025-05-15 06:22:50 +00:00
Use base64 for encoding & Upgrade Media Handling
This commit is contained in:
parent
9a6430656d
commit
9d78266494
7 changed files with 90 additions and 76 deletions
15
src/proxy.rs
15
src/proxy.rs
|
@ -1,22 +1,27 @@
|
|||
use actix_web::{client::Client, get, web, Error, HttpResponse, Result};
|
||||
|
||||
#[cfg(feature = "proxy")]
|
||||
use percent_encoding::percent_decode_str;
|
||||
use base64::decode;
|
||||
|
||||
#[get("/imageproxy/{url:.*}")]
|
||||
async fn handler(web::Path(url): web::Path<String>) -> Result<HttpResponse> {
|
||||
if cfg!(feature = "proxy") {
|
||||
#[cfg(feature = "proxy")]
|
||||
let media: String = percent_decode_str(url.as_str()).decode_utf8()?.to_string();
|
||||
let media: String;
|
||||
|
||||
#[cfg(not(feature = "proxy"))]
|
||||
let media: String = url;
|
||||
let media = url;
|
||||
|
||||
#[cfg(feature = "proxy")]
|
||||
match decode(url) {
|
||||
Ok(bytes) => media = String::from_utf8(bytes).unwrap(),
|
||||
Err(_e) => return Ok(HttpResponse::Ok().body("")),
|
||||
};
|
||||
|
||||
dbg!(&media);
|
||||
|
||||
let client = Client::default();
|
||||
client
|
||||
.get(media)
|
||||
.get(media.replace("&", "&"))
|
||||
.send()
|
||||
.await
|
||||
.map_err(Error::from)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue