Update waf.go (#548)

WAF查询IP是否被封禁导致控制台大量报错,换一个查询方式。
This commit is contained in:
榆木 2024-12-04 20:00:35 +08:00 committed by GitHub
parent 872002d938
commit 0648f61e9c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -43,10 +43,12 @@ func CheckIP(db *gorm.DB, ip string) error {
return err return err
} }
var w WAF var w WAF
if err := db.First(&w, "ip = ?", ipBinary).Error; err != nil { result := db.Limit(1).Find(&w, "ip = ?", ipBinary)
if err != gorm.ErrRecordNotFound { if result.Error != nil {
return err return result.Error
} }
if result.RowsAffected == 0 { // 检查是否未找到记录
return nil
} }
now := time.Now().Unix() now := time.Now().Unix()
if powAdd(w.Count, 4, w.LastBlockTimestamp) > uint64(now) { if powAdd(w.Count, 4, w.LastBlockTimestamp) > uint64(now) {