diff --git a/crates/api_common/src/post.rs b/crates/api_common/src/post.rs index 8f482527c..f7be33a8e 100644 --- a/crates/api_common/src/post.rs +++ b/crates/api_common/src/post.rs @@ -28,6 +28,8 @@ pub struct CreatePost { pub honeypot: Option, pub nsfw: Option, pub language_id: Option, + /// Instead of fetching a thumbnail, use a custom one. + pub custom_thumbnail: Option, } #[derive(Debug, Serialize, Deserialize, Clone)] @@ -114,6 +116,8 @@ pub struct EditPost { pub body: Option, pub nsfw: Option, pub language_id: Option, + /// Instead of fetching a thumbnail, use a custom one. + pub custom_thumbnail: Option, } #[derive(Debug, Serialize, Deserialize, Clone, Default)] diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index 910454d5b..ff684094b 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -87,6 +87,7 @@ pub async fn create_post( // Fetch post links and pictrs cached image let metadata = fetch_link_metadata_opt(url.as_ref(), true, &context).await; let url = proxy_image_link_opt_apub(url, &context).await?; + let thumbnail_url = data.custom_thumbnail.or(metadata.thumbnail); // Only need to check if language is allowed in case user set it explicitly. When using default // language, it already only returns allowed languages. @@ -121,7 +122,7 @@ pub async fn create_post( .embed_description(metadata.opengraph_data.description) .embed_video_url(metadata.opengraph_data.embed_video_url) .language_id(language_id) - .thumbnail_url(metadata.thumbnail) + .thumbnail_url(thumbnail_url) .build(); let inserted_post = Post::create(&mut context.pool(), &post_form) diff --git a/crates/api_crud/src/post/update.rs b/crates/api_crud/src/post/update.rs index c36718615..3198aa2d1 100644 --- a/crates/api_crud/src/post/update.rs +++ b/crates/api_crud/src/post/update.rs @@ -70,7 +70,7 @@ pub async fn update_post( Err(LemmyErrorType::NoPostEditAllowed)? } - // Fetch post links and Pictrs cached image if url was updated + // Fetch post links and thumbnail if url was updated let (embed_title, embed_description, embed_video_url, thumbnail_url) = match &url { Some(url) => { let metadata = fetch_link_metadata(url, true, &context).await?; @@ -78,7 +78,7 @@ pub async fn update_post( Some(metadata.opengraph_data.title), Some(metadata.opengraph_data.description), Some(metadata.opengraph_data.embed_video_url), - Some(metadata.thumbnail), + Some(data.custom_thumbnail.or(metadata.thumbnail)), ) } _ => Default::default(),