From 0bbd178b29c63c5751ab9f2839c915731db89a89 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sun, 4 Oct 2020 20:38:27 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=9C=8D=E5=8A=A1=E7=9A=84?= =?UTF-8?q?=E7=BC=93=E5=AD=98=E7=AD=96=E7=95=A5=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/actions/actionutils/parent_action.go | 8 ++ .../servers/components/cache/createPopup.go | 10 +- .../default/servers/components/cache/index.go | 2 +- .../servers/components/cache/policy.go | 2 +- .../servers/components/cache/update.go | 10 +- .../server/settings/cache/createPopup.go | 81 +++++++++++++ .../servers/server/settings/cache/index.go | 42 +++---- .../servers/server/settings/cache/init.go | 1 + .../server/settings/locations/cache/index.go | 42 +++---- .../locationutils/location_helper.go | 2 +- .../servers/serverutils/server_helper.go | 2 +- internal/web/models/http_cache_policy_dao.go | 35 ++++++ .../common/more-options-indicator.js | 7 +- .../js/components/common/size-capacity-box.js | 11 +- .../js/components/common/time-duration-box.js | 16 ++- .../components/server/http-cache-cond-box.js | 50 -------- .../server/http-cache-config-box.js | 109 ++++++++++++++--- .../components/server/http-cache-ref-box.js | 110 ++++++++++++++++++ .../server/http-request-conds-box.js | 8 ++ .../server/http-request-conds-view.js | 45 +++++++ .../server/settings/cache/createPopup.html | 18 +++ .../server/settings/cache/createPopup.js | 17 +++ .../servers/server/settings/cache/index.html | 2 +- .../server/settings/conds/addGroupPopup.js | 3 + .../settings/locations/cache/index.html | 2 +- 25 files changed, 502 insertions(+), 133 deletions(-) create mode 100644 internal/web/actions/default/servers/server/settings/cache/createPopup.go create mode 100644 internal/web/models/http_cache_policy_dao.go delete mode 100644 web/public/js/components/server/http-cache-cond-box.js create mode 100644 web/public/js/components/server/http-cache-ref-box.js create mode 100644 web/public/js/components/server/http-request-conds-view.js create mode 100644 web/views/@default/servers/server/settings/cache/createPopup.html create mode 100644 web/views/@default/servers/server/settings/cache/createPopup.js diff --git a/internal/web/actions/actionutils/parent_action.go b/internal/web/actions/actionutils/parent_action.go index 8d02c70e..72c94d0c 100644 --- a/internal/web/actions/actionutils/parent_action.go +++ b/internal/web/actions/actionutils/parent_action.go @@ -113,5 +113,13 @@ func (this *ParentAction) RPC() *rpc.RPCClient { // 获取Context func (this *ParentAction) AdminContext() context.Context { + if this.rpcClient == nil { + rpcClient, err := rpc.SharedRPC() + if err != nil { + logs.Fatal(err) + return nil + } + this.rpcClient = rpcClient + } return this.rpcClient.Context(this.AdminId()) } diff --git a/internal/web/actions/default/servers/components/cache/createPopup.go b/internal/web/actions/default/servers/components/cache/createPopup.go index e26e10f5..3bb93b3d 100644 --- a/internal/web/actions/default/servers/components/cache/createPopup.go +++ b/internal/web/actions/default/servers/components/cache/createPopup.go @@ -17,7 +17,7 @@ func (this *CreatePopupAction) Init() { } func (this *CreatePopupAction) RunGet(params struct{}) { - this.Data["types"] = serverconfigs.AllCachePolicyTypes + this.Data["types"] = serverconfigs.AllCachePolicyStorageTypes this.Show() } @@ -44,15 +44,15 @@ func (this *CreatePopupAction) RunPost(params struct { // 校验选项 var options interface{} switch params.Type { - case serverconfigs.CachePolicyTypeFile: + case serverconfigs.CachePolicyStorageFile: params.Must. Field("fileDir", params.FileDir). Require("请输入缓存目录") - options = &serverconfigs.HTTPFileCacheConfig{ + options = &serverconfigs.HTTPFileCacheStorage{ Dir: params.FileDir, } - case serverconfigs.CachePolicyTypeMemory: - options = &serverconfigs.HTTPMemoryCacheConfig{ + case serverconfigs.CachePolicyStorageMemory: + options = &serverconfigs.HTTPMemoryCacheStorage{ } default: this.Fail("请选择正确的缓存类型") diff --git a/internal/web/actions/default/servers/components/cache/index.go b/internal/web/actions/default/servers/components/cache/index.go index 4fb286b4..d1024627 100644 --- a/internal/web/actions/default/servers/components/cache/index.go +++ b/internal/web/actions/default/servers/components/cache/index.go @@ -53,7 +53,7 @@ func (this *IndexAction) RunGet(params struct{}) { countServers := countServersResp.Count infos = append(infos, maps.Map{ - "typeName": serverconfigs.FindCachePolicyTypeName(cachePolicy.Type), + "typeName": serverconfigs.FindCachePolicyStorageName(cachePolicy.Type), "countServers": countServers, }) } diff --git a/internal/web/actions/default/servers/components/cache/policy.go b/internal/web/actions/default/servers/components/cache/policy.go index b298e044..14a1ef20 100644 --- a/internal/web/actions/default/servers/components/cache/policy.go +++ b/internal/web/actions/default/servers/components/cache/policy.go @@ -24,7 +24,7 @@ func (this *PolicyAction) RunGet(params struct { } this.Data["cachePolicy"] = cachePolicy - this.Data["typeName"] = serverconfigs.FindCachePolicyTypeName(cachePolicy.Type) + this.Data["typeName"] = serverconfigs.FindCachePolicyStorageName(cachePolicy.Type) this.Show() } diff --git a/internal/web/actions/default/servers/components/cache/update.go b/internal/web/actions/default/servers/components/cache/update.go index 69e1b966..7f49d6ed 100644 --- a/internal/web/actions/default/servers/components/cache/update.go +++ b/internal/web/actions/default/servers/components/cache/update.go @@ -39,7 +39,7 @@ func (this *UpdateAction) RunGet(params struct { this.Data["cachePolicy"] = cachePolicy // 其他选项 - this.Data["types"] = serverconfigs.AllCachePolicyTypes + this.Data["types"] = serverconfigs.AllCachePolicyStorageTypes this.Show() } @@ -69,15 +69,15 @@ func (this *UpdateAction) RunPost(params struct { // 校验选项 var options interface{} switch params.Type { - case serverconfigs.CachePolicyTypeFile: + case serverconfigs.CachePolicyStorageFile: params.Must. Field("fileDir", params.FileDir). Require("请输入缓存目录") - options = &serverconfigs.HTTPFileCacheConfig{ + options = &serverconfigs.HTTPFileCacheStorage{ Dir: params.FileDir, } - case serverconfigs.CachePolicyTypeMemory: - options = &serverconfigs.HTTPMemoryCacheConfig{ + case serverconfigs.CachePolicyStorageMemory: + options = &serverconfigs.HTTPMemoryCacheStorage{ } default: this.Fail("请选择正确的缓存类型") diff --git a/internal/web/actions/default/servers/server/settings/cache/createPopup.go b/internal/web/actions/default/servers/server/settings/cache/createPopup.go new file mode 100644 index 00000000..83333494 --- /dev/null +++ b/internal/web/actions/default/servers/server/settings/cache/createPopup.go @@ -0,0 +1,81 @@ +package cache + +import ( + "encoding/json" + "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" + "github.com/TeaOSLab/EdgeAdmin/internal/web/models" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" + "github.com/iwind/TeaGo/actions" + "github.com/iwind/TeaGo/maps" +) + +type CreatePopupAction struct { + actionutils.ParentAction +} + +func (this *CreatePopupAction) Init() { + this.Nav("", "", "") +} + +func (this *CreatePopupAction) RunGet(params struct{}) { + // 缓存策略列表 + cachePoliciesResp, err := this.RPC().HTTPCachePolicyRPC().FindAllEnabledHTTPCachePolicies(this.AdminContext(), &pb.FindAllEnabledHTTPCachePoliciesRequest{}) + if err != nil { + this.ErrorPage(err) + return + } + cachePolicyMaps := []maps.Map{} + for _, cachePolicy := range cachePoliciesResp.CachePolicies { + cachePolicyMaps = append(cachePolicyMaps, maps.Map{ + "id": cachePolicy.Id, + "name": cachePolicy.Name, + }) + } + this.Data["cachePolicies"] = cachePolicyMaps + + this.Show() +} + +func (this *CreatePopupAction) RunPost(params struct { + CachePolicyId int64 + CacheRefJSON []byte + + Must *actions.Must +}) { + if params.CachePolicyId <= 0 { + this.Fail("请选择要使用的缓存策略") + } + + cachePolicy, err := models.SharedHTTPCachePolicyDAO.FindEnabledCachePolicyConfig(this.AdminContext(), params.CachePolicyId) + if err != nil { + this.ErrorPage(err) + return + } + if cachePolicy == nil { + this.Fail("找不到你要使用的缓存策略") + } + + cacheRef := &serverconfigs.HTTPCacheRef{} + err = json.Unmarshal(params.CacheRefJSON, cacheRef) + if err != nil { + this.ErrorPage(err) + return + } + if len(cacheRef.Key) == 0 { + this.Fail("请输入缓存Key") + } + + cacheRef.CachePolicyId = cachePolicy.Id + cacheRef.CachePolicy = cachePolicy + + err = cacheRef.Init() + if err != nil { + this.ErrorPage(err) + return + } + + this.Data["cacheRef"] = cacheRef + + this.Success() +} diff --git a/internal/web/actions/default/servers/server/settings/cache/index.go b/internal/web/actions/default/servers/server/settings/cache/index.go index 454d74bf..4b5bd980 100644 --- a/internal/web/actions/default/servers/server/settings/cache/index.go +++ b/internal/web/actions/default/servers/server/settings/cache/index.go @@ -1,11 +1,12 @@ package cache import ( + "encoding/json" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils" "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 { @@ -27,23 +28,7 @@ func (this *IndexAction) RunGet(params struct { } this.Data["webId"] = webConfig.Id - this.Data["cacheConfig"] = webConfig.CacheRefs - - // 所有缓存策略 - 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.Data["cacheConfig"] = webConfig.Cache this.Show() } @@ -55,10 +40,27 @@ func (this *IndexAction) RunPost(params struct { Must *actions.Must }) { // TODO 校验配置 + cacheConfig := &serverconfigs.HTTPCacheConfig{} + err := json.Unmarshal(params.CacheJSON, cacheConfig) + if err != nil { + this.ErrorPage(err) + return + } - _, err := this.RPC().HTTPWebRPC().UpdateHTTPWebCache(this.AdminContext(), &pb.UpdateHTTPWebCacheRequest{ + // 去除不必要的部分 + for _, cacheRef := range cacheConfig.CacheRefs { + cacheRef.CachePolicy = nil + } + + cacheJSON, err := json.Marshal(cacheConfig) + if err != nil { + this.ErrorPage(err) + return + } + + _, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCache(this.AdminContext(), &pb.UpdateHTTPWebCacheRequest{ WebId: params.WebId, - CacheJSON: params.CacheJSON, + CacheJSON: cacheJSON, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/servers/server/settings/cache/init.go b/internal/web/actions/default/servers/server/settings/cache/init.go index 0fc44b11..a455096d 100644 --- a/internal/web/actions/default/servers/server/settings/cache/init.go +++ b/internal/web/actions/default/servers/server/settings/cache/init.go @@ -13,6 +13,7 @@ func init() { Helper(serverutils.NewServerHelper()). Prefix("/servers/server/settings/cache"). GetPost("", new(IndexAction)). + GetPost("/createPopup", new(CreatePopupAction)). EndAll() }) } diff --git a/internal/web/actions/default/servers/server/settings/locations/cache/index.go b/internal/web/actions/default/servers/server/settings/locations/cache/index.go index 122d514a..0acf09c9 100644 --- a/internal/web/actions/default/servers/server/settings/locations/cache/index.go +++ b/internal/web/actions/default/servers/server/settings/locations/cache/index.go @@ -1,11 +1,12 @@ package cache import ( + "encoding/json" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/server/settings/webutils" "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 { @@ -25,23 +26,7 @@ func (this *IndexAction) RunGet(params struct { } this.Data["webId"] = webConfig.Id - this.Data["cacheConfig"] = webConfig.CacheRefs - - // 所有缓存策略 - 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.Data["cacheConfig"] = webConfig.Cache this.Show() } @@ -53,10 +38,27 @@ func (this *IndexAction) RunPost(params struct { Must *actions.Must }) { // TODO 校验配置 + cacheConfig := &serverconfigs.HTTPCacheConfig{} + err := json.Unmarshal(params.CacheJSON, cacheConfig) + if err != nil { + this.ErrorPage(err) + return + } - _, err := this.RPC().HTTPWebRPC().UpdateHTTPWebCache(this.AdminContext(), &pb.UpdateHTTPWebCacheRequest{ + // 去除不必要的部分 + for _, cacheRef := range cacheConfig.CacheRefs { + cacheRef.CachePolicy = nil + } + + cacheJSON, err := json.Marshal(cacheConfig) + if err != nil { + this.ErrorPage(err) + return + } + + _, err = this.RPC().HTTPWebRPC().UpdateHTTPWebCache(this.AdminContext(), &pb.UpdateHTTPWebCacheRequest{ WebId: params.WebId, - CacheJSON: params.CacheJSON, + CacheJSON: cacheJSON, }) if err != nil { this.ErrorPage(err) diff --git a/internal/web/actions/default/servers/server/settings/locations/locationutils/location_helper.go b/internal/web/actions/default/servers/server/settings/locations/locationutils/location_helper.go index 532c23ae..4e8469e1 100644 --- a/internal/web/actions/default/servers/server/settings/locations/locationutils/location_helper.go +++ b/internal/web/actions/default/servers/server/settings/locations/locationutils/location_helper.go @@ -100,7 +100,7 @@ func (this *LocationHelper) createMenus(serverIdString string, locationIdString "name": "缓存", "url": "/servers/server/settings/locations/cache?serverId=" + serverIdString + "&locationId=" + locationIdString, "isActive": secondMenuItem == "cache", - "isOn": locationConfig != nil && locationConfig.Web != nil && len(locationConfig.Web.CacheRefs) > 0, + "isOn": locationConfig != nil && locationConfig.Web != nil && locationConfig.Web.Cache != nil && locationConfig.Web.Cache.IsOn && len(locationConfig.Web.Cache.CacheRefs) > 0, }) menuItems = append(menuItems, maps.Map{ "name": "访问控制", diff --git a/internal/web/actions/default/servers/serverutils/server_helper.go b/internal/web/actions/default/servers/serverutils/server_helper.go index 9096c6b6..4dbda08c 100644 --- a/internal/web/actions/default/servers/serverutils/server_helper.go +++ b/internal/web/actions/default/servers/serverutils/server_helper.go @@ -211,7 +211,7 @@ func (this *ServerHelper) createSettingsMenu(secondMenuItem string, serverIdStri "name": "缓存", "url": "/servers/server/settings/cache?serverId=" + serverIdString, "isActive": secondMenuItem == "cache", - "isOn": serverConfig.Web != nil && len(serverConfig.Web.CacheRefs) > 0, + "isOn": serverConfig.Web != nil && serverConfig.Web.Cache != nil && serverConfig.Web.Cache.IsOn && len(serverConfig.Web.Cache.CacheRefs) > 0, }) menuItems = append(menuItems, maps.Map{ "name": "访问控制", diff --git a/internal/web/models/http_cache_policy_dao.go b/internal/web/models/http_cache_policy_dao.go new file mode 100644 index 00000000..b2263409 --- /dev/null +++ b/internal/web/models/http_cache_policy_dao.go @@ -0,0 +1,35 @@ +package models + +import ( + "context" + "encoding/json" + "github.com/TeaOSLab/EdgeAdmin/internal/rpc" + "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" +) + +var SharedHTTPCachePolicyDAO = new(HTTPCachePolicyDAO) + +type HTTPCachePolicyDAO struct { +} + +// 查找缓存策略配置 +func (this *HTTPCachePolicyDAO) FindEnabledCachePolicyConfig(ctx context.Context, cachePolicyId int64) (*serverconfigs.HTTPCachePolicy, error) { + rpcClient, err := rpc.SharedRPC() + if err != nil { + return nil, err + } + resp, err := rpcClient.HTTPCachePolicyRPC().FindEnabledHTTPCachePolicyConfig(ctx, &pb.FindEnabledHTTPCachePolicyConfigRequest{CachePolicyId: cachePolicyId}) + if err != nil { + return nil, err + } + if len(resp.CachePolicyJSON) == 0 { + return nil, nil + } + config := &serverconfigs.HTTPCachePolicy{} + err = json.Unmarshal(resp.CachePolicyJSON, config) + if err != nil { + return nil, err + } + return config, nil +} diff --git a/web/public/js/components/common/more-options-indicator.js b/web/public/js/components/common/more-options-indicator.js index b7dd48f1..9c2c20df 100644 --- a/web/public/js/components/common/more-options-indicator.js +++ b/web/public/js/components/common/more-options-indicator.js @@ -5,14 +5,15 @@ Vue.component("more-options-indicator", { data: function () { return { visible: false - }; + } }, methods: { changeVisible: function () { - this.visible = !this.visible; + this.visible = !this.visible if (Tea.Vue != null) { - Tea.Vue.moreOptionsVisible = this.visible; + Tea.Vue.moreOptionsVisible = this.visible } + this.$emit("change", this.visible) } }, template: '更多选项收起选项 ' diff --git a/web/public/js/components/common/size-capacity-box.js b/web/public/js/components/common/size-capacity-box.js index 567b50b0..c912e03f 100644 --- a/web/public/js/components/common/size-capacity-box.js +++ b/web/public/js/components/common/size-capacity-box.js @@ -12,7 +12,7 @@ Vue.component("size-capacity-box", { v["count"] = -1 } return { - "size": v, + size: v, countString: (v.count >= 0) ? v.count.toString() : "" } }, @@ -21,12 +21,19 @@ Vue.component("size-capacity-box", { let value = newValue.trim() if (value.length == 0) { this.size.count = -1 + this.change() return } let count = parseInt(value) if (!isNaN(count)) { this.size.count = count } + this.change() + } + }, + methods: { + change: function () { + this.$emit("change", this.size) } }, template: `
@@ -35,7 +42,7 @@ Vue.component("size-capacity-box", {
- diff --git a/web/public/js/components/common/time-duration-box.js b/web/public/js/components/common/time-duration-box.js index b35e29f3..a9241d64 100644 --- a/web/public/js/components/common/time-duration-box.js +++ b/web/public/js/components/common/time-duration-box.js @@ -12,7 +12,7 @@ Vue.component("time-duration-box", { v["count"] = -1 } return { - "size": v, + duration: v, countString: (v.count >= 0) ? v.count.toString() : "" } }, @@ -20,22 +20,28 @@ Vue.component("time-duration-box", { "countString": function (newValue) { let value = newValue.trim() if (value.length == 0) { - this.size.count = -1 + this.duration.count = -1 return } let count = parseInt(value) if (!isNaN(count)) { - this.size.count = count + this.duration.count = count } + this.change() + } + }, + methods: { + change: function () { + this.$emit("change", this.duration) } }, template: `
- +
- diff --git a/web/public/js/components/server/http-cache-cond-box.js b/web/public/js/components/server/http-cache-cond-box.js deleted file mode 100644 index 408ee785..00000000 --- a/web/public/js/components/server/http-cache-cond-box.js +++ /dev/null @@ -1,50 +0,0 @@ -Vue.component("http-cache-cond-box", { - template: `
- - - - - - - - - - - - - - - - - - - - - - - - - -
匹配条件
缓存有效期 - -
状态码列表 - -

允许缓存的HTTP状态码列表。

-
跳过的Cache-Control值 - -

当响应的Cache-Control为这些值时不缓存响应内容,而且不区分大小写。

-
跳过Set-Cookie -
- - -
-

选中后,当响应的Header中有Set-Cookie时不缓存响应内容。

-
支持请求no-cache刷新 -
- - -
-

选中后,当请求的Header中含有Pragma: no-cache或Cache-Control: no-cache时,会跳过缓存直接读取源内容。

-
-
` -}) \ No newline at end of file diff --git a/web/public/js/components/server/http-cache-config-box.js b/web/public/js/components/server/http-cache-config-box.js index abbd2ed9..160131ed 100644 --- a/web/public/js/components/server/http-cache-config-box.js +++ b/web/public/js/components/server/http-cache-config-box.js @@ -6,7 +6,7 @@ Vue.component("http-cache-config-box", { cacheConfig = { isPrior: false, isOn: false, - cachePolicyId: 0 + cacheRefs: [] } } return { @@ -14,8 +14,71 @@ Vue.component("http-cache-config-box", { } }, methods: { - changePolicyId: function () { - this.cacheConfig.cachePolicyId = parseInt(this.cacheConfig.cachePolicyId) + isOn: function () { + return (!this.vIsLocation || this.cacheConfig.isPrior) && this.cacheConfig.isOn + }, + addRef: function () { + window.UPDATING_CACHE_REF = null + + let width = window.innerWidth + if (width > 1024) { + width = 1024 + } + let height = window.innerHeight + if (height > 500) { + height = 500 + } + let that = this + teaweb.popup("/servers/server/settings/cache/createPopup", { + width: width + "px", + height: height + "px", + callback: function (resp) { + that.cacheConfig.cacheRefs.push(resp.data.cacheRef) + } + }) + }, + updateRef: function (index, cacheRef) { + window.UPDATING_CACHE_REF = cacheRef + + let width = window.innerWidth + if (width > 1024) { + width = 1024 + } + let height = window.innerHeight + if (height > 500) { + height = 500 + } + let that = this + teaweb.popup("/servers/server/settings/cache/createPopup", { + width: width + "px", + height: height + "px", + callback: function (resp) { + Vue.set(that.cacheConfig.cacheRefs, index, resp.data.cacheRef) + } + }) + }, + removeRef: function (index) { + let that = this + teaweb.confirm("确定要删除此缓存设置吗?", function () { + that.cacheConfig.cacheRefs.$remove(index) + }) + }, + timeUnitName: function (unit) { + switch (unit) { + case "ms": + return "毫秒" + case "second": + return "秒" + case "minute": + return "分钟" + case "hour": + return "小时" + case "day": + return "天" + case "week": + return "周 " + } + return unit } }, template: `
@@ -33,21 +96,33 @@ Vue.component("http-cache-config-box", { - - - 选择缓存策略 - - 暂时没有可选的缓存策略 -
- -
- - - + +
+ + + + + + + + + + + + + + + +
缓存策略条件缓存时间操作
{{cacheRef.cachePolicy.name}} + + {{cacheRef.life.count}} {{timeUnitName(cacheRef.life.unit)}} + 修改   + 删除 +
+ + +
` }) \ No newline at end of file diff --git a/web/public/js/components/server/http-cache-ref-box.js b/web/public/js/components/server/http-cache-ref-box.js new file mode 100644 index 00000000..2010c6c7 --- /dev/null +++ b/web/public/js/components/server/http-cache-ref-box.js @@ -0,0 +1,110 @@ +Vue.component("http-cache-ref-box", { + props: ["v-cache-ref"], + data: function () { + let ref = this.vCacheRef + if (ref == null) { + ref = { + isOn: true, + cachePolicyId: 0, + key: "${scheme}://${host}${requestURI}", + life: {count: 2, unit: "hour"}, + status: [200], + maxSize: {count: 32, unit: "mb"}, + skipCacheControlValues: ["private", "no-cache", "no-store"], + skipSetCookie: true, + enableRequestCachePragma: false, + conds: null + } + } + if (ref.life == null) { + ref.life = {count: 2, unit: "hour"} + } + if (ref.maxSize == null) { + ref.maxSize = {count: 32, unit: "mb"} + } + return { + ref: ref, + moreOptionsVisible: false + } + }, + methods: { + changeOptionsVisible: function (v) { + this.moreOptionsVisible = v + }, + changeLife: function (v) { + this.ref.life = v + }, + changeMaxSize: function (v) { + this.ref.maxSize = v + }, + changeConds: function (v) { + this.ref.conds = v + } + }, + template: ` + + 匹配条件 * + + + + + + + + 缓存有效期 * + + + + + + 缓存Key * + + +

用来区分不同缓存内容的唯一Key。

+ + + + + + + 可缓存的最大文件 + + + + + + 状态码列表 + + +

允许缓存的HTTP状态码列表。

+ + + + 跳过的Cache-Control值 + + +

当响应的Cache-Control为这些值时不缓存响应内容,而且不区分大小写。

+ + + + 跳过Set-Cookie + +
+ + +
+

选中后,当响应的Header中有Set-Cookie时不缓存响应内容。

+ + + + 支持请求no-cache刷新 + +
+ + +
+

选中后,当请求的Header中含有Pragma: no-cache或Cache-Control: no-cache时,会跳过缓存直接读取源内容。

+ + +` +}) \ No newline at end of file diff --git a/web/public/js/components/server/http-request-conds-box.js b/web/public/js/components/server/http-request-conds-box.js index 095ac6dd..3bad07d0 100644 --- a/web/public/js/components/server/http-request-conds-box.js +++ b/web/public/js/components/server/http-request-conds-box.js @@ -15,12 +15,18 @@ Vue.component("http-request-conds-box", { } }, methods: { + change: function () { + this.$emit("change", this.conds) + }, addGroup: function () { + window.UPDATING_COND_GROUP = null + let that = this teaweb.popup("/servers/server/settings/conds/addGroupPopup", { height: "30em", callback: function (resp) { that.conds.groups.push(resp.data.group) + that.change() } }) }, @@ -31,6 +37,7 @@ Vue.component("http-request-conds-box", { height: "30em", callback: function (resp) { Vue.set(that.conds.groups, groupIndex, resp.data.group) + that.change() } }) }, @@ -38,6 +45,7 @@ Vue.component("http-request-conds-box", { let that = this teaweb.confirm("确定要删除这一组条件吗?", function () { that.conds.groups.$remove(groupIndex) + that.change() }) }, typeName: function (cond) { diff --git a/web/public/js/components/server/http-request-conds-view.js b/web/public/js/components/server/http-request-conds-view.js new file mode 100644 index 00000000..0fc40e83 --- /dev/null +++ b/web/public/js/components/server/http-request-conds-view.js @@ -0,0 +1,45 @@ +Vue.component("http-request-conds-view", { + props: ["v-conds"], + data: function () { + let conds = this.vConds + if (conds == null) { + conds = { + isOn: true, + connector: "or", + groups: [] + } + } + return { + conds: conds, + components: window.REQUEST_COND_COMPONENTS + } + }, + methods: { + typeName: function (cond) { + let c = this.components.$find(function (k, v) { + return v.type == cond.type + }) + if (c != null) { + return c.name; + } + return cond.param + " " + cond.operator + } + }, + template: `
+
+
+ + + {{cond.param}} {{cond.operator}} + {{typeName(cond)}}: + {{cond.value}} + + + {{group.connector}}   + +
+
+
+
+
` +}) \ No newline at end of file diff --git a/web/views/@default/servers/server/settings/cache/createPopup.html b/web/views/@default/servers/server/settings/cache/createPopup.html new file mode 100644 index 00000000..25912436 --- /dev/null +++ b/web/views/@default/servers/server/settings/cache/createPopup.html @@ -0,0 +1,18 @@ +{$layout "layout_popup"} + +

添加缓存设置

+ +
+ + + + + + +
缓存策略 * + +
+ +
\ No newline at end of file diff --git a/web/views/@default/servers/server/settings/cache/createPopup.js b/web/views/@default/servers/server/settings/cache/createPopup.js new file mode 100644 index 00000000..8f26d615 --- /dev/null +++ b/web/views/@default/servers/server/settings/cache/createPopup.js @@ -0,0 +1,17 @@ +Tea.context(function () { + this.success = NotifyPopup + this.cacheRef = null + + let cachePolicyId = 0 + if (this.cachePolicies.length > 0) { + cachePolicyId = this.cachePolicies[0].id + } + if (window.parent.UPDATING_CACHE_REF != null) { + let cacheRef = window.parent.UPDATING_CACHE_REF + this.cacheRef = cacheRef + if (cacheRef.cachePolicy != null) { + cachePolicyId = cacheRef.cachePolicy.id + } + } + this.cachePolicyId = cachePolicyId +}) \ No newline at end of file diff --git a/web/views/@default/servers/server/settings/cache/index.html b/web/views/@default/servers/server/settings/cache/index.html index 12131205..42421d23 100644 --- a/web/views/@default/servers/server/settings/cache/index.html +++ b/web/views/@default/servers/server/settings/cache/index.html @@ -5,7 +5,7 @@
- +
\ No newline at end of file diff --git a/web/views/@default/servers/server/settings/conds/addGroupPopup.js b/web/views/@default/servers/server/settings/conds/addGroupPopup.js index 7566fe14..60c9ee53 100644 --- a/web/views/@default/servers/server/settings/conds/addGroupPopup.js +++ b/web/views/@default/servers/server/settings/conds/addGroupPopup.js @@ -13,6 +13,9 @@ Tea.context(function () { this.$delay(function () { if (window.parent.UPDATING_COND_GROUP != null) { this.group = window.parent.UPDATING_COND_GROUP + } else if (this.group.conds.length == 0) { + // 如果尚未有条件,则自动弹出添加界面 + this.addCond() } }) diff --git a/web/views/@default/servers/server/settings/locations/cache/index.html b/web/views/@default/servers/server/settings/locations/cache/index.html index da8ea9dd..55a6d5e5 100644 --- a/web/views/@default/servers/server/settings/locations/cache/index.html +++ b/web/views/@default/servers/server/settings/locations/cache/index.html @@ -9,7 +9,7 @@
- +