Addressing PR comments

post_link_alt_text
Dessalines 3 months ago
parent 7b887394e3
commit 17315cb164

@ -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())

@ -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 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 (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),
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,

@ -74,8 +74,6 @@ pub(crate) struct Link {
href: Url,
media_type: Option<String>,
r#type: LinkType,
/// Used for alt_text
name: Option<String>,
}
#[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<String>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
@ -120,12 +116,8 @@ impl Attachment {
pub(crate) fn alt_text(self) -> Option<String> {
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,
})
}
}

@ -114,7 +114,7 @@ pub struct PostUpdateForm {
pub language_id: Option<LanguageId>,
pub featured_community: Option<bool>,
pub featured_local: Option<bool>,
pub url_content_type: Option<String>,
pub url_content_type: Option<Option<String>>,
pub alt_text: Option<Option<String>>,
}

Loading…
Cancel
Save