62 lines
1.3 KiB
Go
62 lines
1.3 KiB
Go
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
//go:build plus
|
|
|
|
package scripts
|
|
|
|
import (
|
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
|
"github.com/iwind/TeaGo/actions"
|
|
"strings"
|
|
)
|
|
|
|
type CreatePopupAction struct {
|
|
actionutils.ParentAction
|
|
}
|
|
|
|
func (this *CreatePopupAction) Init() {
|
|
this.Nav("", "", "")
|
|
}
|
|
|
|
func (this *CreatePopupAction) RunGet(params struct{}) {
|
|
this.Show()
|
|
}
|
|
|
|
func (this *CreatePopupAction) RunPost(params struct {
|
|
Filename string
|
|
Name string
|
|
Code string
|
|
|
|
Must *actions.Must
|
|
CSRF *actionutils.CSRF
|
|
}) {
|
|
var scriptId int64
|
|
defer func() {
|
|
this.CreateLogInfo(codes.Script_LogCreateScript, scriptId)
|
|
}()
|
|
|
|
params.Must.
|
|
Field("filename", params.Filename).
|
|
Require("请输入脚本文件名").
|
|
Field("name", params.Name).
|
|
Require("请输入脚本说明")
|
|
|
|
if !strings.HasSuffix(params.Filename, ".js") {
|
|
params.Filename += ".js"
|
|
}
|
|
|
|
createResp, err := this.RPC().ScriptRPC().CreateScript(this.AdminContext(), &pb.CreateScriptRequest{
|
|
Name: params.Name,
|
|
Filename: params.Filename,
|
|
Code: params.Code,
|
|
})
|
|
if err != nil {
|
|
this.ErrorPage(err)
|
|
return
|
|
}
|
|
scriptId = createResp.ScriptId
|
|
|
|
this.Success()
|
|
}
|