pull/4874/merge
Sander Saarend 2024-07-02 11:23:35 -04:00 committed by GitHub
commit 470a573f70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 2 deletions

View File

@ -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
} }

View File

@ -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, &params.url); let url = format!("{}image/original?proxy={}", pictrs_config.url, &params.url);
image(url, req, &client).await image(url, req, &client).await
} }

View File

@ -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,