From d4b29a5357919fbfbd016e16b3c6a25b1ff1bd65 Mon Sep 17 00:00:00 2001 From: Marvin Zhang Date: Wed, 11 Dec 2024 20:05:03 +0800 Subject: [PATCH] fix: added default fields --- core/controllers/spider.go | 8 ++++++++ core/controllers/utils_pagination.go | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/core/controllers/spider.go b/core/controllers/spider.go index e4b9f440..163e6c53 100644 --- a/core/controllers/spider.go +++ b/core/controllers/spider.go @@ -2,6 +2,7 @@ package controllers import ( "errors" + "github.com/crawlab-team/crawlab/core/constants" "github.com/crawlab-team/crawlab/core/models/models" "math" "os" @@ -252,6 +253,13 @@ func PostSpider(c *gin.Context) { return } + if s.Mode == "" { + s.Mode = constants.RunTypeRandom + } + if s.Priority == 0 { + s.Priority = 5 + } + // user u := GetUserFromContext(c) diff --git a/core/controllers/utils_pagination.go b/core/controllers/utils_pagination.go index d16278af..4f148ecf 100644 --- a/core/controllers/utils_pagination.go +++ b/core/controllers/utils_pagination.go @@ -18,6 +18,12 @@ func GetPagination(c *gin.Context) (p *entity.Pagination, err error) { if err := c.ShouldBindQuery(&_p); err != nil { return GetDefaultPagination(), err } + if _p.Page == 0 { + _p.Page = constants.PaginationDefaultPage + } + if _p.Size == 0 { + _p.Size = constants.PaginationDefaultSize + } return &_p, nil }