diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index 1076921b9..8def026c2 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -62,15 +62,13 @@ pub async fn create_post( check_slurs(&data.name, &slur_regex)?; let body = process_markdown_opt(&data.body, &slur_regex, &context).await?; - let alt_text = &data.alt_text; - 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)?; - is_valid_alt_text_field(alt_text)?; + is_valid_alt_text_field(&data.alt_text)?; check_url_scheme(&url)?; check_url_scheme(&custom_thumbnail)?; @@ -135,7 +133,7 @@ pub async fn create_post( .url_content_type(metadata.content_type) .url(url) .body(body) - .alt_text(alt_text.clone()) + .alt_text(&data.alt_text.clone()) .community_id(data.community_id) .creator_id(local_user_view.person.id) .nsfw(data.nsfw) diff --git a/crates/api_crud/src/post/update.rs b/crates/api_crud/src/post/update.rs index 4d3931203..4e5abbdee 100644 --- a/crates/api_crud/src/post/update.rs +++ b/crates/api_crud/src/post/update.rs @@ -54,14 +54,13 @@ pub async fn update_post( let slur_regex = local_site_to_slur_regex(&local_site); check_slurs_opt(&data.name, &slur_regex)?; let body = process_markdown_opt(&data.body, &slur_regex, &context).await?; - let alt_text = &data.alt_text; if let Some(name) = &data.name { is_valid_post_title(name)?; } is_valid_body_field(&body, true)?; - is_valid_alt_text_field(alt_text)?; + is_valid_alt_text_field(&data.alt_text)?; check_url_scheme(&url)?; check_url_scheme(&custom_thumbnail)?; @@ -86,7 +85,7 @@ pub async fn update_post( 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 generate_thumbnail = custom_thumbnail.is_none() || orig_post.thumbnail_url.is_none(); let metadata = fetch_link_metadata(url, generate_thumbnail, &context).await?; ( @@ -127,7 +126,7 @@ pub async fn update_post( url, url_content_type: metadata_content_type, body: diesel_option_overwrite(body), - alt_text: diesel_option_overwrite(alt_text.clone()), + alt_text: diesel_option_overwrite(&data.alt_text.clone()), nsfw: data.nsfw, embed_title, embed_description, diff --git a/crates/apub/src/protocol/objects/page.rs b/crates/apub/src/protocol/objects/page.rs index 8bd39ce00..d6111843e 100644 --- a/crates/apub/src/protocol/objects/page.rs +++ b/crates/apub/src/protocol/objects/page.rs @@ -92,6 +92,8 @@ pub(crate) struct Document { #[serde(rename = "type")] kind: DocumentType, url: Url, + /// Used for alt_text + name: Option, } #[derive(Clone, Debug, Deserialize, Serialize)] @@ -117,6 +119,7 @@ impl Attachment { pub(crate) fn alt_text(self) -> Option { match self { Attachment::Image(i) => i.name, + Attachment::Document(d) => d.name, _ => None, } } @@ -177,13 +180,13 @@ impl Page { impl Attachment { /// Creates new attachment for a given link and mime type. - pub(crate) fn new(url: Url, media_type: Option, name: Option) -> Attachment { + pub(crate) fn new(url: Url, media_type: Option, alt_text: Option) -> Attachment { let is_image = media_type.clone().unwrap_or_default().starts_with("image"); if is_image { Attachment::Image(Image { kind: Default::default(), url, - name, + name: alt_text, }) } else { Attachment::Link(Link {