From 7c01c70b4d3b705ef767b7d61cdfa1aab3130baa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sn=C3=ADda=C5=88ov=C3=BD=20Mistr?= Date: Mon, 4 Mar 2024 08:00:04 +0000 Subject: [PATCH] =?UTF-8?q?Kritick=C3=A1=20chyba!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/web/actions/create_post.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/web/actions/create_post.rs b/src/web/actions/create_post.rs index d9253c0..7ea635a 100644 --- a/src/web/actions/create_post.rs +++ b/src/web/actions/create_post.rs @@ -322,13 +322,15 @@ pub async fn check_spam( return Err(NekrochanError::FloodError); } - let last_thread: i64 = ctx.cache().get(format!("last_thread:{ip}")).await?; + let last_thread: Option = ctx.cache().get(format!("last_thread:{ip}")).await?; - let since_last_thread = Utc::now().timestamp_micros() - last_thread; - let since_last_thread = Duration::microseconds(since_last_thread); + if let Some(last_thread) = last_thread { + let since_last_thread = Utc::now().timestamp_micros() - last_thread; + let since_last_thread = Duration::microseconds(since_last_thread); - if since_last_thread.num_seconds() < board.config.thread_cooldown { - return Err(NekrochanError::FloodError); + if since_last_thread.num_seconds() < board.config.thread_cooldown { + return Err(NekrochanError::FloodError); + } } Ok(())