Agent 节点免填地址/端口/API令牌(前后端校验)+ 补翻译

This commit is contained in:
Muse
2026-10-19 21:00:13 +08:00
parent fc59cb1032
commit 6381587307
3 changed files with 18 additions and 8 deletions
+12 -2
View File
@@ -118,8 +118,8 @@ type NodeMutationRequest struct {
Name string `json:"name" form:"name" validate:"required"`
Remark string `json:"remark" form:"remark"`
Scheme string `json:"scheme" form:"scheme" validate:"omitempty,oneof=http https"`
Address string `json:"address" form:"address" validate:"required"`
Port int `json:"port" form:"port" validate:"gte=1,lte=65535"`
Address string `json:"address" form:"address"`
Port int `json:"port" form:"port" validate:"gte=0,lte=65535"`
BasePath string `json:"basePath" form:"basePath"`
ApiToken *string `json:"apiToken,omitempty" form:"apiToken"`
ClearApiToken bool `json:"clearApiToken,omitempty" form:"clearApiToken"`
@@ -140,6 +140,16 @@ func (r *NodeMutationRequest) validateCredentials(create bool) error {
if r == nil {
return common.NewError("node request is required")
}
// Agent nodes dial out to the master; address/port are not needed.
// Traditional nodes still require them.
if r.NodeType != "agent" {
if strings.TrimSpace(r.Address) == "" {
return common.NewError("address is required")
}
if r.Port < 1 || r.Port > 65535 {
return common.NewError("port must be between 1 and 65535")
}
}
if r.ApiToken != nil && r.ClearApiToken {
return common.NewError("apiToken and clearApiToken are mutually exclusive")
}