// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. //go:build plus package setting import ( "encoding/json" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" "github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/userconfigs" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" ) type ServerAction struct { actionutils.ParentAction } func (this *ServerAction) Init() { this.Nav("", "", "server") } func (this *ServerAction) RunGet(params struct{}) { // 当前配置 resp, err := this.RPC().SysSettingRPC().ReadSysSetting(this.AdminContext(), &pb.ReadSysSettingRequest{Code: systemconfigs.SettingCodeUserServerConfig}) if err != nil { this.ErrorPage(err) return } var config = userconfigs.DefaultUserServerConfig() if len(resp.ValueJSON) > 0 { err = json.Unmarshal(resp.ValueJSON, config) if err != nil { this.ErrorPage(err) return } } this.Data["config"] = config // 分组 groupsResp, err := this.RPC().ServerGroupRPC().FindAllEnabledServerGroups(this.AdminContext(), &pb.FindAllEnabledServerGroupsRequest{}) if err != nil { this.ErrorPage(err) return } var groupMaps = []maps.Map{} for _, group := range groupsResp.ServerGroups { groupMaps = append(groupMaps, maps.Map{ "id": group.Id, "name": group.Name, }) } this.Data["groups"] = groupMaps // 缓存 this.Data["defaultMaxCacheKeysPerTask"] = userconfigs.MaxCacheKeysPerTask this.Data["defaultMaxCacheKeysPerDay"] = userconfigs.MaxCacheKeysPerDay this.Show() } func (this *ServerAction) RunPost(params struct { GroupId int64 RequirePlan bool EnableStat bool // 缓存相关 PurgeMaxKeysPerTask int32 PurgeMaxKeysPerDay int32 FetchMaxKeysPerTask int32 FetchMaxKeysPerDay int32 Must *actions.Must CSRF *actionutils.CSRF }) { var config = userconfigs.DefaultUserServerConfig() config.GroupId = params.GroupId config.RequirePlan = params.RequirePlan config.EnableStat = params.EnableStat if config.HTTPCacheTaskPurgeConfig != nil { config.HTTPCacheTaskPurgeConfig.MaxKeysPerTask = params.PurgeMaxKeysPerTask config.HTTPCacheTaskPurgeConfig.MaxKeysPerDay = params.PurgeMaxKeysPerDay } if config.HTTPCacheTaskFetchConfig != nil { config.HTTPCacheTaskFetchConfig.MaxKeysPerTask = params.FetchMaxKeysPerTask config.HTTPCacheTaskFetchConfig.MaxKeysPerDay = params.FetchMaxKeysPerDay } configJSON, err := json.Marshal(config) if err != nil { this.ErrorPage(err) return } _, err = this.RPC().SysSettingRPC().UpdateSysSetting(this.AdminContext(), &pb.UpdateSysSettingRequest{ Code: systemconfigs.SettingCodeUserServerConfig, ValueJSON: configJSON, }) if err != nil { this.ErrorPage(err) return } this.Success() }