Fix some bug for scan task.
This commit is contained in:
parent
7adf56ce0a
commit
fbea823ba1
@ -2,10 +2,10 @@ package rest
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/eyebluecn/tank/code/core"
|
"github.com/eyebluecn/tank/code/core"
|
||||||
|
"github.com/eyebluecn/tank/code/tool/i18n"
|
||||||
"github.com/eyebluecn/tank/code/tool/result"
|
"github.com/eyebluecn/tank/code/tool/result"
|
||||||
"github.com/eyebluecn/tank/code/tool/util"
|
"github.com/eyebluecn/tank/code/tool/util"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
"github.com/robfig/cron/v3"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
@ -152,6 +152,9 @@ func (this *PreferenceController) EditPreviewConfig(writer http.ResponseWriter,
|
|||||||
func (this *PreferenceController) EditScanConfig(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
func (this *PreferenceController) EditScanConfig(writer http.ResponseWriter, request *http.Request) *result.WebResult {
|
||||||
|
|
||||||
scanConfigStr := request.FormValue("scanConfig")
|
scanConfigStr := request.FormValue("scanConfig")
|
||||||
|
if scanConfigStr == "" {
|
||||||
|
panic(result.BadRequest("scanConfig cannot be null"))
|
||||||
|
}
|
||||||
|
|
||||||
preference := this.preferenceDao.Fetch()
|
preference := this.preferenceDao.Fetch()
|
||||||
|
|
||||||
@ -164,8 +167,9 @@ func (this *PreferenceController) EditScanConfig(writer http.ResponseWriter, req
|
|||||||
//validate the scan config.
|
//validate the scan config.
|
||||||
if scanConfig.Enable {
|
if scanConfig.Enable {
|
||||||
//validate cron.
|
//validate cron.
|
||||||
_, err := cron.ParseStandard(scanConfig.Cron)
|
if !util.ValidateCron(scanConfig.Cron) {
|
||||||
this.PanicError(err)
|
panic(result.CustomWebResultI18n(request, result.SHARE_CODE_ERROR, i18n.CronValidateError))
|
||||||
|
}
|
||||||
|
|
||||||
//validate scope.
|
//validate scope.
|
||||||
if scanConfig.Scope == SCAN_SCOPE_CUSTOM {
|
if scanConfig.Scope == SCAN_SCOPE_CUSTOM {
|
||||||
@ -179,6 +183,7 @@ func (this *PreferenceController) EditScanConfig(writer http.ResponseWriter, req
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
preference.ScanConfig = scanConfigStr
|
||||||
preference = this.preferenceService.Save(preference)
|
preference = this.preferenceService.Save(preference)
|
||||||
|
|
||||||
//reinit the scan task.
|
//reinit the scan task.
|
||||||
|
@ -45,6 +45,7 @@ var (
|
|||||||
ShareNumExceedLimit = &Item{English: `sharing files' num exceed the limit %d > %d`, Chinese: `一次分享的文件数量超出限制了 %d > %d `}
|
ShareNumExceedLimit = &Item{English: `sharing files' num exceed the limit %d > %d`, Chinese: `一次分享的文件数量超出限制了 %d > %d `}
|
||||||
ShareCodeRequired = &Item{English: `share code required`, Chinese: `提取码必填`}
|
ShareCodeRequired = &Item{English: `share code required`, Chinese: `提取码必填`}
|
||||||
ShareCodeError = &Item{English: `share code error`, Chinese: `提取码错误`}
|
ShareCodeError = &Item{English: `share code error`, Chinese: `提取码错误`}
|
||||||
|
CronValidateError = &Item{English: `cron error. five fields needed. eg: 1 * * * *`, Chinese: `Cron表达式错误,必须为5位。例如:1 * * * *`}
|
||||||
)
|
)
|
||||||
|
|
||||||
func (this *Item) Message(request *http.Request) string {
|
func (this *Item) Message(request *http.Request) string {
|
||||||
|
Loading…
Reference in New Issue
Block a user