mirror of
https://github.com/LemmyNet/lemmy.git
synced 2025-01-15 14:35:54 +00:00
Change default image_mode to proxy, remove deprecated option (#5176)
* Change default image_mode to proxy, remove deprecated option * fix api test
This commit is contained in:
parent
c879eb1244
commit
11e0513592
7 changed files with 12 additions and 36 deletions
|
@ -20,11 +20,6 @@
|
||||||
url: "http://localhost:8080/"
|
url: "http://localhost:8080/"
|
||||||
# Set a custom pictrs API key. ( Required for deleting images )
|
# Set a custom pictrs API key. ( Required for deleting images )
|
||||||
api_key: "string"
|
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
|
# Specifies how to handle remote images, so that users don't have to connect directly to remote
|
||||||
# servers.
|
# servers.
|
||||||
image_mode:
|
image_mode:
|
||||||
|
@ -38,7 +33,7 @@
|
||||||
# ensures that they can be reliably retrieved and can be resized using pict-rs APIs. However
|
# ensures that they can be reliably retrieved and can be resized using pict-rs APIs. However
|
||||||
# it also increases storage usage.
|
# it also increases storage usage.
|
||||||
#
|
#
|
||||||
# This is the default behaviour, and also matches Lemmy 0.18.
|
# This behaviour matches Lemmy 0.18.
|
||||||
"StoreLinkPreviews"
|
"StoreLinkPreviews"
|
||||||
|
|
||||||
# or
|
# or
|
||||||
|
|
|
@ -371,7 +371,7 @@ pub async fn delete_image_from_pictrs(
|
||||||
async fn generate_pictrs_thumbnail(image_url: &Url, context: &LemmyContext) -> LemmyResult<Url> {
|
async fn generate_pictrs_thumbnail(image_url: &Url, context: &LemmyContext) -> LemmyResult<Url> {
|
||||||
let pictrs_config = context.settings().pictrs_config()?;
|
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::None => return Ok(image_url.clone()),
|
||||||
PictrsImageMode::ProxyAllImages => {
|
PictrsImageMode::ProxyAllImages => {
|
||||||
return Ok(proxy_image_link(image_url.clone(), context).await?.into())
|
return Ok(proxy_image_link(image_url.clone(), context).await?.into())
|
||||||
|
|
|
@ -1060,7 +1060,7 @@ pub async fn process_markdown(
|
||||||
|
|
||||||
markdown_check_for_blocked_urls(&text, url_blocklist)?;
|
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);
|
let (text, links) = markdown_rewrite_image_links(text);
|
||||||
RemoteImage::create(&mut context.pool(), links.clone()).await?;
|
RemoteImage::create(&mut context.pool(), links.clone()).await?;
|
||||||
|
|
||||||
|
@ -1130,7 +1130,7 @@ async fn proxy_image_link_internal(
|
||||||
pub async fn proxy_image_link(link: Url, context: &LemmyContext) -> LemmyResult<DbUrl> {
|
pub async fn proxy_image_link(link: Url, context: &LemmyContext) -> LemmyResult<DbUrl> {
|
||||||
proxy_image_link_internal(
|
proxy_image_link_internal(
|
||||||
link,
|
link,
|
||||||
context.settings().pictrs_config()?.image_mode(),
|
context.settings().pictrs_config()?.image_mode,
|
||||||
context,
|
context,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -3,12 +3,12 @@ use anyhow::{anyhow, Context};
|
||||||
use deser_hjson::from_str;
|
use deser_hjson::from_str;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use std::{env, fs, io::Error, sync::LazyLock};
|
use std::{env, fs, io::Error, sync::LazyLock};
|
||||||
use structs::{PictrsConfig, PictrsImageMode, Settings};
|
use structs::{PictrsConfig, Settings};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
pub mod structs;
|
pub mod structs;
|
||||||
|
|
||||||
const DEFAULT_CONFIG_FILE: &str = "config/config.hjson";
|
static DEFAULT_CONFIG_FILE: &str = "config/config.hjson";
|
||||||
|
|
||||||
#[allow(clippy::expect_used)]
|
#[allow(clippy::expect_used)]
|
||||||
pub static SETTINGS: LazyLock<Settings> = LazyLock::new(|| {
|
pub static SETTINGS: LazyLock<Settings> = LazyLock::new(|| {
|
||||||
|
@ -104,21 +104,6 @@ impl Settings {
|
||||||
.ok_or_else(|| anyhow!("images_disabled").into())
|
.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)]
|
#[allow(clippy::expect_used)]
|
||||||
/// Necessary to avoid URL expect failures
|
/// Necessary to avoid URL expect failures
|
||||||
fn pictrs_placeholder_url() -> Url {
|
fn pictrs_placeholder_url() -> Url {
|
||||||
|
|
|
@ -77,16 +77,10 @@ pub struct PictrsConfig {
|
||||||
#[default(None)]
|
#[default(None)]
|
||||||
pub api_key: Option<String>,
|
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
|
/// Specifies how to handle remote images, so that users don't have to connect directly to remote
|
||||||
/// servers.
|
/// servers.
|
||||||
#[default(PictrsImageMode::StoreLinkPreviews)]
|
#[default(PictrsImageMode::ProxyAllImages)]
|
||||||
pub(super) image_mode: PictrsImageMode,
|
pub image_mode: PictrsImageMode,
|
||||||
|
|
||||||
/// Allows bypassing proxy for specific image hosts when using ProxyAllImages.
|
/// Allows bypassing proxy for specific image hosts when using ProxyAllImages.
|
||||||
///
|
///
|
||||||
|
@ -116,8 +110,7 @@ pub enum PictrsImageMode {
|
||||||
/// ensures that they can be reliably retrieved and can be resized using pict-rs APIs. However
|
/// ensures that they can be reliably retrieved and can be resized using pict-rs APIs. However
|
||||||
/// it also increases storage usage.
|
/// it also increases storage usage.
|
||||||
///
|
///
|
||||||
/// This is the default behaviour, and also matches Lemmy 0.18.
|
/// This behaviour matches Lemmy 0.18.
|
||||||
#[default]
|
|
||||||
StoreLinkPreviews,
|
StoreLinkPreviews,
|
||||||
/// If enabled, all images from remote domains are rewritten to pass through
|
/// If enabled, all images from remote domains are rewritten to pass through
|
||||||
/// `/api/v4/image_proxy`, including embedded images in markdown. Images are stored temporarily
|
/// `/api/v4/image_proxy`, including embedded images in markdown. Images are stored temporarily
|
||||||
|
@ -126,6 +119,7 @@ pub enum PictrsImageMode {
|
||||||
/// local server.
|
/// local server.
|
||||||
///
|
///
|
||||||
/// Requires pict-rs 0.5
|
/// Requires pict-rs 0.5
|
||||||
|
#[default]
|
||||||
ProxyAllImages,
|
ProxyAllImages,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,5 +12,6 @@
|
||||||
}
|
}
|
||||||
pictrs: {
|
pictrs: {
|
||||||
api_key: "my-pictrs-key"
|
api_key: "my-pictrs-key"
|
||||||
|
image_mode: StoreLinkPreviews
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,5 +12,6 @@
|
||||||
}
|
}
|
||||||
pictrs: {
|
pictrs: {
|
||||||
api_key: "my-pictrs-key"
|
api_key: "my-pictrs-key"
|
||||||
|
image_mode: StoreLinkPreviews
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue