Initial commit (code only without large binaries)
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
// 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()
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
type DeleteAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *DeleteAction) RunPost(params struct {
|
||||
ScriptId int64
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.Script_LogDeleteScript, params.ScriptId)
|
||||
|
||||
_, err := this.RPC().ScriptRPC().DeleteScript(this.AdminContext(), &pb.DeleteScriptRequest{ScriptId: params.ScriptId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
// 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/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
timeutil "github.com/iwind/TeaGo/utils/time"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
// 检查是否更新
|
||||
updatesResp, err := this.RPC().ScriptRPC().CheckScriptUpdates(this.AdminContext(), &pb.CheckScriptUpdatesRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
this.Data["hasUpdates"] = updatesResp.HasUpdates
|
||||
var lastVersion = updatesResp.Version
|
||||
|
||||
// 数量
|
||||
countResp, err := this.RPC().ScriptRPC().CountAllEnabledScripts(this.AdminContext(), &pb.CountAllEnabledScriptsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var count = countResp.Count
|
||||
var page = this.NewPage(count)
|
||||
this.Data["page"] = page.AsHTML()
|
||||
|
||||
// 单页脚本
|
||||
scriptsResp, err := this.RPC().ScriptRPC().ListEnabledScripts(this.AdminContext(), &pb.ListEnabledScriptsRequest{
|
||||
Offset: page.Offset,
|
||||
Size: page.Size,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var scriptMaps = []maps.Map{}
|
||||
for _, script := range scriptsResp.Scripts {
|
||||
scriptMaps = append(scriptMaps, maps.Map{
|
||||
"id": script.Id,
|
||||
"name": script.Name,
|
||||
"filename": script.Filename,
|
||||
"isOn": script.IsOn,
|
||||
"updatedTime": timeutil.FormatTime("Y-m-d H:i:s", script.UpdatedAt),
|
||||
"isChanged": script.UpdatedAt > lastVersion,
|
||||
})
|
||||
}
|
||||
this.Data["scripts"] = scriptMaps
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
//go:build plus
|
||||
|
||||
package scripts
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeServer)).
|
||||
Data("teaMenu", "servers").
|
||||
Data("teaSubMenu", "script").
|
||||
Prefix("/servers/scripts").
|
||||
Get("", new(IndexAction)).
|
||||
GetPost("/createPopup", new(CreatePopupAction)).
|
||||
GetPost("/update", new(UpdateAction)).
|
||||
Post("/delete", new(DeleteAction)).
|
||||
Get("/script", new(ScriptAction)).
|
||||
Post("/publish", new(PublishAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// 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"
|
||||
)
|
||||
|
||||
type PublishAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *PublishAction) RunPost(params struct{}) {
|
||||
defer this.CreateLogInfo(codes.Script_LogPublishScripts)
|
||||
|
||||
_, err := this.RPC().ScriptRPC().PublishScripts(this.AdminContext(), &pb.PublishScriptsRequest{})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// 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/rpc/pb"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
)
|
||||
|
||||
type ScriptAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *ScriptAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *ScriptAction) RunGet(params struct {
|
||||
ScriptId int64
|
||||
}) {
|
||||
scriptResp, err := this.RPC().ScriptRPC().FindEnabledScript(this.AdminContext(), &pb.FindEnabledScriptRequest{ScriptId: params.ScriptId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var script = scriptResp.Script
|
||||
if script == nil {
|
||||
this.NotFound("script", params.ScriptId)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["script"] = maps.Map{
|
||||
"id": script.Id,
|
||||
"name": script.Name,
|
||||
"filename": script.Filename,
|
||||
"code": script.Code,
|
||||
"isOn": script.IsOn,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
// 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"
|
||||
"github.com/iwind/TeaGo/maps"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type UpdateAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *UpdateAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *UpdateAction) RunGet(params struct {
|
||||
ScriptId int64
|
||||
EditingCode bool
|
||||
}) {
|
||||
this.Data["isEditingCode"] = params.EditingCode
|
||||
|
||||
scriptResp, err := this.RPC().ScriptRPC().FindEnabledScript(this.AdminContext(), &pb.FindEnabledScriptRequest{ScriptId: params.ScriptId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
var script = scriptResp.Script
|
||||
if script == nil {
|
||||
this.NotFound("script", params.ScriptId)
|
||||
return
|
||||
}
|
||||
|
||||
this.Data["script"] = maps.Map{
|
||||
"id": script.Id,
|
||||
"name": script.Name,
|
||||
"filename": script.Filename,
|
||||
"code": script.Code,
|
||||
"isOn": script.IsOn,
|
||||
}
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *UpdateAction) RunPost(params struct {
|
||||
ScriptId int64
|
||||
Filename string
|
||||
Name string
|
||||
Code string
|
||||
IsOn bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.Script_LogUpdateScript, params.ScriptId)
|
||||
|
||||
params.Must.
|
||||
Field("filename", params.Filename).
|
||||
Require("请输入脚本文件名").
|
||||
Field("name", params.Name).
|
||||
Require("请输入脚本说明")
|
||||
|
||||
if !strings.HasSuffix(params.Filename, ".js") {
|
||||
params.Filename += ".js"
|
||||
}
|
||||
|
||||
_, err := this.RPC().ScriptRPC().UpdateScript(this.AdminContext(), &pb.UpdateScriptRequest{
|
||||
ScriptId: params.ScriptId,
|
||||
Name: params.Name,
|
||||
Filename: params.Filename,
|
||||
Code: params.Code,
|
||||
IsOn: params.IsOn,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
Reference in New Issue
Block a user