From 7f294a86c2fd618d0e798195c566deb51541ac74 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Fri, 8 Nov 2024 11:07:42 +0100 Subject: [PATCH] Change default image_mode to proxy, remove deprecated option --- config/defaults.hjson | 5 ----- crates/api_common/src/request.rs | 2 +- crates/api_common/src/utils.rs | 4 ++-- crates/utils/src/settings/mod.rs | 16 +--------------- crates/utils/src/settings/structs.rs | 14 ++++---------- 5 files changed, 8 insertions(+), 33 deletions(-) diff --git a/config/defaults.hjson b/config/defaults.hjson index f0b9d56df5..227307b6ca 100644 --- a/config/defaults.hjson +++ b/config/defaults.hjson @@ -42,11 +42,6 @@ url: "http://localhost:8080/" # Set a custom pictrs API key. ( Required for deleting images ) api_key: "string" - # Backwards compatibility with 0.18.1. False is equivalent to `image_mode: None`, true is - # equivalent to `image_mode: StoreLinkPreviews`. - # - # To be removed in 0.20 - cache_external_link_previews: true # Specifies how to handle remote images, so that users don't have to connect directly to remote # servers. image_mode: diff --git a/crates/api_common/src/request.rs b/crates/api_common/src/request.rs index b0da6cf4d8..ad3a96c8ec 100644 --- a/crates/api_common/src/request.rs +++ b/crates/api_common/src/request.rs @@ -343,7 +343,7 @@ pub async fn delete_image_from_pictrs( async fn generate_pictrs_thumbnail(image_url: &Url, context: &LemmyContext) -> LemmyResult { let pictrs_config = context.settings().pictrs_config()?; - match pictrs_config.image_mode() { + match pictrs_config.image_mode { PictrsImageMode::None => return Ok(image_url.clone()), PictrsImageMode::ProxyAllImages => { return Ok(proxy_image_link(image_url.clone(), context).await?.into()) diff --git a/crates/api_common/src/utils.rs b/crates/api_common/src/utils.rs index ddddd35e98..16a71cc9cf 100644 --- a/crates/api_common/src/utils.rs +++ b/crates/api_common/src/utils.rs @@ -1045,7 +1045,7 @@ pub async fn process_markdown( markdown_check_for_blocked_urls(&text, url_blocklist)?; - if context.settings().pictrs_config()?.image_mode() == PictrsImageMode::ProxyAllImages { + if context.settings().pictrs_config()?.image_mode == PictrsImageMode::ProxyAllImages { let (text, links) = markdown_rewrite_image_links(text); RemoteImage::create(&mut context.pool(), links.clone()).await?; @@ -1115,7 +1115,7 @@ async fn proxy_image_link_internal( pub async fn proxy_image_link(link: Url, context: &LemmyContext) -> LemmyResult { proxy_image_link_internal( link, - context.settings().pictrs_config()?.image_mode(), + context.settings().pictrs_config()?.image_mode, context, ) .await diff --git a/crates/utils/src/settings/mod.rs b/crates/utils/src/settings/mod.rs index aba1a4fb1e..3a5539a084 100644 --- a/crates/utils/src/settings/mod.rs +++ b/crates/utils/src/settings/mod.rs @@ -7,7 +7,7 @@ use urlencoding::encode; pub mod structs; -use structs::{DatabaseConnection, PictrsConfig, PictrsImageMode, Settings}; +use structs::{DatabaseConnection, PictrsConfig, Settings}; static DEFAULT_CONFIG_FILE: &str = "config/config.hjson"; @@ -114,17 +114,3 @@ impl Settings { .ok_or_else(|| anyhow!("images_disabled").into()) } } - -impl PictrsConfig { - pub fn image_mode(&self) -> PictrsImageMode { - if let Some(cache_external_link_previews) = self.cache_external_link_previews { - if cache_external_link_previews { - PictrsImageMode::StoreLinkPreviews - } else { - PictrsImageMode::None - } - } else { - self.image_mode.clone() - } - } -} diff --git a/crates/utils/src/settings/structs.rs b/crates/utils/src/settings/structs.rs index 8c28d908a2..a4a9e3ead2 100644 --- a/crates/utils/src/settings/structs.rs +++ b/crates/utils/src/settings/structs.rs @@ -76,16 +76,10 @@ pub struct PictrsConfig { #[default(None)] pub api_key: Option, - /// Backwards compatibility with 0.18.1. False is equivalent to `image_mode: None`, true is - /// equivalent to `image_mode: StoreLinkPreviews`. - /// - /// To be removed in 0.20 - pub(super) cache_external_link_previews: Option, - /// Specifies how to handle remote images, so that users don't have to connect directly to remote /// servers. - #[default(PictrsImageMode::StoreLinkPreviews)] - pub(super) image_mode: PictrsImageMode, + #[default(PictrsImageMode::ProxyAllImages)] + pub image_mode: PictrsImageMode, /// Timeout for uploading images to pictrs (in seconds) #[default(30)] @@ -106,8 +100,7 @@ pub enum PictrsImageMode { /// ensures that they can be reliably retrieved and can be resized using pict-rs APIs. However /// it also increases storage usage. /// - /// This is the default behaviour, and also matches Lemmy 0.18. - #[default] + /// This behaviour matches Lemmy 0.18. StoreLinkPreviews, /// If enabled, all images from remote domains are rewritten to pass through /// `/api/v3/image_proxy`, including embedded images in markdown. Images are stored temporarily @@ -116,6 +109,7 @@ pub enum PictrsImageMode { /// local server. /// /// Requires pict-rs 0.5 + #[default] ProxyAllImages, }