mirror of
				https://github.com/TeaOSLab/EdgeAdmin.git
				synced 2025-11-04 05:00:25 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			84 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			84 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
package providers
 | 
						|
 | 
						|
import (
 | 
						|
	"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
 | 
						|
	"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
 | 
						|
	"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
 | 
						|
	"github.com/iwind/TeaGo/actions"
 | 
						|
	"github.com/iwind/TeaGo/maps"
 | 
						|
)
 | 
						|
 | 
						|
type CreatePopupAction struct {
 | 
						|
	actionutils.ParentAction
 | 
						|
}
 | 
						|
 | 
						|
func (this *CreatePopupAction) Init() {
 | 
						|
	this.Nav("", "", "")
 | 
						|
}
 | 
						|
 | 
						|
func (this *CreatePopupAction) RunGet(params struct{}) {
 | 
						|
	// 所有厂商
 | 
						|
	typesResp, err := this.RPC().DNSProviderRPC().FindAllDNSProviderTypes(this.AdminContext(), &pb.FindAllDNSProviderTypesRequest{})
 | 
						|
	if err != nil {
 | 
						|
		this.ErrorPage(err)
 | 
						|
		return
 | 
						|
	}
 | 
						|
	typeMaps := []maps.Map{}
 | 
						|
	for _, t := range typesResp.ProviderTypes {
 | 
						|
		typeMaps = append(typeMaps, maps.Map{
 | 
						|
			"name": t.Name,
 | 
						|
			"code": t.Code,
 | 
						|
		})
 | 
						|
	}
 | 
						|
	this.Data["types"] = typeMaps
 | 
						|
 | 
						|
	this.Show()
 | 
						|
}
 | 
						|
 | 
						|
func (this *CreatePopupAction) RunPost(params struct {
 | 
						|
	Name string
 | 
						|
	Type string
 | 
						|
 | 
						|
	// dnspod
 | 
						|
	ParamId    string
 | 
						|
	ParamToken string
 | 
						|
 | 
						|
	Must *actions.Must
 | 
						|
	CSRF *actionutils.CSRF
 | 
						|
}) {
 | 
						|
	params.Must.
 | 
						|
		Field("name", params.Name).
 | 
						|
		Require("请输入账号说明").
 | 
						|
		Field("type", params.Type).
 | 
						|
		Require("请选择服务商厂家")
 | 
						|
 | 
						|
	apiParams := maps.Map{}
 | 
						|
	switch params.Type {
 | 
						|
	case "dnspod":
 | 
						|
		params.Must.
 | 
						|
			Field("paramId", params.ParamId).
 | 
						|
			Require("请输入密钥ID").
 | 
						|
			Field("paramToken", params.ParamToken).
 | 
						|
			Require("请输入密钥Token")
 | 
						|
 | 
						|
		apiParams["id"] = params.ParamId
 | 
						|
		apiParams["token"] = params.ParamToken
 | 
						|
	default:
 | 
						|
		this.Fail("暂时不支持此服务商'" + params.Type + "'")
 | 
						|
	}
 | 
						|
 | 
						|
	createResp, err := this.RPC().DNSProviderRPC().CreateDNSProvider(this.AdminContext(), &pb.CreateDNSProviderRequest{
 | 
						|
		Name:          params.Name,
 | 
						|
		Type:          params.Type,
 | 
						|
		ApiParamsJSON: apiParams.AsJSON(),
 | 
						|
	})
 | 
						|
	if err != nil {
 | 
						|
		this.ErrorPage(err)
 | 
						|
		return
 | 
						|
	}
 | 
						|
 | 
						|
	this.CreateLog(oplogs.LevelInfo, "创建DNS服务商 %d", createResp.DnsProviderId)
 | 
						|
 | 
						|
	this.Success()
 | 
						|
}
 |