This commit is contained in:
2026-08-15 01:28:51 +08:00
parent 6698e59c3a
commit 2f165d3a45
26 changed files with 242 additions and 216 deletions
+2 -2
View File
@@ -10,7 +10,7 @@ import (
"github.com/gin-gonic/gin"
)
func SecurityRateLimit(system *service.SystemService, settings *service.SettingsService) gin.HandlerFunc {
func SecurityRateLimit(settings *service.SettingsService) gin.HandlerFunc {
return func(c *gin.Context) {
path := strings.TrimSuffix(c.Request.URL.Path, "/")
if !strings.HasSuffix(path, "/base/login") && !strings.HasSuffix(path, "/base/captcha") {
@@ -27,7 +27,7 @@ func SecurityRateLimit(system *service.SystemService, settings *service.Settings
window = 60
}
key := "KRA_SecLimit" + c.ClientIP() + c.FullPath()
count, cacheErr := system.CacheIncrement(c.Request.Context(), key, time.Duration(window)*time.Second)
count, cacheErr := settings.CacheIncrement(c.Request.Context(), key, time.Duration(window)*time.Second)
if cacheErr == nil && int(count) > config.LimitCount {
httpx.Fail(c, "请求太过频繁,请稍后再试")
c.Abort()