From e49d346535f0769b85ad0fa4b0baabfbdba0deff Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 14 Feb 2024 11:20:44 -0500 Subject: [PATCH] Only generate metadata thumbnail is theres no custom thumbnail. --- crates/api_crud/src/post/create.rs | 6 +++++- crates/api_crud/src/post/update.rs | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index 8a8d8a3c2..a5a9c013f 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -86,8 +86,12 @@ pub async fn create_post( } } + // Only generate the thumbnail if there's no custom thumbnail provided, + // otherwise it will save it in pictrs + let generate_thumbnail = custom_thumbnail.is_none(); + // Fetch post links and pictrs cached image - let metadata = fetch_link_metadata_opt(url.as_ref(), true, &context).await; + let metadata = fetch_link_metadata_opt(url.as_ref(), generate_thumbnail, &context).await; let url = proxy_image_link_opt_apub(url, &context).await?; let thumbnail_url = proxy_image_link_opt_apub(custom_thumbnail, &context) .await? diff --git a/crates/api_crud/src/post/update.rs b/crates/api_crud/src/post/update.rs index e7140b7cf..e858d9b30 100644 --- a/crates/api_crud/src/post/update.rs +++ b/crates/api_crud/src/post/update.rs @@ -75,7 +75,11 @@ pub async fn update_post( // Fetch post links and thumbnail if url was updated let (embed_title, embed_description, embed_video_url, metadata_thumbnail) = match &url { Some(url) => { - let metadata = fetch_link_metadata(url, true, &context).await?; + // Only generate the thumbnail if there's no custom thumbnail provided, + // otherwise it will save it in pictrs + let generate_thumbnail = custom_thumbnail.is_none(); + + let metadata = fetch_link_metadata(url, generate_thumbnail, &context).await?; ( Some(metadata.opengraph_data.title), Some(metadata.opengraph_data.description),