diff --git a/internal/web/actions/default/clusters/cluster/node/settings/cache/index.go b/internal/web/actions/default/clusters/cluster/node/settings/cache/index.go index bc493651..0c98ef5a 100644 --- a/internal/web/actions/default/clusters/cluster/node/settings/cache/index.go +++ b/internal/web/actions/default/clusters/cluster/node/settings/cache/index.go @@ -7,6 +7,7 @@ import ( "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils" "github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/clusters/cluster/node/nodeutils" "github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb" + "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs" "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" "github.com/iwind/TeaGo/actions" "github.com/iwind/TeaGo/maps" @@ -57,9 +58,19 @@ func (this *IndexAction) RunGet(params struct { } } + var diskSubDirs = []*serverconfigs.CacheDir{} + if len(node.CacheDiskSubDirsJSON) > 0 { + err = json.Unmarshal(node.CacheDiskSubDirsJSON, &diskSubDirs) + if err != nil { + this.ErrorPage(err) + return + } + } + var nodeMap = this.Data["node"].(maps.Map) nodeMap["maxCacheDiskCapacity"] = maxCacheDiskCapacity nodeMap["cacheDiskDir"] = node.CacheDiskDir + nodeMap["cacheDiskSubDirs"] = diskSubDirs nodeMap["maxCacheMemoryCapacity"] = maxCacheMemoryCapacity this.Show() @@ -69,6 +80,7 @@ func (this *IndexAction) RunPost(params struct { NodeId int64 MaxCacheDiskCapacityJSON []byte CacheDiskDir string + CacheDiskSubDirsJSON []byte MaxCacheMemoryCapacityJSON []byte Must *actions.Must @@ -105,10 +117,20 @@ func (this *IndexAction) RunPost(params struct { } } + if len(params.CacheDiskSubDirsJSON) > 0 { + var cacheSubDirs = []*serverconfigs.CacheDir{} + err := json.Unmarshal(params.CacheDiskSubDirsJSON, &cacheSubDirs) + if err != nil { + this.ErrorPage(err) + return + } + } + _, err := this.RPC().NodeRPC().UpdateNodeCache(this.AdminContext(), &pb.UpdateNodeCacheRequest{ NodeId: params.NodeId, MaxCacheDiskCapacity: pbMaxCacheDiskCapacity, CacheDiskDir: params.CacheDiskDir, + CacheDiskSubDirsJSON: params.CacheDiskSubDirsJSON, MaxCacheMemoryCapacity: pbMaxCacheMemoryCapacity, }) if err != nil { diff --git a/web/public/js/components/node/node-cache-disk-dirs-box.js b/web/public/js/components/node/node-cache-disk-dirs-box.js new file mode 100644 index 00000000..9c8a594a --- /dev/null +++ b/web/public/js/components/node/node-cache-disk-dirs-box.js @@ -0,0 +1,79 @@ +Vue.component("node-cache-disk-dirs-box", { + props: ["value", "name"], + data: function () { + let dirs = this.value + if (dirs == null) { + dirs = [] + } + return { + dirs: dirs, + + isEditing: false, + isAdding: false, + + addingPath: "" + } + }, + methods: { + add: function () { + this.isAdding = true + let that = this + setTimeout(function () { + that.$refs.addingPath.focus() + }, 100) + }, + confirm: function () { + let addingPath = this.addingPath.trim() + if (addingPath.length == 0) { + let that = this + teaweb.warn("请输入要添加的缓存目录", function () { + that.$refs.addingPath.focus() + }) + return + } + if (addingPath[0] != "/") { + addingPath = "/" + addingPath + } + this.dirs.push({ + path: addingPath + }) + this.cancel() + }, + cancel: function () { + this.addingPath = "" + this.isAdding = false + this.isEditing = false + }, + remove: function (index) { + let that = this + teaweb.confirm("确定要删除此目录吗?", function () { + that.dirs.$remove(index) + }) + } + }, + template: `
+ +
+ + {{dir.path}}   + +
+ + +
+
+
+ +
+
+ +   +
+
+
+ +
+ +
+
` +}) \ No newline at end of file diff --git a/web/views/@default/clusters/cluster/node/settings/cache/index.html b/web/views/@default/clusters/cluster/node/settings/cache/index.html index 13000dce..3fdc2d9d 100644 --- a/web/views/@default/clusters/cluster/node/settings/cache/index.html +++ b/web/views/@default/clusters/cluster/node/settings/cache/index.html @@ -15,10 +15,17 @@ - 磁盘缓存目录 + 磁盘缓存主目录 -

存放文件缓存的目录,通常填写绝对路径。不填则表示使用集群缓存策略中定义的目录。

+

存放文件缓存的主目录,通常填写绝对路径。不填则表示使用集群缓存策略中定义的目录。

+ + + + 其他磁盘缓存目录 + + +

除了主目录外,可以在这里添加别的可用于缓存的目录;缓存目录有变更时(添加、删除或修改)需要手动将这些缓存目录清空。