mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-03 20:40:26 +08:00
64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
|
|
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 UpdateAction struct {
|
|
actionutils.ParentAction
|
|
}
|
|
|
|
func (this *UpdateAction) RunPost(params struct {
|
|
AutoCheck bool
|
|
}) {
|
|
defer this.CreateLogInfo("修改检查更新设置")
|
|
|
|
// 读取当前设置
|
|
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.AutoCheck = params.AutoCheck
|
|
|
|
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
|
|
}
|
|
|
|
// 重置状态
|
|
if !config.AutoCheck {
|
|
teaconst.NewVersionCode = ""
|
|
teaconst.NewVersionDownloadURL = ""
|
|
}
|
|
|
|
this.Success()
|
|
}
|