Skip to content

Commit

Permalink
pref:插件国际化properties文件value值支持引入文件 TencentBlueKing#9366
Browse files Browse the repository at this point in the history
  • Loading branch information
yjieliang committed Oct 8, 2023
1 parent 335cc85 commit 4be6c77
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -62,8 +61,8 @@ interface ServiceArchiveAtomResource {
): Result<String>

@ApiOperation("下载插件包文件")
@POST
@Path("/atom/file/content")
@GET
@Path("/atom/file/download")
fun downloadAtomFile(
@ApiParam("文件路径", required = true)
@QueryParam("filePath")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ interface ServiceGitResource {
): Result<GitMrInfo>

@ApiOperation("下载git仓库文件")
@POST
@GET
@Path("repoIds/{repoId}/downloadTGitRepoFile")
fun downloadGitRepoFile(
@ApiParam(value = "仓库id")
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,29 @@ class SampleStoreFileServiceImpl : StoreFileService() {
pathList: List<String>,
client: Client,
fileDirPath: String,
logoFlag: Boolean,
result: MutableMap<String, String>
): Map<String, String> {
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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import org.springframework.stereotype.Service
* since: 2019-08-15
*/
@Service
@Suppress("ALL")
abstract class StoreFileService {

companion object {
Expand Down Expand Up @@ -105,6 +104,7 @@ abstract class StoreFileService {
pathList: List<String>,
client: Client,
fileDirPath: String,
logoFlag: Boolean = false,
result: MutableMap<String, String>
): Map<String, String>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down

0 comments on commit 4be6c77

Please sign in to comment.