From 4be6c77ba49f983e29c6b08f8852af3bc19700f1 Mon Sep 17 00:00:00 2001 From: yjieliang Date: Sun, 8 Oct 2023 15:30:12 +0800 Subject: [PATCH] =?UTF-8?q?pref:=E6=8F=92=E4=BB=B6=E5=9B=BD=E9=99=85?= =?UTF-8?q?=E5=8C=96properties=E6=96=87=E4=BB=B6value=E5=80=BC=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=BC=95=E5=85=A5=E6=96=87=E4=BB=B6=20#9366?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/ServiceArchiveAtomResource.kt | 5 +- .../repository/api/scm/ServiceGitResource.kt | 2 +- .../common/TextReferenceFileParseRequest.kt | 45 +++++++++++++++++ .../common/impl/SampleStoreFileServiceImpl.kt | 32 +++++++------ .../impl/SampleStoreI18nMessageServiceImpl.kt | 7 +-- .../store/service/common/StoreFileService.kt | 2 +- .../impl/StoreI18nMessageServiceImpl.kt | 48 +++++++++---------- 7 files changed, 93 insertions(+), 48 deletions(-) create mode 100644 src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/pojo/common/TextReferenceFileParseRequest.kt diff --git a/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/ServiceArchiveAtomResource.kt b/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/ServiceArchiveAtomResource.kt index b53b2aa1d38..321089cdef6 100644 --- a/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/ServiceArchiveAtomResource.kt +++ b/src/backend/ci/core/artifactory/api-artifactory/src/main/kotlin/com/tencent/devops/artifactory/api/ServiceArchiveAtomResource.kt @@ -37,7 +37,6 @@ import javax.ws.rs.Consumes import javax.ws.rs.DELETE import javax.ws.rs.GET import javax.ws.rs.HeaderParam -import javax.ws.rs.POST import javax.ws.rs.PUT import javax.ws.rs.Path import javax.ws.rs.PathParam @@ -62,8 +61,8 @@ interface ServiceArchiveAtomResource { ): Result @ApiOperation("下载插件包文件") - @POST - @Path("/atom/file/content") + @GET + @Path("/atom/file/download") fun downloadAtomFile( @ApiParam("文件路径", required = true) @QueryParam("filePath") diff --git a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/scm/ServiceGitResource.kt b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/scm/ServiceGitResource.kt index 06f36c2ba46..7a3c32bc18d 100644 --- a/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/scm/ServiceGitResource.kt +++ b/src/backend/ci/core/repository/api-repository/src/main/kotlin/com/tencent/devops/repository/api/scm/ServiceGitResource.kt @@ -385,7 +385,7 @@ interface ServiceGitResource { ): Result @ApiOperation("下载git仓库文件") - @POST + @GET @Path("repoIds/{repoId}/downloadTGitRepoFile") fun downloadGitRepoFile( @ApiParam(value = "仓库id") diff --git a/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/pojo/common/TextReferenceFileParseRequest.kt b/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/pojo/common/TextReferenceFileParseRequest.kt new file mode 100644 index 00000000000..8bcef0963fe --- /dev/null +++ b/src/backend/ci/core/store/api-store/src/main/kotlin/com/tencent/devops/store/pojo/common/TextReferenceFileParseRequest.kt @@ -0,0 +1,45 @@ +/* + * Tencent is pleased to support the open source community by making BK-CI 蓝鲸持续集成平台 available. + * + * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved. + * + * BK-CI 蓝鲸持续集成平台 is licensed under the MIT license. + * + * A copy of the MIT License is included in this file. + * + * + * Terms of the MIT License: + * --------------------------------------------------- + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated + * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of + * the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT + * LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +package com.tencent.devops.store.pojo.common + +import io.swagger.annotations.ApiModel +import io.swagger.annotations.ApiModelProperty + +@ApiModel("文本引用文件解析请求") +data class TextReferenceFileParseRequest( + @ApiModelProperty("插件包文件路径", required = true) + val fileDir: String, + @ApiModelProperty("仓库哈希ID", required = false) + val repositoryHashId: String? = null, + @ApiModelProperty("分支", required = false) + val branch: String? = null, + @ApiModelProperty("文本内容", required = true) + val content: String, + @ApiModelProperty("国际化语言信息", required = true) + val language: String +) diff --git a/src/backend/ci/core/store/biz-store-sample/src/main/kotlin/com/tencent/devops/store/service/common/impl/SampleStoreFileServiceImpl.kt b/src/backend/ci/core/store/biz-store-sample/src/main/kotlin/com/tencent/devops/store/service/common/impl/SampleStoreFileServiceImpl.kt index e40d394d582..6a8c7364daf 100644 --- a/src/backend/ci/core/store/biz-store-sample/src/main/kotlin/com/tencent/devops/store/service/common/impl/SampleStoreFileServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store-sample/src/main/kotlin/com/tencent/devops/store/service/common/impl/SampleStoreFileServiceImpl.kt @@ -51,25 +51,29 @@ class SampleStoreFileServiceImpl : StoreFileService() { pathList: List, client: Client, fileDirPath: String, + logoFlag: Boolean, result: MutableMap ): Map { pathList.forEach { path -> val file = File("$fileDirPath${fileSeparator}$path") - if (file.exists()) { - val serviceUrlPrefix = client.getServiceUrl(ServiceFileResource::class) - val fileUrl = CommonUtils.serviceUploadFile( - userId = userId, - serviceUrlPrefix = serviceUrlPrefix, - file = file, - fileChannelType = FileChannelTypeEnum.WEB_SHOW.name, - logo = true, - language = I18nUtil.getLanguage(I18nUtil.getRequestUserId()) - ).data - fileUrl?.let { result[path] = fileUrl } - } else { - logger.warn("Resource file does not exist:${file.path}") + try { + if (file.exists()) { + val serviceUrlPrefix = client.getServiceUrl(ServiceFileResource::class) + val fileUrl = CommonUtils.serviceUploadFile( + userId = userId, + serviceUrlPrefix = serviceUrlPrefix, + file = file, + logo = logoFlag, + fileChannelType = FileChannelTypeEnum.WEB_SHOW.name, + language = I18nUtil.getLanguage(I18nUtil.getRequestUserId()) + ).data + fileUrl?.let { result[path] = fileUrl } + } else { + logger.warn("Resource file does not exist:${file.path}") + } + } finally { + file.delete() } - file.delete() } return result } diff --git a/src/backend/ci/core/store/biz-store-sample/src/main/kotlin/com/tencent/devops/store/service/common/impl/SampleStoreI18nMessageServiceImpl.kt b/src/backend/ci/core/store/biz-store-sample/src/main/kotlin/com/tencent/devops/store/service/common/impl/SampleStoreI18nMessageServiceImpl.kt index 74cdeba337d..7220b7a6598 100644 --- a/src/backend/ci/core/store/biz-store-sample/src/main/kotlin/com/tencent/devops/store/service/common/impl/SampleStoreI18nMessageServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store-sample/src/main/kotlin/com/tencent/devops/store/service/common/impl/SampleStoreI18nMessageServiceImpl.kt @@ -71,12 +71,9 @@ class SampleStoreI18nMessageServiceImpl : StoreI18nMessageServiceImpl() { format: String? ) { val url = client.getServiceUrl(ServiceArchiveAtomResource::class) + - "/service/artifactories/atom/file/content?filePath=${URLEncoder.encode(filePath, "UTF-8")}" + "/service/artifactories/atom/file/download?filePath=${URLEncoder.encode(filePath, "UTF-8")}" logger.info("downloadFile filePath:$filePath") - val response = OkhttpUtils.doPost(url, "") - if (response.isSuccessful) { - OkhttpUtils.downloadFile(response, file) - } + OkhttpUtils.downloadFile(url, file) } override fun getFileNames( diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/common/StoreFileService.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/common/StoreFileService.kt index 857a696db46..072e53b02bd 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/common/StoreFileService.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/common/StoreFileService.kt @@ -42,7 +42,6 @@ import org.springframework.stereotype.Service * since: 2019-08-15 */ @Service -@Suppress("ALL") abstract class StoreFileService { companion object { @@ -105,6 +104,7 @@ abstract class StoreFileService { pathList: List, client: Client, fileDirPath: String, + logoFlag: Boolean = false, result: MutableMap ): Map diff --git a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/common/impl/StoreI18nMessageServiceImpl.kt b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/common/impl/StoreI18nMessageServiceImpl.kt index 77a72db85b4..2e41b294702 100644 --- a/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/common/impl/StoreI18nMessageServiceImpl.kt +++ b/src/backend/ci/core/store/biz-store/src/main/kotlin/com/tencent/devops/store/service/common/impl/StoreI18nMessageServiceImpl.kt @@ -42,6 +42,7 @@ import com.tencent.devops.common.web.service.ServiceI18nMessageResource import com.tencent.devops.common.web.utils.I18nUtil import com.tencent.devops.store.dao.atom.AtomDao import com.tencent.devops.store.pojo.common.KEY_RELEASE_INFO +import com.tencent.devops.store.pojo.common.TextReferenceFileParseRequest import com.tencent.devops.store.service.common.StoreFileService import com.tencent.devops.store.service.common.StoreFileService.Companion.BK_CI_PATH_REGEX import com.tencent.devops.store.service.common.StoreI18nMessageService @@ -240,12 +241,14 @@ abstract class StoreI18nMessageServiceImpl : StoreI18nMessageService { val description = fileProperties["$KEY_RELEASE_INFO.$KEY_DESCRIPTION"]?.toString() if (!description.isNullOrBlank()) { val descriptionStr = getDescriptionI18nContent( - userId = userId, projectCode = projectCode, - fileDir = fileDir, - repositoryHashId = repositoryHashId, - content = description, - language = language + userId = userId, + request = TextReferenceFileParseRequest( + fileDir = fileDir, + repositoryHashId = repositoryHashId, + content = description, + language = language + ) ) if (description != descriptionStr) { fileProperties["$KEY_RELEASE_INFO.$KEY_DESCRIPTION"] = descriptionStr @@ -355,12 +358,9 @@ abstract class StoreI18nMessageServiceImpl : StoreI18nMessageService { private fun getDescriptionI18nContent( userId: String, projectCode: String, - fileDir: String, - repositoryHashId: String? = null, - branch: String? = null, - content: String, - language: String + request: TextReferenceFileParseRequest ): String { + val content = request.content val pattern: Pattern = Pattern.compile(BK_CI_PATH_REGEX) val matcher: Matcher = pattern.matcher(content) val path: String @@ -369,22 +369,22 @@ abstract class StoreI18nMessageServiceImpl : StoreI18nMessageService { } else { return content } - // 存在文件路径引用,解析路径 - val fileStr = getFileStr( + return getFileStr( projectCode = projectCode, - fileDir = fileDir, + fileDir = request.fileDir, fileName = "file/$path", - repositoryHashId = repositoryHashId, - branch = branch - ) ?: return content - return descriptionAnalysis( - userId = userId, - projectCode = projectCode, - description = fileStr, - fileDir = fileDir, - language = language, - repositoryHashId = repositoryHashId - ) + repositoryHashId = request.repositoryHashId, + branch = request.branch + )?.let { fileStr -> + descriptionAnalysis( + userId = userId, + projectCode = projectCode, + description = fileStr, + fileDir = request.fileDir, + language = request.language, + repositoryHashId = request.repositoryHashId + ) + } ?: content } abstract fun descriptionAnalysis(