66 lines
1.7 KiB
Go
66 lines
1.7 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/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()
|
|
}
|