Skip to content

Commit

Permalink
fix: artifactory对接制品库时,上传插件logo失败 #6260
Browse files Browse the repository at this point in the history
  • Loading branch information
yaoxuwan authored and irwinsun committed Mar 14, 2022
1 parent 087a70d commit 4fe96c9
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ interface ServiceFileResource {
projectCode: String? = null,
@ApiParam("渠道类型", required = true)
@QueryParam("fileChannelType")
fileChannelType: FileChannelTypeEnum = FileChannelTypeEnum.SERVICE
fileChannelType: FileChannelTypeEnum = FileChannelTypeEnum.SERVICE,
@ApiParam("是否为插件logo", required = false)
@QueryParam("logo")
logo: Boolean? = false
): Result<String?>

@ApiOperation("下载文件")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ class UserFileResourceImpl @Autowired constructor(
checkParam(userId, projectId, path)
val url = archiveFileService.uploadFile(
userId = userId,
projectId = projectId,
filePath = path,
inputStream = inputStream,
disposition = disposition,
projectId = projectId,
filePath = path,
fileType = FileTypeEnum.BK_CUSTOM,
fileChannelType = FileChannelTypeEnum.WEB_SHOW
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,16 @@ class ServiceFileResourceImpl @Autowired constructor(private val archiveFileServ
inputStream: InputStream,
disposition: FormDataContentDisposition,
projectCode: String?,
fileChannelType: FileChannelTypeEnum
fileChannelType: FileChannelTypeEnum,
logo: Boolean?
): Result<String?> {
val url = archiveFileService.uploadFile(
userId = userId,
inputStream = inputStream,
disposition = disposition,
projectId = projectCode,
fileChannelType = fileChannelType
fileChannelType = fileChannelType,
logo = logo
)
return Result(url)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ interface ArchiveFileService {
fileName: String? = null,
fileType: FileTypeEnum? = null,
props: Map<String, String?>? = null,
fileChannelType: FileChannelTypeEnum
fileChannelType: FileChannelTypeEnum,
logo: Boolean? = false
): String

/**
Expand All @@ -74,7 +75,8 @@ interface ArchiveFileService {
filePath: String? = null,
fileType: FileTypeEnum? = null,
props: Map<String, String?>? = null,
fileChannelType: FileChannelTypeEnum
fileChannelType: FileChannelTypeEnum,
logo: Boolean? = false
): String

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ abstract class ArchiveFileServiceImpl : ArchiveFileService {
filePath: String?,
fileType: FileTypeEnum?,
props: Map<String, String?>?,
fileChannelType: FileChannelTypeEnum
fileChannelType: FileChannelTypeEnum,
logo: Boolean?
): String {
val fileName = String(disposition.fileName.toByteArray(Charset.forName("ISO8859-1")), Charset.forName("UTF-8"))
val file = DefaultPathUtils.randomFile(fileName)
Expand All @@ -93,7 +94,8 @@ abstract class ArchiveFileServiceImpl : ArchiveFileService {
fileName = fileName,
fileType = fileType,
props = props,
fileChannelType = fileChannelType
fileChannelType = fileChannelType,
logo = logo
)
} finally {
file.delete()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class BkRepoArchiveFileServiceImpl @Autowired constructor(
fileName: String?,
fileType: FileTypeEnum?,
props: Map<String, String?>?,
fileChannelType: FileChannelTypeEnum
fileChannelType: FileChannelTypeEnum,
logo: Boolean?
): String {
val destPath = filePath ?: DefaultPathUtils.randomFileName()
val metadata = mutableMapOf<String, String>()
Expand All @@ -102,8 +103,20 @@ class BkRepoArchiveFileServiceImpl @Autowired constructor(
projectId!!
}
val repoName = BkRepoUtils.getRepoName(fileType)
defaultBkRepoClient.uploadLocalFile(userId, repoProjectId, repoName, destPath, file, metadata)
return generateFileDownloadUrl(fileChannelType, "$repoProjectId/$repoName/$destPath")
return if (logo == true) {
defaultBkRepoClient.uploadLocalFile(
userId = userId,
projectId = BKREPO_STORE_PROJECT_ID,
repoName = REPO_NAME_STATIC,
path = destPath,
file = file,
metadata = metadata
)
generateFileDownloadUrl(fileChannelType, destPath).plus("?logo=true")
} else {
defaultBkRepoClient.uploadLocalFile(userId, repoProjectId, repoName, destPath, file, metadata)
generateFileDownloadUrl(fileChannelType, "$repoProjectId/$repoName/$destPath")
}
}

override fun downloadArchiveFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ class DiskArchiveFileServiceImpl : ArchiveFileServiceImpl() {
fileName: String?,
fileType: FileTypeEnum?,
props: Map<String, String?>?,
fileChannelType: FileChannelTypeEnum
fileChannelType: FileChannelTypeEnum,
logo: Boolean?
): String {
logger.info("uploadFile|filePath=$filePath|fileName=$fileName|props=$props")
val uploadFileName = fileName ?: file.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,11 @@ object CommonUtils {
userId: String,
serviceUrlPrefix: String,
file: File,
fileChannelType: String
fileChannelType: String,
logo: Boolean = false
): Result<String?> {
val serviceUrl =
"$serviceUrlPrefix/service/artifactories/file/upload?userId=$userId&fileChannelType=$fileChannelType"
val serviceUrl = "$serviceUrlPrefix/service/artifactories/file/upload" +
"?userId=$userId&fileChannelType=$fileChannelType&logo=$logo"
logger.info("the serviceUrl is:$serviceUrl")
OkhttpUtils.uploadFile(serviceUrl, file).use { response ->
val responseContent = response.body()!!.string()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ class SampleStoreLogoServiceImpl : StoreLogoServiceImpl() {
userId = userId,
serviceUrlPrefix = serviceUrlPrefix,
file = file,
fileChannelType = FileChannelTypeEnum.WEB_SHOW.name
fileChannelType = FileChannelTypeEnum.WEB_SHOW.name,
logo = true
).data
// 开源版如果logoUrl的域名和ci域名一样,则logoUrl无需带上域名,防止域名变更影响图片显示(logoUrl会存db)
return Result(if (logoUrl != null) StoreUtils.removeUrlHost(logoUrl) else logoUrl)
Expand Down
2 changes: 2 additions & 0 deletions support-files/sql/5001_ci_store-init_dml_mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,5 @@ INSERT IGNORE INTO `T_STORE_STATISTICS_TOTAL` (`ID`, `STORE_CODE`, `STORE_TYPE`,
('0bf3fd65f97649888c1d8b7072c89299','codeP4WebHookTrigger','0','0','0','0','0.00','2021-02-24 11:23:23','2021-06-17 21:21:30','0','0');
INSERT IGNORE INTO `T_ATOM_ENV_INFO` (`ID`, `ATOM_ID`, `PKG_PATH`, `LANGUAGE`, `MIN_VERSION`, `TARGET`, `PRE_CMD`, `CREATOR`, `MODIFIER`, `CREATE_TIME`, `UPDATE_TIME`, `SHA_CONTENT`, `PKG_NAME`, `POST_ENTRY_PARAM`, `POST_CONDITION`) VALUES
('48101620b2394b728be3cfcfaa46a746','39580f08e9574fc291cdd8c51f39ddee','','java','1.8','',NULL,'system','system','2021-11-16 15:56:53','2021-11-16 15:56:53',NULL,'',NULL,NULL);

REPLACE INTO `T_LOGO`(`ID`, `TYPE`, `LOGO_URL`, `LINK`, `CREATOR`, `MODIFIER`, `CREATE_TIME`, `UPDATE_TIME`, `ORDER`) VALUES ('ef3e60ba6ef44b92b0fec0b940af8fa1', 'BANNER', '/ms/artifactory/api/user/artifactories/file/download?filePath=%2Ffile%2Fpng%2FBANNER.png&logo=true', '', 'system', 'system', '2019-10-21 17:23:40', '2022-03-10 17:23:40', 2);

0 comments on commit 4fe96c9

Please sign in to comment.