add setting disable_external_link_previews

cleanup-request-rs
Felix Ableitner 2023-11-03 11:40:20 +01:00
parent 7fbfa48590
commit 706841950d
4 changed files with 20 additions and 2 deletions

View File

@ -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: {

View File

@ -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<Url, LemmyError> {
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!(

View File

@ -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)]

@ -1 +1 @@
Subproject commit abd40d4737fa732321fd7b62e42bbfcd51081cb6
Subproject commit e943f97fe481dc425acdebc8872bf1fdcabaf875