Skip to content

Commit

Permalink
Merge pull request TencentBlueKing#974 from zacYL/issue_972
Browse files Browse the repository at this point in the history
bug: 删除分发临时存放的文件 TencentBlueKing#972
  • Loading branch information
owenlxu authored Jul 27, 2023
2 parents 20065c7 + 4b5e7fb commit 2a458d9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
package com.tencent.bkrepo.common.artifact.resolve.file

import com.tencent.bkrepo.common.artifact.api.ArtifactFile
import com.tencent.bkrepo.common.artifact.api.toArtifactFile
import com.tencent.bkrepo.common.artifact.repository.context.ArtifactContextHolder
import com.tencent.bkrepo.common.artifact.resolve.file.bksync.BkSyncArtifactFile
import com.tencent.bkrepo.common.artifact.resolve.file.chunk.ChunkedArtifactFile
Expand All @@ -43,6 +44,7 @@ import org.springframework.stereotype.Component
import org.springframework.web.context.request.RequestAttributes.SCOPE_REQUEST
import org.springframework.web.context.request.RequestContextHolder
import org.springframework.web.multipart.MultipartFile
import java.io.File
import java.io.InputStream

/**
Expand Down Expand Up @@ -131,6 +133,19 @@ class ArtifactFileFactory(
}
}

/**
* 通过表单文件构造artifact file,存放临时目录
* @param multipartFile 表单文件
* @param filePath 文件临时存储路径
*/
fun build(file: MultipartFile, filePath: String): ArtifactFile {
val artifactFile = File(filePath)
file.transferTo(artifactFile)
return artifactFile.toArtifactFile().apply {
track(this)
}
}

/**
* 获取当前仓库的存储凭证
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import com.tencent.bkrepo.common.api.exception.ErrorCodeException
import com.tencent.bkrepo.common.api.exception.NotFoundException
import com.tencent.bkrepo.common.api.pojo.Response
import com.tencent.bkrepo.common.artifact.api.ArtifactFile
import com.tencent.bkrepo.common.artifact.api.toArtifactFile
import com.tencent.bkrepo.common.artifact.message.ArtifactMessageCode
import com.tencent.bkrepo.common.artifact.resolve.file.ArtifactFileFactory
import com.tencent.bkrepo.common.security.permission.Principal
Expand Down Expand Up @@ -59,7 +58,6 @@ import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RequestPart
import org.springframework.web.bind.annotation.RestController
import org.springframework.web.multipart.MultipartFile
import java.io.File

/**
* blob数据同步接口
Expand Down Expand Up @@ -110,9 +108,7 @@ class BlobReplicaController(
ArtifactFileFactory.build(file, credentials)
} else {
val filepath: String = credentials.upload.location + "/" + fileName
val artifactFile = File(filepath)
file.transferTo(artifactFile)
artifactFile.toArtifactFile()
ArtifactFileFactory.build(file, filepath)
}
}

Expand Down

0 comments on commit 2a458d9

Please sign in to comment.