mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-09 08:40:26 +08:00
实现修改缓存配置
This commit is contained in:
@@ -33,6 +33,7 @@ type RPCClient struct {
|
|||||||
httpHeaderClients []pb.HTTPHeaderServiceClient
|
httpHeaderClients []pb.HTTPHeaderServiceClient
|
||||||
httpPageClients []pb.HTTPPageServiceClient
|
httpPageClients []pb.HTTPPageServiceClient
|
||||||
httpAccessLogPolicyClients []pb.HTTPAccessLogPolicyServiceClient
|
httpAccessLogPolicyClients []pb.HTTPAccessLogPolicyServiceClient
|
||||||
|
httpCachePolicyClients []pb.HTTPCachePolicyServiceClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
|
func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
|
||||||
@@ -55,6 +56,7 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
|
|||||||
httpHeaderClients := []pb.HTTPHeaderServiceClient{}
|
httpHeaderClients := []pb.HTTPHeaderServiceClient{}
|
||||||
httpPageClients := []pb.HTTPPageServiceClient{}
|
httpPageClients := []pb.HTTPPageServiceClient{}
|
||||||
httpAccessLogPolicyClients := []pb.HTTPAccessLogPolicyServiceClient{}
|
httpAccessLogPolicyClients := []pb.HTTPAccessLogPolicyServiceClient{}
|
||||||
|
httpCachePolicyClients := []pb.HTTPCachePolicyServiceClient{}
|
||||||
|
|
||||||
conns := []*grpc.ClientConn{}
|
conns := []*grpc.ClientConn{}
|
||||||
for _, endpoint := range apiConfig.RPC.Endpoints {
|
for _, endpoint := range apiConfig.RPC.Endpoints {
|
||||||
@@ -85,6 +87,7 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
|
|||||||
httpHeaderClients = append(httpHeaderClients, pb.NewHTTPHeaderServiceClient(conn))
|
httpHeaderClients = append(httpHeaderClients, pb.NewHTTPHeaderServiceClient(conn))
|
||||||
httpPageClients = append(httpPageClients, pb.NewHTTPPageServiceClient(conn))
|
httpPageClients = append(httpPageClients, pb.NewHTTPPageServiceClient(conn))
|
||||||
httpAccessLogPolicyClients = append(httpAccessLogPolicyClients, pb.NewHTTPAccessLogPolicyServiceClient(conn))
|
httpAccessLogPolicyClients = append(httpAccessLogPolicyClients, pb.NewHTTPAccessLogPolicyServiceClient(conn))
|
||||||
|
httpCachePolicyClients = append(httpCachePolicyClients, pb.NewHTTPCachePolicyServiceClient(conn))
|
||||||
}
|
}
|
||||||
|
|
||||||
return &RPCClient{
|
return &RPCClient{
|
||||||
@@ -104,6 +107,7 @@ func NewRPCClient(apiConfig *configs.APIConfig) (*RPCClient, error) {
|
|||||||
httpHeaderClients: httpHeaderClients,
|
httpHeaderClients: httpHeaderClients,
|
||||||
httpPageClients: httpPageClients,
|
httpPageClients: httpPageClients,
|
||||||
httpAccessLogPolicyClients: httpAccessLogPolicyClients,
|
httpAccessLogPolicyClients: httpAccessLogPolicyClients,
|
||||||
|
httpCachePolicyClients: httpCachePolicyClients,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,6 +216,13 @@ func (this *RPCClient) HTTPAccessLogPolicyRPC() pb.HTTPAccessLogPolicyServiceCli
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *RPCClient) HTTPCachePolicyRPC() pb.HTTPCachePolicyServiceClient {
|
||||||
|
if len(this.httpCachePolicyClients) > 0 {
|
||||||
|
return this.httpCachePolicyClients[rands.Int(0, len(this.httpCachePolicyClients)-1)]
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (this *RPCClient) Context(adminId int64) context.Context {
|
func (this *RPCClient) Context(adminId int64) context.Context {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
m := maps.Map{
|
m := maps.Map{
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.Data["webId"] = webConfig.Id
|
this.Data["webId"] = webConfig.Id
|
||||||
this.Data["accessLogConfig"] = webConfig.AccessLog
|
this.Data["accessLogConfig"] = webConfig.AccessLogRef
|
||||||
|
|
||||||
// 可选的缓存策略
|
// 可选的缓存策略
|
||||||
policiesResp, err := this.RPC().HTTPAccessLogPolicyRPC().FindAllEnabledHTTPAccessLogPolicies(this.AdminContext(), &pb.FindAllEnabledHTTPAccessLogPoliciesRequest{})
|
policiesResp, err := this.RPC().HTTPAccessLogPolicyRPC().FindAllEnabledHTTPAccessLogPolicies(this.AdminContext(), &pb.FindAllEnabledHTTPAccessLogPoliciesRequest{})
|
||||||
|
|||||||
@@ -1,7 +1,12 @@
|
|||||||
package cache
|
package cache
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
|
"github.com/iwind/TeaGo/actions"
|
||||||
|
"github.com/iwind/TeaGo/maps"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IndexAction struct {
|
type IndexAction struct {
|
||||||
@@ -16,7 +21,56 @@ func (this *IndexAction) Init() {
|
|||||||
func (this *IndexAction) RunGet(params struct {
|
func (this *IndexAction) RunGet(params struct {
|
||||||
ServerId int64
|
ServerId int64
|
||||||
}) {
|
}) {
|
||||||
// TODO
|
webConfigResp, err := this.RPC().ServerRPC().FindAndInitServerWebConfig(this.AdminContext(), &pb.FindAndInitServerWebRequest{ServerId: params.ServerId})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
webConfig := &serverconfigs.HTTPWebConfig{}
|
||||||
|
err = json.Unmarshal(webConfigResp.Config, webConfig)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Data["webId"] = webConfig.Id
|
||||||
|
this.Data["cacheConfig"] = webConfig.CacheRef
|
||||||
|
|
||||||
|
// 所有缓存策略
|
||||||
|
cachePoliciesResp, err := this.RPC().HTTPCachePolicyRPC().FindAllEnabledHTTPCachePolicies(this.AdminContext(), &pb.FindAllEnabledHTTPCachePoliciesRequest{})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
policyMaps := []maps.Map{}
|
||||||
|
for _, policy := range cachePoliciesResp.CachePolicies {
|
||||||
|
policyMaps = append(policyMaps, maps.Map{
|
||||||
|
"id": policy.Id,
|
||||||
|
"name": policy.Name,
|
||||||
|
"isOn": policy.IsOn,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.Data["policies"] = policyMaps
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *IndexAction) RunPost(params struct {
|
||||||
|
WebId int64
|
||||||
|
CacheJSON []byte
|
||||||
|
|
||||||
|
Must *actions.Must
|
||||||
|
}) {
|
||||||
|
// TODO 校验配置
|
||||||
|
|
||||||
|
_, err := this.RPC().HTTPWebRPC().UpdateHTTPCache(this.AdminContext(), &pb.UpdateHTTPCacheRequest{
|
||||||
|
WebId: params.WebId,
|
||||||
|
CacheJSON: params.CacheJSON,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Success()
|
||||||
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ func init() {
|
|||||||
Helper(helpers.NewUserMustAuth()).
|
Helper(helpers.NewUserMustAuth()).
|
||||||
Helper(serverutils.NewServerHelper()).
|
Helper(serverutils.NewServerHelper()).
|
||||||
Prefix("/servers/server/settings/cache").
|
Prefix("/servers/server/settings/cache").
|
||||||
Get("", new(IndexAction)).
|
GetPost("", new(IndexAction)).
|
||||||
EndAll()
|
EndAll()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||||
"github.com/iwind/TeaGo/actions"
|
"github.com/iwind/TeaGo/actions"
|
||||||
|
"github.com/iwind/TeaGo/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IndexAction struct {
|
type IndexAction struct {
|
||||||
@@ -32,16 +33,12 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
webResp, err := this.RPC().HTTPWebRPC().FindEnabledHTTPWeb(this.AdminContext(), &pb.FindEnabledHTTPWebRequest{WebId: webConfig.Id})
|
|
||||||
if err != nil {
|
|
||||||
this.ErrorPage(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
web := webResp.Web
|
|
||||||
|
|
||||||
this.Data["webId"] = webConfig.Id
|
this.Data["webId"] = webConfig.Id
|
||||||
|
|
||||||
gzipId := web.GzipId
|
gzipId := int64(0)
|
||||||
|
if webConfig.GzipRef != nil {
|
||||||
|
gzipId = webConfig.GzipRef.GzipId
|
||||||
|
}
|
||||||
gzipConfig := &serverconfigs.HTTPGzipConfig{
|
gzipConfig := &serverconfigs.HTTPGzipConfig{
|
||||||
Id: 0,
|
Id: 0,
|
||||||
IsOn: true,
|
IsOn: true,
|
||||||
@@ -95,11 +92,10 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if params.GzipId > 0 {
|
if params.GzipId > 0 {
|
||||||
_, err := this.RPC().HTTPGzipRPC().UpdateHTTPGzip(this.AdminContext(), &pb.UpdateHTTPGzipRequest{
|
_, err := this.RPC().HTTPGzipRPC().UpdateHTTPGzip(this.AdminContext(), &pb.UpdateHTTPGzipRequest{
|
||||||
GzipId: params.GzipId,
|
GzipId: params.GzipId,
|
||||||
Level: int32(params.Level),
|
Level: types.Int32(params.Level),
|
||||||
MinLength: minLength,
|
MinLength: minLength,
|
||||||
MaxLength: maxLength,
|
MaxLength: maxLength,
|
||||||
})
|
})
|
||||||
@@ -109,9 +105,9 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
resp, err := this.RPC().HTTPGzipRPC().CreateHTTPGzip(this.AdminContext(), &pb.CreateHTTPGzipRequest{
|
resp, err := this.RPC().HTTPGzipRPC().CreateHTTPGzip(this.AdminContext(), &pb.CreateHTTPGzipRequest{
|
||||||
Level: 0,
|
Level: types.Int32(params.Level),
|
||||||
MinLength: nil,
|
MinLength: minLength,
|
||||||
MaxLength: nil,
|
MaxLength: maxLength,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
@@ -119,9 +115,19 @@ func (this *IndexAction) RunPost(params struct {
|
|||||||
}
|
}
|
||||||
gzipId := resp.GzipId
|
gzipId := resp.GzipId
|
||||||
|
|
||||||
|
gzipRef := &serverconfigs.HTTPGzipRef{
|
||||||
|
IsOn: true,
|
||||||
|
GzipId: gzipId,
|
||||||
|
}
|
||||||
|
gzipRefJSON, err := json.Marshal(gzipRef)
|
||||||
|
if err != nil {
|
||||||
|
this.ErrorPage(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebGzip(this.AdminContext(), &pb.UpdateHTTPWebGzipRequest{
|
_, err = this.RPC().HTTPWebRPC().UpdateHTTPWebGzip(this.AdminContext(), &pb.UpdateHTTPWebGzipRequest{
|
||||||
WebId: params.WebId,
|
WebId: params.WebId,
|
||||||
GzipId: gzipId,
|
GzipJSON: gzipRefJSON,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
this.ErrorPage(err)
|
this.ErrorPage(err)
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func (this *IndexAction) RunGet(params struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.Data["webId"] = webConfig.Id
|
this.Data["webId"] = webConfig.Id
|
||||||
this.Data["statConfig"] = webConfig.Stat
|
this.Data["statConfig"] = webConfig.StatRef
|
||||||
|
|
||||||
this.Show()
|
this.Show()
|
||||||
}
|
}
|
||||||
|
|||||||
46
web/public/js/components/server/http-cache-config-box.js
Normal file
46
web/public/js/components/server/http-cache-config-box.js
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
Vue.component("http-cache-config-box", {
|
||||||
|
props: ["v-cache-config", "v-cache-policies"],
|
||||||
|
data: function () {
|
||||||
|
let cacheConfig = this.vCacheConfig
|
||||||
|
if (cacheConfig == null) {
|
||||||
|
cacheConfig = {
|
||||||
|
isOn: false,
|
||||||
|
cachePolicyId: 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
cacheConfig: cacheConfig
|
||||||
|
}
|
||||||
|
},
|
||||||
|
template: `<div>
|
||||||
|
<input type="hidden" name="cacheJSON" :value="JSON.stringify(cacheConfig)"/>
|
||||||
|
<table class="ui table definition selectable">
|
||||||
|
<tbody>
|
||||||
|
<tr>
|
||||||
|
<td class="title">是否开启缓存</td>
|
||||||
|
<td>
|
||||||
|
<div class="ui checkbox">
|
||||||
|
<input type="checkbox" v-model="cacheConfig.isOn"/>
|
||||||
|
<label></label>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
<tbody v-show="cacheConfig.isOn">
|
||||||
|
<tr>
|
||||||
|
<td class="title">选择缓存策略</td>
|
||||||
|
<td>
|
||||||
|
<span class="disabled" v-if="vCachePolicies.length == 0">暂时没有可选的缓存策略</span>
|
||||||
|
<div v-if="vCachePolicies.length > 0">
|
||||||
|
<select class="ui dropdown auto-width" v-model="cacheConfig.cachePolicyId">
|
||||||
|
<option value="0">[不使用缓存策略]</option>
|
||||||
|
<option v-for="policy in vCachePolicies" :value="policy.id">{{policy.name}}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
<div class="margin"></div>
|
||||||
|
</div>`
|
||||||
|
})
|
||||||
@@ -3,5 +3,9 @@
|
|||||||
{$template "/left_menu"}
|
{$template "/left_menu"}
|
||||||
|
|
||||||
<div class="right-box">
|
<div class="right-box">
|
||||||
<p class="ui message">此功能暂未开放,敬请期待。</p>
|
<form class="ui form" data-tea-action="$" data-tea-success="success">
|
||||||
|
<input type="hidden" name="webId" :value="webId"/>
|
||||||
|
<http-cache-config-box :v-cache-config="cacheConfig" :v-cache-policies="policies"></http-cache-config-box>
|
||||||
|
<submit-btn></submit-btn>
|
||||||
|
</form>
|
||||||
</div>
|
</div>
|
||||||
3
web/views/@default/servers/server/settings/cache/index.js
vendored
Normal file
3
web/views/@default/servers/server/settings/cache/index.js
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
Tea.context(function () {
|
||||||
|
this.success = NotifyReloadSuccess("保存成功")
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user