mirror of
https://github.com/nezhahq/nezha.git
synced 2025-01-22 12:48:14 -05:00
update waf api
This commit is contained in:
parent
a839056d69
commit
f86b4f961b
@ -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
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user