Use process_markdown instead of process_markdown_opt

This commit is contained in:
Freakazoid182 2024-04-06 12:33:49 +02:00
parent 7759602c9d
commit 6ffcc1f98a
3 changed files with 19 additions and 36 deletions

View file

@ -3,7 +3,7 @@ use actix_web::web::Json;
use lemmy_api_common::{
context::LemmyContext,
tagline::{CreateTagline, TaglineResponse},
utils::{get_url_blocklist, is_admin, local_site_to_slur_regex, process_markdown_opt},
utils::{get_url_blocklist, is_admin, local_site_to_slur_regex, process_markdown},
};
use lemmy_db_schema::{
source::{
@ -28,18 +28,12 @@ pub async fn create_tagline(
let slur_regex = local_site_to_slur_regex(&local_site);
let url_blocklist = get_url_blocklist(&context).await?;
let processed_content = process_markdown_opt(
&Some(data.content.to_owned()),
&slur_regex,
&url_blocklist,
&context,
)
.await?;
let content = is_valid_tagline_content(processed_content)?;
let content = process_markdown(&data.content, &slur_regex, &url_blocklist, &context).await?;
is_valid_tagline_content(&content)?;
let tagline_form = TaglineInsertForm {
local_site_id: local_site.id,
content,
content: content.clone(),
};
let tagline = Tagline::create(&mut context.pool(), &tagline_form).await?;

View file

@ -3,7 +3,7 @@ use actix_web::web::Json;
use lemmy_api_common::{
context::LemmyContext,
tagline::{TaglineResponse, UpdateTagline},
utils::{get_url_blocklist, is_admin, local_site_to_slur_regex, process_markdown_opt},
utils::{get_url_blocklist, is_admin, local_site_to_slur_regex, process_markdown},
};
use lemmy_db_schema::{
source::{
@ -29,14 +29,8 @@ pub async fn update_tagline(
let slur_regex = local_site_to_slur_regex(&local_site);
let url_blocklist = get_url_blocklist(&context).await?;
let processed_content = process_markdown_opt(
&Some(data.content.to_owned()),
&slur_regex,
&url_blocklist,
&context,
)
.await?;
let content = is_valid_tagline_content(processed_content)?;
let content = process_markdown(&data.content, &slur_regex, &url_blocklist, &context).await?;
is_valid_tagline_content(&content)?;
let tagline_form = TaglineUpdateForm {
content,

View file

@ -171,23 +171,18 @@ pub fn is_valid_body_field(body: &Option<String>, post: bool) -> LemmyResult<()>
Ok(())
}
pub fn is_valid_tagline_content(content: Option<String>) -> LemmyResult<String> {
match content {
Some(content) => {
min_length_check(
&content,
TAGLINE_CONTENT_MIN_LENGTH,
LemmyErrorType::TaglineContentRequired,
)?;
max_length_check(
&content,
TAGLINE_CONTENT_MAX_LENGTH,
LemmyErrorType::TaglineContentLengthOverflow,
)?;
Ok(content)
}
None => Err(LemmyErrorType::TaglineContentRequired.into()),
}
pub fn is_valid_tagline_content(content: &str) -> LemmyResult<()> {
min_length_check(
content,
TAGLINE_CONTENT_MIN_LENGTH,
LemmyErrorType::TaglineContentRequired,
)?;
max_length_check(
content,
TAGLINE_CONTENT_MAX_LENGTH,
LemmyErrorType::TaglineContentLengthOverflow,
)?;
Ok(())
}
pub fn is_valid_bio_field(bio: &str) -> LemmyResult<()> {