From 4fbe71ef31d5ffd8494192b73de7e5239d3b1c41 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Mon, 12 Feb 2024 11:53:37 -0500 Subject: [PATCH] Proxying custom_thumbnail. Fixed logic for update. --- crates/api_crud/src/post/create.rs | 5 ++++- crates/api_crud/src/post/update.rs | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index 881eda4d0..8a8d8a3c2 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -89,7 +89,10 @@ 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 = custom_thumbnail.map(Into::into).or(metadata.thumbnail); + let thumbnail_url = proxy_image_link_opt_apub(custom_thumbnail, &context) + .await? + .map(Into::into) + .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. diff --git a/crates/api_crud/src/post/update.rs b/crates/api_crud/src/post/update.rs index e7d7f7c6f..e7140b7cf 100644 --- a/crates/api_crud/src/post/update.rs +++ b/crates/api_crud/src/post/update.rs @@ -73,23 +73,33 @@ pub async fn update_post( } // Fetch post links and thumbnail if url was updated - let (embed_title, embed_description, embed_video_url, thumbnail_url) = match &url { + let (embed_title, embed_description, embed_video_url, metadata_thumbnail) = match &url { Some(url) => { let metadata = fetch_link_metadata(url, true, &context).await?; ( Some(metadata.opengraph_data.title), Some(metadata.opengraph_data.description), Some(metadata.opengraph_data.embed_video_url), - Some(custom_thumbnail.map(Into::into).or(metadata.thumbnail)), + Some(metadata.thumbnail), ) } _ => Default::default(), }; + let url = match url { Some(url) => Some(proxy_image_link_opt_apub(Some(url), &context).await?), _ => Default::default(), }; + let custom_thumbnail = match custom_thumbnail { + Some(custom_thumbnail) => { + Some(proxy_image_link_opt_apub(Some(custom_thumbnail), &context).await?) + } + _ => Default::default(), + }; + + let thumbnail_url = custom_thumbnail.or(metadata_thumbnail); + let language_id = data.language_id; CommunityLanguage::is_allowed_community_language( &mut context.pool(),