update waf api

This commit is contained in:
uubulb 2024-12-21 19:16:28 +08:00
parent a839056d69
commit f86b4f961b
2 changed files with 13 additions and 10 deletions

View File

@ -15,21 +15,24 @@ import (
// @Schemes
// @Description List server
// @Tags auth required
// @Param page query uint false "Page number"
// @Param limit query uint false "Page limit"
// @Param offset query uint false "Page offset"
// @Produce json
// @Success 200 {object} model.CommonResponse[[]model.WAFApiMock]
// @Router /waf [get]
func listBlockedAddress(c *gin.Context) ([]*model.WAF, error) {
const pageSize = 25
page, err := strconv.ParseUint(c.Query("page"), 10, 64)
if err != nil || page < 1 {
page = 1
limit, err := strconv.ParseUint(c.Query("limit"), 10, 64)
if err != nil || limit < 1 {
limit = 25
}
offset, err := strconv.ParseUint(c.Query("offset"), 10, 64)
if err != nil || offset < 1 {
offset = 1
}
offset := (page - 1) * pageSize
var waf []*model.WAF
if err := singleton.DB.Limit(pageSize).Offset(int(offset)).Find(&waf).Error; err != nil {
if err := singleton.DB.Limit(int(limit)).Offset(int(offset)).Find(&waf).Error; err != nil {
return nil, err
}

View File

@ -52,8 +52,8 @@ func CheckIP(db *gorm.DB, ip string) error {
}
var blockTimestamp uint64
result := db.Model(&WAF{}).Select("block_timestamp").Order("id desc").Where("ip = ?", ipBinary).First(&blockTimestamp)
if result.Error != nil && result.Error != gorm.ErrRecordNotFound {
result := db.Model(&WAF{}).Select("block_timestamp").Order("id desc").Where("ip = ?", ipBinary).Limit(1).Find(&blockTimestamp)
if result.Error != nil {
return result.Error
}