fix: align admin behavior and Kratos integrations

This commit is contained in:
2026-08-14 14:14:51 +08:00
parent 8c4c6ba661
commit e0b0e1d8c8
123 changed files with 4334 additions and 1877 deletions
+4 -6
View File
@@ -1,8 +1,6 @@
package middleware
import (
"net/http"
"strconv"
"time"
"kra/internal/server/httpx"
@@ -26,11 +24,11 @@ func SecurityRateLimit(system *service.SystemService, settings *service.Settings
if window < 1 {
window = 60
}
bucket := time.Now().Unix() / int64(window)
key := "rate:" + c.ClientIP() + ":" + strconv.FormatInt(bucket, 10)
count, cacheErr := system.CacheIncrement(c.Request.Context(), key, time.Duration(window+1)*time.Second)
key := "KRA_SecLimit" + c.ClientIP() + c.FullPath()
count, cacheErr := system.CacheIncrement(c.Request.Context(), key, time.Duration(window)*time.Second)
if cacheErr == nil && int(count) > config.LimitCount {
c.AbortWithStatusJSON(http.StatusTooManyRequests, httpx.Response{Code: httpx.CodeError, Data: nil, Msg: "请求过于频繁"})
httpx.Fail(c, "请求太过频繁,请稍后再试")
c.Abort()
return
}
c.Next()