X-Git-Url: http://these/git/?a=blobdiff_plain;f=crates%2Fapi%2Fsrc%2Flib.rs;h=b297f503f6f9d4abc2115255a55e8ca567bd5fff;hb=3471f3533cb724b2cf6953d563aadfcc9f66c1d2;hp=44e7a76b59c458a25af7e4facc8ac4192b5a7b82;hpb=ff26bc21af8edb70ea21be30231d229ca20a3993;p=lemmy.git diff --git a/crates/api/src/lib.rs b/crates/api/src/lib.rs index 44e7a76b..b297f503 100644 --- a/crates/api/src/lib.rs +++ b/crates/api/src/lib.rs @@ -3,7 +3,10 @@ use base64::{engine::general_purpose::STANDARD_NO_PAD as base64, Engine}; use captcha::Captcha; use lemmy_api_common::{context::LemmyContext, utils::local_site_to_slur_regex}; use lemmy_db_schema::source::local_site::LocalSite; -use lemmy_utils::{error::LemmyError, utils::slurs::check_slurs}; +use lemmy_utils::{ + error::{LemmyError, LemmyErrorExt, LemmyErrorType}, + utils::slurs::check_slurs, +}; use std::io::Cursor; mod comment; @@ -37,7 +40,7 @@ pub(crate) fn captcha_as_wav_base64(captcha: &Captcha) -> Result Result header, - None => return Err(LemmyError::from_message("couldnt_create_audio_captcha")), + None => return Err(LemmyErrorType::CouldntCreateAudioCaptcha)?, }; - let wav_write_result = wav::write( + wav::write( header, &wav::BitDepth::Sixteen(concat_samples), &mut output_buffer, - ); - if let Err(e) = wav_write_result { - return Err(LemmyError::from_error_message( - e, - "couldnt_create_audio_captcha", - )); - } + ) + .with_lemmy_type(LemmyErrorType::CouldntCreateAudioCaptcha)?; Ok(base64.encode(output_buffer.into_inner())) } -/// Check size of report and remove whitespace +/// Check size of report pub(crate) fn check_report_reason(reason: &str, local_site: &LocalSite) -> Result<(), LemmyError> { let slur_regex = &local_site_to_slur_regex(local_site); check_slurs(reason, slur_regex)?; if reason.is_empty() { - return Err(LemmyError::from_message("report_reason_required")); + return Err(LemmyErrorType::ReportReasonRequired)?; } if reason.chars().count() > 1000 { - return Err(LemmyError::from_message("report_too_long")); + return Err(LemmyErrorType::ReportTooLong)?; } Ok(()) } #[cfg(test)] mod tests { + #![allow(clippy::unwrap_used)] + #![allow(clippy::indexing_slicing)] + use lemmy_api_common::utils::check_validator_time; use lemmy_db_schema::{ source::{ @@ -96,6 +97,7 @@ mod tests { #[serial] async fn test_should_not_validate_user_token_after_password_change() { let pool = &build_db_pool_for_tests().await; + let pool = &mut pool.into(); let secret = Secret::init(pool).await.unwrap(); let settings = &SETTINGS.to_owned();