实现自动下载升级版本

This commit is contained in:
GoEdgeLab
2023-06-13 20:52:37 +08:00
parent 05100d0ac4
commit 62d6e5bc17
13 changed files with 380 additions and 40 deletions

View File

@@ -0,0 +1,61 @@
// Copyright 2023 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package updates
import (
"encoding/json"
teaconst "github.com/TeaOSLab/EdgeAdmin/internal/const"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
)
type IgnoreVersionAction struct {
actionutils.ParentAction
}
func (this *IgnoreVersionAction) RunPost(params struct {
Version string
}) {
defer this.CreateLogInfo("忽略升级版本 %s", params.Version)
if len(params.Version) == 0 {
this.Fail("请输入要忽略的版本号")
return
}
valueResp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeCheckUpdates})
if err != nil {
this.ErrorPage(err)
return
}
var valueJSON = valueResp.ValueJSON
var config = systemconfigs.NewCheckUpdatesConfig()
if len(valueJSON) > 0 {
err = json.Unmarshal(valueJSON, config)
if err != nil {
this.ErrorPage(err)
return
}
}
config.IgnoredVersion = params.Version
configJSON, err := json.Marshal(config)
if err != nil {
this.ErrorPage(err)
return
}
_, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{
Code: systemconfigs.SettingCodeCheckUpdates,
ValueJSON: configJSON,
})
if err != nil {
this.ErrorPage(err)
return
}
// 清除状态
teaconst.NewVersionCode = ""
this.Success()
}