支持批量添加域名、域名修改

This commit is contained in:
GoEdgeLab
2020-11-01 18:00:48 +08:00
parent cfe2fb1e91
commit 3982450fb9
5 changed files with 94 additions and 14 deletions

View File

@@ -4,6 +4,8 @@ import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
"regexp"
"strings"
)
type AddServerNamePopupAction struct {
@@ -19,17 +21,43 @@ func (this *AddServerNamePopupAction) RunGet(params struct{}) {
}
func (this *AddServerNamePopupAction) RunPost(params struct {
ServerName string
Mode string
ServerName string
ServerNames string
Must *actions.Must
}) {
params.Must.
Field("serverName", params.ServerName).
Require("请输入域名")
if params.Mode == "single" {
params.Must.
Field("serverName", params.ServerName).
Require("请输入域名")
this.Data["serverName"] = maps.Map{
"name": params.ServerName,
"type": "full",
}
} else if params.Mode == "multiple" {
if len(params.ServerNames) == 0 {
this.FailField("serverNames", "请输入至少域名")
}
this.Data["serverName"] = maps.Map{
"name": params.ServerName,
"type": "full",
serverNames := []string{}
for _, line := range strings.Split(params.ServerNames, "\n") {
line := strings.TrimSpace(line)
line = regexp.MustCompile(`\s+`).ReplaceAllString(line, "")
if len(line) == 0 {
continue
}
serverNames = append(serverNames, line)
}
this.Data["serverName"] = maps.Map{
"name": "",
"type": "full",
"subNames": serverNames,
}
} else {
this.Fail("错误的mode参数")
}
this.Success()
}