集群可以单独设置WebP策略

This commit is contained in:
刘祥超
2022-04-01 16:42:08 +08:00
parent 53b1f07601
commit 8076fcd148
9 changed files with 188 additions and 7 deletions

View File

@@ -5,6 +5,7 @@ package webp
import (
"encoding/json"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/dao"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
@@ -44,6 +45,25 @@ func (this *IndexAction) RunGet(params struct {
this.Data["webId"] = webConfig.Id
this.Data["webpConfig"] = webConfig.WebP
// WebP策略配置
var serverMap = this.Data.GetMap("server")
var clusterId = serverMap.GetInt64("clusterId")
webpPolicyResp, err := this.RPC().NodeClusterRPC().FindEnabledNodeClusterWebPPolicy(this.AdminContext(), &pb.FindEnabledNodeClusterWebPPolicyRequest{NodeClusterId: clusterId})
if err != nil {
this.ErrorPage(err)
return
}
this.Data["requireCache"] = true
if len(webpPolicyResp.WebpPolicyJSON) > 0 {
var webpPolicy = &nodeconfigs.WebPImagePolicy{}
err = json.Unmarshal(webpPolicyResp.WebpPolicyJSON, webpPolicy)
if err != nil {
this.ErrorPage(err)
return
}
this.Data["requireCache"] = webpPolicy.RequireCache
}
this.Show()
}

View File

@@ -62,7 +62,7 @@ func (this *ServerHelper) createLeftMenu(action *actions.ActionObject) {
logs.Error(err)
return
}
server := serverResp.Server
var server = serverResp.Server
if server == nil {
logs.Error(errors.New("can not find the server"))
return
@@ -70,11 +70,18 @@ func (this *ServerHelper) createLeftMenu(action *actions.ActionObject) {
// 初始化数据
if !action.Data.Has("server") {
action.Data["server"] = maps.Map{"id": server.Id, "name": server.Name}
if server.NodeCluster == nil {
server.NodeCluster = &pb.NodeCluster{Id: 0}
}
action.Data["server"] = maps.Map{
"id": server.Id,
"name": server.Name,
"clusterId": server.NodeCluster.Id,
}
}
// 服务管理
serverConfig := &serverconfigs.ServerConfig{}
var serverConfig = &serverconfigs.ServerConfig{}
err = json.Unmarshal(server.Config, serverConfig)
if err != nil {
logs.Error(err)