mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
fix: openai model validator
This commit is contained in:
parent
db832d045b
commit
da2c6d83d6
5 changed files with 14 additions and 14 deletions
|
@ -54,7 +54,7 @@ const errors: Record<string, Record<string, string>> = inject('errors') as Recor
|
||||||
<AFormItem
|
<AFormItem
|
||||||
:label="$gettext('API Token')"
|
:label="$gettext('API Token')"
|
||||||
:validate-status="errors?.openai?.token ? 'error' : ''"
|
:validate-status="errors?.openai?.token ? 'error' : ''"
|
||||||
:help="errors?.openai?.token === 'alphanumdash'
|
:help="errors?.openai?.token === 'alpha_num_dash_dot'
|
||||||
? $gettext('Token is not valid')
|
? $gettext('Token is not valid')
|
||||||
: ''"
|
: ''"
|
||||||
>
|
>
|
||||||
|
|
10
internal/validation/alpha_num_dash_dot.go
Normal file
10
internal/validation/alpha_num_dash_dot.go
Normal file
|
@ -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())
|
||||||
|
}
|
|
@ -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())
|
|
||||||
}
|
|
|
@ -12,7 +12,7 @@ func Init() {
|
||||||
logger.Fatal("binding validator engine is not initialized")
|
logger.Fatal("binding validator engine is not initialized")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := v.RegisterValidation("alphanumdash", alphaNumDash)
|
err := v.RegisterValidation("alpha_num_dash_dot", alphaNumDashDot)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Fatal(err)
|
logger.Fatal(err)
|
||||||
|
|
|
@ -2,9 +2,9 @@ package settings
|
||||||
|
|
||||||
type OpenAI struct {
|
type OpenAI struct {
|
||||||
BaseUrl string `json:"base_url" binding:"omitempty,url"`
|
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"`
|
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{}
|
var OpenAISettings = OpenAI{}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue