federate post url as image depending on mime type

cleanup-request-rs
Felix Ableitner 2023-11-06 12:28:05 +01:00
parent 706841950d
commit ecd8e3b11b
5 changed files with 20 additions and 11 deletions

View File

@ -234,7 +234,7 @@ async fn generate_pictrs_thumbnail(
let pictrs_config = context.settings().pictrs_config()?;
if pictrs_config.disable_external_link_previews {
return Ok(proxy_image_link(image_url.clone(), context)?);
return Ok(proxy_image_link(image_url.clone(), context).await?.into());
}
// fetch remote non-pictrs images for persistent thumbnail link

View File

@ -116,7 +116,7 @@ impl Object for ApubPost {
let attachment = self
.url
.clone()
.map(|url| Attachment::new(url, self.url_content_type.clone()))
.map(|url| Attachment::new(url.into(), self.url_content_type.clone()))
.into_iter()
.collect();

View File

@ -20,7 +20,6 @@ use activitypub_federation::{
use chrono::{DateTime, Utc};
use itertools::Itertools;
use lemmy_api_common::context::LemmyContext;
use lemmy_db_schema::newtypes::DbUrl;
use lemmy_utils::error::{LemmyError, LemmyErrorType};
use serde::{de::Error, Deserialize, Deserializer, Serialize};
use serde_with::skip_serializing_none;
@ -168,14 +167,23 @@ impl Page {
}
impl Attachment {
pub(crate) fn new(url: DbUrl, media_type: Option<String>) -> Attachment {
/// Creates new attachment for a given link and mime type.
pub(crate) fn new(url: Url, media_type: Option<String>) -> Attachment {
let is_image = media_type.clone().unwrap_or_default().starts_with("image");
if is_image {
Attachment::Image(Image {
kind: Default::default(),
url,
})
} else {
Attachment::Link(Link {
href: url.into(),
href: url,
media_type,
r#type: Default::default(),
})
}
}
}
// Used for community outbox, so that it can be compatible with Pleroma/Mastodon.
#[async_trait::async_trait]

View File

@ -91,7 +91,8 @@ pub struct PictrsConfig {
/// 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.
/// If this setting is enabled, the Opengraph image is directly returned as thumbnail. Note that
/// it still gets proxied through the local instance if `image_proxy` is enabled.
#[default(false)]
pub disable_external_link_previews: bool,
}

@ -1 +1 @@
Subproject commit e943f97fe481dc425acdebc8872bf1fdcabaf875
Subproject commit 83540721c6035c701f4ef1daf7d95f78a51fedf7