Allow bypassing proxy for some domains with ProxyAllImages

pull/4874/head
sunaurus 2024-06-28 22:27:34 +03:00
parent 9120207314
commit 31fc2767d8
No known key found for this signature in database
3 changed files with 25 additions and 2 deletions

View File

@ -73,6 +73,11 @@
#
# Requires pict-rs 0.5
"ProxyAllImages"
# Allows bypassing proxy for specific image hosts when using ProxyAllImages
proxy_bypass_domains: [
"string"
/* ... */
]
# Timeout for uploading images to pictrs (in seconds)
upload_timeout: 30
}

View File

@ -5,9 +5,10 @@ use actix_web::{
StatusCode,
},
web,
web::Query,
web::{Query, Redirect},
HttpRequest,
HttpResponse,
Responder,
};
use futures::stream::{Stream, StreamExt};
use lemmy_api_common::{context::LemmyContext, request::PictrsResponse};
@ -225,9 +226,22 @@ pub async fn image_proxy(
// for arbitrary purposes.
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 url = format!("{}image/original?proxy={}", pictrs_config.url, &params.url);
image(url, req, &client).await
}

View File

@ -91,6 +91,10 @@ pub struct PictrsConfig {
#[default(PictrsImageMode::StoreLinkPreviews)]
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)
#[default(30)]
pub upload_timeout: u64,