chore: build
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
@@ -14,11 +15,26 @@ import (
|
||||
|
||||
var (
|
||||
cancelRateLimitMap = make(map[string][]time.Time)
|
||||
cancelRateLimitMu sync.Mutex
|
||||
cancelMaxRequests = 5 // Max 5 annulations
|
||||
cancelTimeWindow = time.Hour // Par heure
|
||||
)
|
||||
|
||||
func isCancelRateLimited(key string) bool {
|
||||
cancelRateLimitMu.Lock()
|
||||
defer cancelRateLimitMu.Unlock()
|
||||
return countRecent(cancelRateLimitMap[key], cancelTimeWindow) >= cancelMaxRequests
|
||||
}
|
||||
|
||||
func resetCancelRateLimit(key string) {
|
||||
cancelRateLimitMu.Lock()
|
||||
defer cancelRateLimitMu.Unlock()
|
||||
delete(cancelRateLimitMap, key)
|
||||
}
|
||||
|
||||
func checkCancelRateLimit(key string) bool {
|
||||
cancelRateLimitMu.Lock()
|
||||
defer cancelRateLimitMu.Unlock()
|
||||
now := time.Now()
|
||||
|
||||
if timestamps, exists := cancelRateLimitMap[key]; exists {
|
||||
@@ -67,7 +83,7 @@ func CancelCommandByClient(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
rateLimitKey := fmt.Sprintf("cancel:%s", username)
|
||||
rateLimitKey := cancelRateLimitKey(username)
|
||||
if !checkCancelRateLimit(rateLimitKey) {
|
||||
log.Printf("⚠️ [CANCEL_CLIENT] Rate limit dépassé pour %s", username)
|
||||
c.JSON(http.StatusTooManyRequests, gin.H{
|
||||
|
||||
Reference in New Issue
Block a user