mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-23 09:51:01 +00:00
Add alt_text for posts. Fixes #1086
This commit is contained in:
parent
328a48c9f5
commit
c5a98c5a3f
12 changed files with 31 additions and 1 deletions
|
@ -24,6 +24,8 @@ pub struct CreatePost {
|
|||
pub url: Option<Url>,
|
||||
/// An optional body for the post in markdown.
|
||||
pub body: Option<String>,
|
||||
/// An optional alt_text, usable for image posts.
|
||||
pub alt_text: Option<String>,
|
||||
/// A honeypot to catch bots. Should be None.
|
||||
pub honeypot: Option<String>,
|
||||
pub nsfw: Option<bool>,
|
||||
|
@ -115,6 +117,8 @@ pub struct EditPost {
|
|||
pub url: Option<Url>,
|
||||
/// An optional body for the post in markdown.
|
||||
pub body: Option<String>,
|
||||
/// An optional alt_text, usable for image posts.
|
||||
pub alt_text: Option<String>,
|
||||
pub nsfw: Option<bool>,
|
||||
pub language_id: Option<LanguageId>,
|
||||
#[cfg_attr(feature = "full", ts(type = "string"))]
|
||||
|
|
|
@ -50,10 +50,13 @@ pub async fn create_post(
|
|||
) -> Result<Json<PostResponse>, LemmyError> {
|
||||
let local_site = LocalSite::read(&mut context.pool()).await?;
|
||||
|
||||
honeypot_check(&data.honeypot)?;
|
||||
|
||||
let slur_regex = local_site_to_slur_regex(&local_site);
|
||||
check_slurs(&data.name, &slur_regex)?;
|
||||
|
||||
let body = process_markdown_opt(&data.body, &slur_regex, &context).await?;
|
||||
honeypot_check(&data.honeypot)?;
|
||||
let alt_text = process_markdown_opt(&data.alt_text, &slur_regex, &context).await?;
|
||||
|
||||
let data_url = data.url.as_ref();
|
||||
let url = data_url.map(clean_url_params); // TODO no good way to handle a "clear"
|
||||
|
@ -61,6 +64,7 @@ pub async fn create_post(
|
|||
|
||||
is_valid_post_title(&data.name)?;
|
||||
is_valid_body_field(&body, true)?;
|
||||
is_valid_body_field(&alt_text, false)?;
|
||||
check_url_scheme(&url)?;
|
||||
check_url_scheme(&custom_thumbnail)?;
|
||||
|
||||
|
@ -124,6 +128,7 @@ pub async fn create_post(
|
|||
.name(data.name.trim().to_string())
|
||||
.url(url)
|
||||
.body(body)
|
||||
.alt_text(alt_text)
|
||||
.community_id(data.community_id)
|
||||
.creator_id(local_user_view.person.id)
|
||||
.nsfw(data.nsfw)
|
||||
|
|
|
@ -48,12 +48,14 @@ 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 = process_markdown_opt(&data.alt_text, &slur_regex, &context).await?;
|
||||
|
||||
if let Some(name) = &data.name {
|
||||
is_valid_post_title(name)?;
|
||||
}
|
||||
|
||||
is_valid_body_field(&body, true)?;
|
||||
is_valid_body_field(&alt_text, false)?;
|
||||
check_url_scheme(&url)?;
|
||||
check_url_scheme(&custom_thumbnail)?;
|
||||
|
||||
|
@ -116,6 +118,7 @@ pub async fn update_post(
|
|||
name: data.name.clone(),
|
||||
url,
|
||||
body: diesel_option_overwrite(body),
|
||||
alt_text: diesel_option_overwrite(alt_text),
|
||||
nsfw: data.nsfw,
|
||||
embed_title,
|
||||
embed_description,
|
||||
|
|
|
@ -127,6 +127,7 @@ impl Object for ApubPost {
|
|||
cc: vec![],
|
||||
name: Some(self.name.clone()),
|
||||
content: self.body.as_ref().map(|b| markdown_to_html(b)),
|
||||
alt_text: self.alt_text.as_ref().map(|b| markdown_to_html(b)),
|
||||
media_type: Some(MediaTypeMarkdownOrHtml::Html),
|
||||
source: self.body.clone().map(Source::new),
|
||||
attachment,
|
||||
|
@ -234,6 +235,7 @@ impl Object for ApubPost {
|
|||
|
||||
let body = read_from_string_or_source_opt(&page.content, &page.media_type, &page.source);
|
||||
let body = process_markdown_opt(&body, slur_regex, context).await?;
|
||||
let alt_text = process_markdown_opt(&page.alt_text, slur_regex, context).await?;
|
||||
let language_id =
|
||||
LanguageTag::to_language_id_single(page.language, &mut context.pool()).await?;
|
||||
|
||||
|
@ -241,6 +243,7 @@ impl Object for ApubPost {
|
|||
name,
|
||||
url: url.map(Into::into),
|
||||
body,
|
||||
alt_text,
|
||||
creator_id: creator.id,
|
||||
community_id: community.id,
|
||||
removed: None,
|
||||
|
|
|
@ -52,6 +52,7 @@ pub struct Page {
|
|||
#[serde(deserialize_with = "deserialize_one_or_many", default)]
|
||||
pub(crate) cc: Vec<Url>,
|
||||
pub(crate) content: Option<String>,
|
||||
pub(crate) alt_text: Option<String>,
|
||||
pub(crate) media_type: Option<MediaTypeMarkdownOrHtml>,
|
||||
#[serde(deserialize_with = "deserialize_skip_error", default)]
|
||||
pub(crate) source: Option<Source>,
|
||||
|
|
|
@ -417,6 +417,7 @@ mod tests {
|
|||
name: "A test post".into(),
|
||||
url: None,
|
||||
body: None,
|
||||
alt_text: None,
|
||||
creator_id: inserted_person.id,
|
||||
community_id: inserted_community.id,
|
||||
published: inserted_post.published,
|
||||
|
|
|
@ -705,6 +705,7 @@ diesel::table! {
|
|||
featured_community -> Bool,
|
||||
featured_local -> Bool,
|
||||
url_content_type -> Nullable<Text>,
|
||||
alt_text -> Nullable<Text>,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,8 @@ pub struct Post {
|
|||
/// Whether the post is featured to its site.
|
||||
pub featured_local: bool,
|
||||
pub url_content_type: Option<String>,
|
||||
/// An optional alt_text, usable for image posts.
|
||||
pub alt_text: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, TypedBuilder)]
|
||||
|
@ -87,6 +89,7 @@ pub struct PostInsertForm {
|
|||
pub featured_community: Option<bool>,
|
||||
pub featured_local: Option<bool>,
|
||||
pub url_content_type: Option<String>,
|
||||
pub alt_text: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default)]
|
||||
|
@ -112,6 +115,7 @@ pub struct PostUpdateForm {
|
|||
pub featured_community: Option<bool>,
|
||||
pub featured_local: Option<bool>,
|
||||
pub url_content_type: Option<String>,
|
||||
pub alt_text: Option<Option<String>>,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Eq, Debug)]
|
||||
|
|
|
@ -1015,6 +1015,7 @@ mod tests {
|
|||
creator_id: data.timmy_local_user_view.person.id,
|
||||
url: None,
|
||||
body: None,
|
||||
alt_text: None,
|
||||
published: data.inserted_post.published,
|
||||
updated: None,
|
||||
community_id: data.inserted_community.id,
|
||||
|
|
|
@ -1490,6 +1490,7 @@ mod tests {
|
|||
creator_id: inserted_person.id,
|
||||
url: None,
|
||||
body: None,
|
||||
alt_text: None,
|
||||
published: inserted_post.published,
|
||||
updated: None,
|
||||
community_id: inserted_community.id,
|
||||
|
|
3
migrations/2024-02-27-204628_add_post_alt_text/down.sql
Normal file
3
migrations/2024-02-27-204628_add_post_alt_text/down.sql
Normal file
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE post
|
||||
DROP COLUMN alt_text;
|
||||
|
3
migrations/2024-02-27-204628_add_post_alt_text/up.sql
Normal file
3
migrations/2024-02-27-204628_add_post_alt_text/up.sql
Normal file
|
@ -0,0 +1,3 @@
|
|||
ALTER TABLE post
|
||||
ADD COLUMN alt_text text;
|
||||
|
Loading…
Reference in a new issue