diff --git a/config/defaults.hjson b/config/defaults.hjson index 188ca324d..1ce63396f 100644 --- a/config/defaults.hjson +++ b/config/defaults.hjson @@ -49,6 +49,12 @@ # # Requires pict-rs 0.5 image_proxy: false + # Don't store preview images for external links in pict-rs. Enabling this setting reduces + # storage usage. It may also be necessary in certain countries which don't allow copying images + # from newspaper articles, but only allow hotlinking. + # + # If this setting is enabled, the Opengraph image is directly returned as thumbnail. + disable_external_link_previews: false } # Email sending configuration. All options except login/password are mandatory email: { diff --git a/crates/api_common/src/request.rs b/crates/api_common/src/request.rs index 954a6cd88..3e2311f8f 100644 --- a/crates/api_common/src/request.rs +++ b/crates/api_common/src/request.rs @@ -1,4 +1,4 @@ -use crate::{context::LemmyContext, post::LinkMetadata}; +use crate::{context::LemmyContext, post::LinkMetadata, utils::proxy_image_link}; use encoding::{all::encodings, DecoderTrap}; use lemmy_utils::{ error::{LemmyError, LemmyErrorType}, @@ -233,6 +233,10 @@ async fn generate_pictrs_thumbnail( ) -> Result { let pictrs_config = context.settings().pictrs_config()?; + if pictrs_config.disable_external_link_previews { + return Ok(proxy_image_link(image_url.clone(), context)?); + } + // fetch remote non-pictrs images for persistent thumbnail link // TODO: should limit size once supported by pictrs let fetch_url = format!( diff --git a/crates/utils/src/settings/structs.rs b/crates/utils/src/settings/structs.rs index d5dc8c8f6..39153f4a8 100644 --- a/crates/utils/src/settings/structs.rs +++ b/crates/utils/src/settings/structs.rs @@ -86,6 +86,14 @@ pub struct PictrsConfig { /// Requires pict-rs 0.5 #[default(false)] pub image_proxy: bool, + + /// Don't store preview images for external links in pict-rs. Enabling this setting reduces + /// storage usage. It may also be necessary in certain countries which don't allow copying images + /// from newspaper articles, but only allow hotlinking. + /// + /// If this setting is enabled, the Opengraph image is directly returned as thumbnail. + #[default(false)] + pub disable_external_link_previews: bool, } #[derive(Debug, Deserialize, Serialize, Clone, SmartDefault, Document)] diff --git a/crates/utils/translations b/crates/utils/translations index abd40d473..e943f97fe 160000 --- a/crates/utils/translations +++ b/crates/utils/translations @@ -1 +1 @@ -Subproject commit abd40d4737fa732321fd7b62e42bbfcd51081cb6 +Subproject commit e943f97fe481dc425acdebc8872bf1fdcabaf875