From 0f131a310c9e790cdf7fbd6a20a15f9fd3a1c20e Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 25 Jul 2021 15:44:14 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8C=BA=E5=88=86=E7=A4=BE=E5=8C=BA=E7=89=88?= =?UTF-8?q?=E5=92=8C=E5=95=86=E4=B8=9A=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/const/build.go | 7 ++ internal/tasks/task_authority.go | 93 ------------------- .../settings/settingutils/advanced_helper.go | 4 +- 3 files changed, 10 insertions(+), 94 deletions(-) create mode 100644 internal/const/build.go delete mode 100644 internal/tasks/task_authority.go diff --git a/internal/const/build.go b/internal/const/build.go new file mode 100644 index 00000000..eb65a29f --- /dev/null +++ b/internal/const/build.go @@ -0,0 +1,7 @@ +// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. +// +build community + +package teaconst + +const BuildCommunity = true +const BuildPlus = false diff --git a/internal/tasks/task_authority.go b/internal/tasks/task_authority.go deleted file mode 100644 index 278baaa5..00000000 --- a/internal/tasks/task_authority.go +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved. - -package tasks - -import ( - "github.com/TeaOSLab/EdgeAdmin/internal/configs" - teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const" - "github.com/TeaOSLab/EdgeAdmin/internal/events" - "github.com/TeaOSLab/EdgeAdmin/internal/rpc" - "github.com/TeaOSLab/EdgeAdmin/internal/setup" - "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" - "github.com/iwind/TeaGo/Tea" - "github.com/iwind/TeaGo/logs" - timeutil "github.com/iwind/TeaGo/utils/time" - "time" -) - -func init() { - events.On(events.EventStart, func() { - task := NewAuthorityTask() - go task.Start() - }) -} - -type AuthorityTask struct { -} - -func NewAuthorityTask() *AuthorityTask { - return &AuthorityTask{} -} - -func (this *AuthorityTask) Start() { - // 从缓存中读取 - config := configs.ReadPlusConfig() - if config != nil { - teaconst.IsPlus = config.IsPlus - } - - // 开始计时器 - ticker := time.NewTicker(10 * time.Minute) - if Tea.IsTesting() { - // 快速测试 - ticker = time.NewTicker(1 * time.Minute) - } - - // 初始化的时候先获取一次 - timeout := time.NewTimer(3 * time.Second) - <-timeout.C - err := this.Loop() - if err != nil { - logs.Println("[TASK][AuthorityTask]" + err.Error()) - } - - // 定时获取 - for range ticker.C { - err := this.Loop() - if err != nil { - logs.Println("[TASK][AuthorityTask]" + err.Error()) - } - } -} - -func (this *AuthorityTask) Loop() error { - // 如果还没有安装直接返回 - if !setup.IsConfigured() { - return nil - } - - rpcClient, err := rpc.SharedRPC() - if err != nil { - return err - } - resp, err := rpcClient.AuthorityKeyRPC().ReadAuthorityKey(rpcClient.Context(0), &pb.ReadAuthorityKeyRequest{}) - if err != nil { - return err - } - if resp.AuthorityKey == nil { - teaconst.IsPlus = false - return nil - } - var oldState = teaconst.IsPlus - if resp.AuthorityKey != nil && len(resp.AuthorityKey.Value) > 0 && resp.AuthorityKey.DayTo >= timeutil.Format("Y-m-d") { - teaconst.IsPlus = true - } else { - teaconst.IsPlus = false - } - - if oldState != teaconst.IsPlus { - _ = configs.WritePlusConfig(&configs.PlusConfig{IsPlus: teaconst.IsPlus}) - } - - return nil -} diff --git a/internal/web/actions/default/settings/settingutils/advanced_helper.go b/internal/web/actions/default/settings/settingutils/advanced_helper.go index cab9b8f7..1ee2b042 100644 --- a/internal/web/actions/default/settings/settingutils/advanced_helper.go +++ b/internal/web/actions/default/settings/settingutils/advanced_helper.go @@ -38,7 +38,9 @@ func (this *AdvancedHelper) BeforeAction(actionPtr actions.ActionWrapper) (goNex if teaconst.IsPlus { tabbar.Add("监控节点", "", "/settings/monitorNodes", "", this.tab == "monitorNodes") } - tabbar.Add("企业版认证", "", "/settings/authority", "", this.tab == "authority") + if teaconst.BuildPlus { + tabbar.Add("企业版认证", "", "/settings/authority", "", this.tab == "authority") + } //tabbar.Add("备份", "", "/settings/backup", "", this.tab == "backup") }