From b7df22c7459957fb434ff6c4b03a46a8ab577b85 Mon Sep 17 00:00:00 2001 From: lannoy0523 <935275025@qq.com> Date: Tue, 23 Apr 2024 18:09:43 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BC=93=E5=AD=98=E9=A2=9D=E5=A4=96?= =?UTF-8?q?=E4=BF=9D=E7=95=99=E9=85=8D=E7=BD=AE=E6=94=AF=E6=8C=81=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E5=90=8E=E7=BC=80=20#2002?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../file/BasedRepositoryFileExpireResolver.kt | 16 ++- .../bkrepo/job/pojo/FileCacheRequest.kt | 2 + .../com/tencent/bkrepo/job/pojo/TFileCache.kt | 2 + .../job/service/impl/FileCacheServiceImp.kt | 2 + .../devops-op/src/views/node/FileCache.vue | 20 +++- .../CreateOrUpdateFileCacheDialog.vue | 97 ++++++++++++++----- 6 files changed, 108 insertions(+), 31 deletions(-) diff --git a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/file/BasedRepositoryFileExpireResolver.kt b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/file/BasedRepositoryFileExpireResolver.kt index ced47175ee..8573da1ded 100644 --- a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/file/BasedRepositoryFileExpireResolver.kt +++ b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/batch/file/BasedRepositoryFileExpireResolver.kt @@ -93,13 +93,25 @@ class BasedRepositoryFileExpireResolver( // 获取每个的sha256 val sha256 = ret[SHA256].toString() val fullPath = ret[FULL_PATH].toString() - temp.add(sha256) - logger.info("Retain node $projectId/$repoName$fullPath, $sha256.") + var fileExtensionCheck = true + it.fileExtension?.let { fileExtensionCheck = checkFileExtension(it, fullPath) } + if (fileExtensionCheck) { + temp.add(sha256) + logger.info("Retain node $projectId/$repoName$fullPath, $sha256.") + } } } return temp } + private fun checkFileExtension(fileExtension: List , fullPath: String ) : Boolean { + var fileExtensionCheck = true + if (!fileExtension.contains("/") && !fileExtension.any { fullPath.endsWith(it) }) { + fileExtensionCheck = false + } + return fileExtensionCheck + } + private fun convertRepoConfigToFileCache(repoConfig: RepoConfig):TFileCache { return TFileCache( id = null, diff --git a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/pojo/FileCacheRequest.kt b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/pojo/FileCacheRequest.kt index a47007c994..ba9b438af1 100644 --- a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/pojo/FileCacheRequest.kt +++ b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/pojo/FileCacheRequest.kt @@ -33,6 +33,8 @@ data class FileCacheRequest( var repoName: String = "", // 路径前缀匹配 var pathPrefix: List = emptyList(), + // 文件后缀 + var fileExtension: List = emptyList(), // 保留最近多少天内访问 var days: Int = 30, var size: Long = 10, diff --git a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/pojo/TFileCache.kt b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/pojo/TFileCache.kt index e3598cd9c3..ca6725c4a9 100644 --- a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/pojo/TFileCache.kt +++ b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/pojo/TFileCache.kt @@ -46,6 +46,8 @@ data class TFileCache( var repoName: String, // 路径前缀匹配 var pathPrefix: List = emptyList(), + // 文件后缀 + var fileExtension: List ?= emptyList(), // 保留最近多少天内访问 var days: Int = 30, var size: Long = 10 diff --git a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/service/impl/FileCacheServiceImp.kt b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/service/impl/FileCacheServiceImp.kt index bda8090f33..763d5a06f1 100644 --- a/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/service/impl/FileCacheServiceImp.kt +++ b/src/backend/job/biz-job/src/main/kotlin/com/tencent/bkrepo/job/service/impl/FileCacheServiceImp.kt @@ -48,6 +48,7 @@ class FileCacheServiceImp constructor( projectId = fileCacheRequest.projectId, repoName = fileCacheRequest.repoName, pathPrefix = fileCacheRequest.pathPrefix, + fileExtension = fileCacheRequest.fileExtension, size = fileCacheRequest.size, days = fileCacheRequest.days ) @@ -78,6 +79,7 @@ class FileCacheServiceImp constructor( projectId = fileCacheRequest.projectId, repoName = fileCacheRequest.repoName, pathPrefix = fileCacheRequest.pathPrefix, + fileExtension = fileCacheRequest.fileExtension, size = fileCacheRequest.size, days = fileCacheRequest.days ) diff --git a/src/frontend/devops-op/src/views/node/FileCache.vue b/src/frontend/devops-op/src/views/node/FileCache.vue index c02ebd5dd0..544d107653 100644 --- a/src/frontend/devops-op/src/views/node/FileCache.vue +++ b/src/frontend/devops-op/src/views/node/FileCache.vue @@ -46,7 +46,7 @@ - + + + + @@ -87,8 +97,8 @@ :visible.sync="showDialog" :updating-file-caches="updatingFileCache" :repo-config="fileCacheConf" - @created="getDates" - @updated="getDates" + @created="updated" + @updated="updated" /> @@ -101,6 +111,7 @@ import { searchProjects } from '@/api/project' import { listRepositories } from '@/api/repository' export default { + inject: ['reload'], name: 'FileCache', components: { CreateOrUpdateFileCacheDialog }, data() { @@ -254,6 +265,9 @@ export default { return projectFilter && repoFilter }) } + }, + updated() { + this.reload() } } } diff --git a/src/frontend/devops-op/src/views/node/components/CreateOrUpdateFileCacheDialog.vue b/src/frontend/devops-op/src/views/node/components/CreateOrUpdateFileCacheDialog.vue index 30df382f14..a83721a84e 100644 --- a/src/frontend/devops-op/src/views/node/components/CreateOrUpdateFileCacheDialog.vue +++ b/src/frontend/devops-op/src/views/node/components/CreateOrUpdateFileCacheDialog.vue @@ -39,31 +39,60 @@ - - - - - +
+ + + + + +
+
+ + + + + +
取 消 @@ -170,7 +199,10 @@ export default { if (fileCache.pathPrefix.length === 1 && fileCache.pathPrefix[0].trim() === '') { fileCache.pathPrefix = ['/'] } - fileCache.pathPrefix = Array.from(new Set(fileCache.pathPrefix)).filter(path => path.trim() !== '') + if (fileCache.fileExtension.length === 1 && fileCache.fileExtension[0].trim() === '') { + fileCache.fileExtension = ['/'] + } + fileCache.fileExtension = Array.from(new Set(fileCache.fileExtension)).filter(path => path.trim() !== '') // 根据是否为创建模式发起不同请求 let reqPromise let msg @@ -217,6 +249,9 @@ export default { if (this.createMode) { this.fileCache = this.newFileCache() } else { + if (!this.updatingFileCaches.fileExtension || this.updatingFileCaches.fileExtension.length === 0) { + this.updatingFileCaches.fileExtension = [''] + } this.fileCache = _.cloneDeep(this.updatingFileCaches) } this.$nextTick(() => { @@ -229,6 +264,7 @@ export default { repoName: '', paths: '', pathPrefix: [''], + fileExtension: [''], days: '', size: '' } @@ -254,8 +290,17 @@ export default { this.fileCache.pathPrefix.splice(index, 1) } }, + removeFileDomain(item) { + const index = this.fileCache.fileExtension.indexOf(item) + if (index !== -1 && this.fileCache.fileExtension.length !== 1) { + this.fileCache.fileExtension.splice(index, 1) + } + }, addDomain() { this.fileCache.pathPrefix.push('') + }, + addFileDomain() { + this.fileCache.fileExtension.push('') } } }