From 495dd3f4f63c50367ecf28fe7494fa50f70fa5f3 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 4 Feb 2024 23:26:18 -0500 Subject: [PATCH] Fixing conversion, adding checks. --- crates/api_crud/src/post/create.rs | 6 ++++-- crates/api_crud/src/post/update.rs | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index ff684094b..881eda4d0 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -57,10 +57,12 @@ pub async fn create_post( let data_url = data.url.as_ref(); let url = data_url.map(clean_url_params); // TODO no good way to handle a "clear" + let custom_thumbnail = data.custom_thumbnail.as_ref().map(clean_url_params); is_valid_post_title(&data.name)?; is_valid_body_field(&body, true)?; - check_url_scheme(&data.url)?; + check_url_scheme(&url)?; + check_url_scheme(&custom_thumbnail)?; check_community_user_action( &local_user_view.person, @@ -87,7 +89,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); + let thumbnail_url = custom_thumbnail.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 3198aa2d1..e7d7f7c6f 100644 --- a/crates/api_crud/src/post/update.rs +++ b/crates/api_crud/src/post/update.rs @@ -43,6 +43,7 @@ pub async fn update_post( // TODO No good way to handle a clear. // Issue link: https://github.com/LemmyNet/lemmy/issues/2287 let url = data.url.as_ref().map(clean_url_params); + let custom_thumbnail = data.custom_thumbnail.as_ref().map(clean_url_params); let slur_regex = local_site_to_slur_regex(&local_site); check_slurs_opt(&data.name, &slur_regex)?; @@ -53,7 +54,8 @@ pub async fn update_post( } is_valid_body_field(&body, true)?; - check_url_scheme(&data.url)?; + check_url_scheme(&url)?; + check_url_scheme(&custom_thumbnail)?; let post_id = data.post_id; let orig_post = Post::read(&mut context.pool(), post_id).await?; @@ -78,7 +80,7 @@ pub async fn update_post( Some(metadata.opengraph_data.title), Some(metadata.opengraph_data.description), Some(metadata.opengraph_data.embed_video_url), - Some(data.custom_thumbnail.or(metadata.thumbnail)), + Some(custom_thumbnail.map(Into::into).or(metadata.thumbnail)), ) } _ => Default::default(),