Replace Comment System #4

Merged
w33b merged 20 commits from comment-system into main 2026-01-10 21:16:56 +00:00
2 changed files with 6 additions and 7 deletions
Showing only changes of commit dfedf4058e - Show all commits

View File

@@ -85,15 +85,16 @@ class Comment extends Component
$user = auth()->user(); $user = auth()->user();
$rateLimitKey = "send-comment:{$user->id}"; $rateLimitKey = "send-comment:{$user->id}";
$rateLimitMinutes = 60 * 5; // 5 minutes
if (RateLimiter::tooManyAttempts($rateLimitKey, 5)) { if (RateLimiter::tooManyAttempts($rateLimitKey, 1)) {
$seconds = RateLimiter::availableIn($rateLimitKey); $seconds = RateLimiter::availableIn($rateLimitKey);
$this->addError('replyState.body', "Too many comments. Try again in {$seconds} seconds."); $this->addError('replyState.body', "Too many comments. Try again in {$seconds} seconds.");
return; return;
} }
RateLimiter::hit($rateLimitKey, 60); RateLimiter::hit($rateLimitKey, $rateLimitMinutes);
$this->validate([ $this->validate([
'replyState.body' => 'required' 'replyState.body' => 'required'

View File

@@ -31,20 +31,18 @@ class Comments extends Component
'newCommentState.body' => 'required' 'newCommentState.body' => 'required'
]); ]);
$this->addError('newCommentState.body', "Too many comments. Try again in 1 seconds.");
return;
$user = auth()->user(); $user = auth()->user();
$rateLimitKey = "send-comment:{$user->id}"; $rateLimitKey = "send-comment:{$user->id}";
$rateLimitMinutes = 60 * 5; // 5 minutes
if (RateLimiter::tooManyAttempts($rateLimitKey, 5)) { if (RateLimiter::tooManyAttempts($rateLimitKey, 1)) {
$seconds = RateLimiter::availableIn($rateLimitKey); $seconds = RateLimiter::availableIn($rateLimitKey);
$this->addError('newCommentState.body', "Too many comments. Try again in {$seconds} seconds."); $this->addError('newCommentState.body', "Too many comments. Try again in {$seconds} seconds.");
return; return;
} }
RateLimiter::hit($rateLimitKey, 60); RateLimiter::hit($rateLimitKey, $rateLimitMinutes);
$comment = $this->model->comments()->make($this->newCommentState); $comment = $this->model->comments()->make($this->newCommentState);
$comment->user()->associate($user); $comment->user()->associate($user);