From da2c6d83d6c0e1be31ff436f3be8f4eeea2d10dc Mon Sep 17 00:00:00 2001 From: 0xJacky Date: Mon, 29 Jan 2024 21:24:32 +0800 Subject: [PATCH] fix: openai model validator --- app/src/views/preference/OpenAISettings.vue | 2 +- internal/validation/alpha_num_dash_dot.go | 10 ++++++++++ internal/validation/alphanumdash.go | 10 ---------- internal/validation/validation.go | 2 +- settings/openai.go | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 internal/validation/alpha_num_dash_dot.go delete mode 100644 internal/validation/alphanumdash.go diff --git a/app/src/views/preference/OpenAISettings.vue b/app/src/views/preference/OpenAISettings.vue index 3c537532..2a7892a1 100644 --- a/app/src/views/preference/OpenAISettings.vue +++ b/app/src/views/preference/OpenAISettings.vue @@ -54,7 +54,7 @@ const errors: Record> = inject('errors') as Recor diff --git a/internal/validation/alpha_num_dash_dot.go b/internal/validation/alpha_num_dash_dot.go new file mode 100644 index 00000000..03cecbe8 --- /dev/null +++ b/internal/validation/alpha_num_dash_dot.go @@ -0,0 +1,10 @@ +package validation + +import ( + val "github.com/go-playground/validator/v10" + "regexp" +) + +func alphaNumDashDot(fl val.FieldLevel) bool { + return regexp.MustCompile(`^[a-zA-Z0-9-.]+$`).MatchString(fl.Field().String()) +} diff --git a/internal/validation/alphanumdash.go b/internal/validation/alphanumdash.go deleted file mode 100644 index 39f6ce75..00000000 --- a/internal/validation/alphanumdash.go +++ /dev/null @@ -1,10 +0,0 @@ -package validation - -import ( - val "github.com/go-playground/validator/v10" - "regexp" -) - -func alphaNumDash(fl val.FieldLevel) bool { - return regexp.MustCompile(`^[a-zA-Z0-9-]+$`).MatchString(fl.Field().String()) -} diff --git a/internal/validation/validation.go b/internal/validation/validation.go index 0389e827..df3bd895 100644 --- a/internal/validation/validation.go +++ b/internal/validation/validation.go @@ -12,7 +12,7 @@ func Init() { logger.Fatal("binding validator engine is not initialized") } - err := v.RegisterValidation("alphanumdash", alphaNumDash) + err := v.RegisterValidation("alpha_num_dash_dot", alphaNumDashDot) if err != nil { logger.Fatal(err) diff --git a/settings/openai.go b/settings/openai.go index 140d619e..66b4df69 100644 --- a/settings/openai.go +++ b/settings/openai.go @@ -2,9 +2,9 @@ package settings type OpenAI struct { BaseUrl string `json:"base_url" binding:"omitempty,url"` - Token string `json:"token" binding:"omitempty,alphanumdash"` + Token string `json:"token" binding:"omitempty,alpha_num_dash_dot"` Proxy string `json:"proxy" binding:"omitempty,url"` - Model string `json:"model" binding:"omitempty,alphanumdash"` + Model string `json:"model" binding:"omitempty,alpha_num_dash_dot"` } var OpenAISettings = OpenAI{}