From 17315cb164dbbf23abbc307642f583eed543be09 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 1 Mar 2024 11:51:03 -0500 Subject: [PATCH] Addressing PR comments --- crates/api_crud/src/post/create.rs | 1 + crates/api_crud/src/post/update.rs | 33 +++++++++++++----------- crates/apub/src/protocol/objects/page.rs | 11 +------- crates/db_schema/src/source/post.rs | 2 +- 4 files changed, 21 insertions(+), 26 deletions(-) diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index e5a5e8c3a..1076921b9 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -132,6 +132,7 @@ pub async fn create_post( let post_form = PostInsertForm::builder() .name(data.name.trim().to_string()) + .url_content_type(metadata.content_type) .url(url) .body(body) .alt_text(alt_text.clone()) diff --git a/crates/api_crud/src/post/update.rs b/crates/api_crud/src/post/update.rs index 9f1fa72e3..4d3931203 100644 --- a/crates/api_crud/src/post/update.rs +++ b/crates/api_crud/src/post/update.rs @@ -81,22 +81,24 @@ 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) => { - // 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 (embed_title, embed_description, embed_video_url, metadata_thumbnail, metadata_content_type) = + match &url { + Some(url) => { + // 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), - Some(metadata.opengraph_data.embed_video_url), - Some(metadata.thumbnail), - ) - } - _ => Default::default(), - }; + let metadata = fetch_link_metadata(url, generate_thumbnail, &context).await?; + ( + Some(metadata.opengraph_data.title), + Some(metadata.opengraph_data.description), + Some(metadata.opengraph_data.embed_video_url), + Some(metadata.thumbnail), + Some(metadata.content_type), + ) + } + _ => Default::default(), + }; let url = match url { Some(url) => Some(proxy_image_link_opt_apub(Some(url), &context).await?), @@ -123,6 +125,7 @@ pub async fn update_post( let post_form = PostUpdateForm { name: data.name.clone(), url, + url_content_type: metadata_content_type, body: diesel_option_overwrite(body), alt_text: diesel_option_overwrite(alt_text.clone()), nsfw: data.nsfw, diff --git a/crates/apub/src/protocol/objects/page.rs b/crates/apub/src/protocol/objects/page.rs index 345967e0d..8bd39ce00 100644 --- a/crates/apub/src/protocol/objects/page.rs +++ b/crates/apub/src/protocol/objects/page.rs @@ -74,8 +74,6 @@ pub(crate) struct Link { href: Url, media_type: Option, r#type: LinkType, - /// Used for alt_text - name: Option, } #[derive(Clone, Debug, Deserialize, Serialize)] @@ -94,8 +92,6 @@ pub(crate) struct Document { #[serde(rename = "type")] kind: DocumentType, url: Url, - /// Used for alt_text - name: Option, } #[derive(Clone, Debug, Deserialize, Serialize)] @@ -120,12 +116,8 @@ impl Attachment { pub(crate) fn alt_text(self) -> Option { match self { - // url as sent by Lemmy (new) - Attachment::Link(l) => l.name, - // image sent by lotide Attachment::Image(i) => i.name, - // sent by mobilizon - Attachment::Document(d) => d.name, + _ => None, } } } @@ -198,7 +190,6 @@ impl Attachment { href: url, media_type, r#type: Default::default(), - name, }) } } diff --git a/crates/db_schema/src/source/post.rs b/crates/db_schema/src/source/post.rs index cbab48cb1..541d9c307 100644 --- a/crates/db_schema/src/source/post.rs +++ b/crates/db_schema/src/source/post.rs @@ -114,7 +114,7 @@ pub struct PostUpdateForm { pub language_id: Option, pub featured_community: Option, pub featured_local: Option, - pub url_content_type: Option, + pub url_content_type: Option>, pub alt_text: Option>, }