mirror of https://github.com/LemmyNet/lemmy.git
Merge 31fc2767d8
into 78702b59fd
commit
470a573f70
|
@ -73,6 +73,11 @@
|
||||||
#
|
#
|
||||||
# Requires pict-rs 0.5
|
# Requires pict-rs 0.5
|
||||||
"ProxyAllImages"
|
"ProxyAllImages"
|
||||||
|
# Allows bypassing proxy for specific image hosts when using ProxyAllImages
|
||||||
|
proxy_bypass_domains: [
|
||||||
|
"string"
|
||||||
|
/* ... */
|
||||||
|
]
|
||||||
# Timeout for uploading images to pictrs (in seconds)
|
# Timeout for uploading images to pictrs (in seconds)
|
||||||
upload_timeout: 30
|
upload_timeout: 30
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,10 @@ use actix_web::{
|
||||||
StatusCode,
|
StatusCode,
|
||||||
},
|
},
|
||||||
web,
|
web,
|
||||||
web::Query,
|
web::{Query, Redirect},
|
||||||
HttpRequest,
|
HttpRequest,
|
||||||
HttpResponse,
|
HttpResponse,
|
||||||
|
Responder,
|
||||||
};
|
};
|
||||||
use futures::stream::{Stream, StreamExt};
|
use futures::stream::{Stream, StreamExt};
|
||||||
use lemmy_api_common::{context::LemmyContext, request::PictrsResponse};
|
use lemmy_api_common::{context::LemmyContext, request::PictrsResponse};
|
||||||
|
@ -225,9 +226,22 @@ pub async fn image_proxy(
|
||||||
// for arbitrary purposes.
|
// for arbitrary purposes.
|
||||||
RemoteImage::validate(&mut context.pool(), url.clone().into()).await?;
|
RemoteImage::validate(&mut context.pool(), url.clone().into()).await?;
|
||||||
|
|
||||||
|
if context
|
||||||
|
.settings()
|
||||||
|
.pictrs_config()?
|
||||||
|
.proxy_bypass_domains
|
||||||
|
.iter()
|
||||||
|
.any(|s| url.domain().expect("Invalid URL").starts_with(s))
|
||||||
|
{
|
||||||
|
return Ok(
|
||||||
|
Redirect::to(url.to_string())
|
||||||
|
.respond_to(&req)
|
||||||
|
.map_into_boxed_body(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let pictrs_config = context.settings().pictrs_config()?;
|
let pictrs_config = context.settings().pictrs_config()?;
|
||||||
let url = format!("{}image/original?proxy={}", pictrs_config.url, ¶ms.url);
|
let url = format!("{}image/original?proxy={}", pictrs_config.url, ¶ms.url);
|
||||||
|
|
||||||
image(url, req, &client).await
|
image(url, req, &client).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,10 @@ pub struct PictrsConfig {
|
||||||
#[default(PictrsImageMode::StoreLinkPreviews)]
|
#[default(PictrsImageMode::StoreLinkPreviews)]
|
||||||
pub(super) image_mode: PictrsImageMode,
|
pub(super) image_mode: PictrsImageMode,
|
||||||
|
|
||||||
|
/// Allows bypassing proxy for specific image hosts when using ProxyAllImages
|
||||||
|
#[default([].to_vec())]
|
||||||
|
pub proxy_bypass_domains: Vec<String>,
|
||||||
|
|
||||||
/// Timeout for uploading images to pictrs (in seconds)
|
/// Timeout for uploading images to pictrs (in seconds)
|
||||||
#[default(30)]
|
#[default(30)]
|
||||||
pub upload_timeout: u64,
|
pub upload_timeout: u64,
|
||||||
|
|
Loading…
Reference in New Issue