Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change default image_mode to proxy, remove deprecated option #5176

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions config/defaults.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -60,7 +55,7 @@
# 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.
# This behaviour matches Lemmy 0.18.
"StoreLinkPreviews"

# or
Expand Down
2 changes: 1 addition & 1 deletion crates/api_common/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ pub async fn delete_image_from_pictrs(
async fn generate_pictrs_thumbnail(image_url: &Url, context: &LemmyContext) -> LemmyResult<Url> {
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())
Expand Down
4 changes: 2 additions & 2 deletions crates/api_common/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,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?;

Expand Down Expand Up @@ -1124,7 +1124,7 @@ async fn proxy_image_link_internal(
pub async fn proxy_image_link(link: Url, context: &LemmyContext) -> LemmyResult<DbUrl> {
proxy_image_link_internal(
link,
context.settings().pictrs_config()?.image_mode(),
context.settings().pictrs_config()?.image_mode,
context,
)
.await
Expand Down
17 changes: 1 addition & 16 deletions crates/utils/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,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";

Expand Down Expand Up @@ -117,21 +117,6 @@ 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()
}
}
}

#[allow(clippy::expect_used)]
/// Necessary to avoid URL expect failures
fn pictrs_placeholder_url() -> Url {
Expand Down
14 changes: 4 additions & 10 deletions crates/utils/src/settings/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,10 @@ pub struct PictrsConfig {
#[default(None)]
pub api_key: Option<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
pub(super) cache_external_link_previews: Option<bool>,

/// 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)]
Expand All @@ -107,8 +101,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
Expand All @@ -117,6 +110,7 @@ pub enum PictrsImageMode {
/// local server.
///
/// Requires pict-rs 0.5
#[default]
ProxyAllImages,
}

Expand Down
1 change: 1 addition & 0 deletions docker/federation/lemmy_alpha.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
}
pictrs: {
api_key: "my-pictrs-key"
image_mode: StoreLinkPreviews
}
}
1 change: 1 addition & 0 deletions docker/federation/lemmy_beta.hjson
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
}
pictrs: {
api_key: "my-pictrs-key"
image_mode: StoreLinkPreviews
}
}