|
@@ -6,7 +6,8 @@ import com.github.tobato.fastdfs.service.AppendFileStorageClient
|
|
|
import com.github.tobato.fastdfs.service.FastFileStorageClient
|
|
|
import com.gxzc.zen.common.exception.ZenException
|
|
|
import com.gxzc.zen.common.exception.ZenExceptionEnum
|
|
|
-import com.gxzc.zen.common.properties.UploadProperties
|
|
|
+import com.gxzc.zen.common.properties.FSProperties
|
|
|
+import com.gxzc.zen.common.properties.FdfsProperties
|
|
|
import com.gxzc.zen.common.util.KeyLock
|
|
|
import com.gxzc.zen.common.util.SpringContextHolder
|
|
|
import com.gxzc.zen.common.util.upload.constants.CheckStatus
|
|
@@ -31,7 +32,8 @@ import java.nio.file.Paths
|
|
|
object FdfsUploadUtil {
|
|
|
private val logger = LoggerFactory.getLogger(FdfsUploadUtil::class.java)
|
|
|
|
|
|
- private val uploadProperties: UploadProperties by lazy { SpringContextHolder.getBean(UploadProperties::class.java)!! }
|
|
|
+ private val fdfsProperties: FdfsProperties by lazy { SpringContextHolder.getBean(FdfsProperties::class.java)!! }
|
|
|
+ private val fsProperties: FSProperties by lazy { SpringContextHolder.getBean(FSProperties::class.java)!! }
|
|
|
|
|
|
private val appendFileStorageClient: AppendFileStorageClient by lazy { SpringContextHolder.getBean(AppendFileStorageClient::class.java)!! }
|
|
|
private val fastFileStorageClient: FastFileStorageClient by lazy { SpringContextHolder.getBean(FastFileStorageClient::class.java)!! }
|
|
@@ -96,7 +98,7 @@ object FdfsUploadUtil {
|
|
|
ret.checkStatus = CheckStatus.FDFS_NO_DB_FULL_CHUNK
|
|
|
|
|
|
val hashedMd5 = fileMetadata.md5!!.hashCode()
|
|
|
- val tmpPath = uploadProperties.tmpPath!!
|
|
|
+ val tmpPath = fdfsProperties.tmpPath
|
|
|
|
|
|
checkMergeLock.lock(hashedMd5)
|
|
|
try {
|
|
@@ -120,8 +122,8 @@ object FdfsUploadUtil {
|
|
|
* 文件夹结构/文件名
|
|
|
*/
|
|
|
fun upload(fileMetadata: ZenFileMetadata, file: MultipartFile): UploadResult {
|
|
|
- val tmpPath = uploadProperties.tmpPath!!
|
|
|
- val chunkSize = uploadProperties.chunkSize!!
|
|
|
+ val tmpPath = fdfsProperties.tmpPath
|
|
|
+ val chunkSize = fsProperties.chunkSize
|
|
|
var storePath: StorePath? = null
|
|
|
if (validateRequest(fileMetadata, file)) {
|
|
|
val filename = fileMetadata.filename!!
|
|
@@ -182,7 +184,7 @@ object FdfsUploadUtil {
|
|
|
val totalChunks = fileMetadata.totalChunks!!
|
|
|
val md5 = fileMetadata.md5!!
|
|
|
// val hashedMd5 = md5.hashCode()
|
|
|
- // val chunkSize = uploadProperties!!.chunkSize!!
|
|
|
+ // val chunkSize = fdfsProperties!!.chunkSize!!
|
|
|
var storePath: StorePath? = null
|
|
|
for (i in 1..totalChunks) {
|
|
|
val sourceFile = File(getChunkFilename(sourceRootPath, i, md5))
|
|
@@ -224,7 +226,7 @@ object FdfsUploadUtil {
|
|
|
* 检查分片是否存在 (tmp目录)
|
|
|
*/
|
|
|
private fun chunkExists(chunkNumber: Int?, md5: String): Boolean {
|
|
|
- val tmpPath = uploadProperties.tmpPath!!
|
|
|
+ val tmpPath = fdfsProperties.tmpPath
|
|
|
return Files.exists(Paths.get(getChunkFilename(tmpPath, chunkNumber, md5)))
|
|
|
}
|
|
|
|
|
@@ -275,9 +277,9 @@ object FdfsUploadUtil {
|
|
|
}
|
|
|
|
|
|
// is the file too large?
|
|
|
- uploadProperties.let {
|
|
|
+ fsProperties.let {
|
|
|
val maxFileSize = it.maxFileSize
|
|
|
- if (maxFileSize != null && maxFileSize > 0) {
|
|
|
+ if (maxFileSize > 0) {
|
|
|
if (totalSize > maxFileSize) {
|
|
|
logger.error("filesize limit: [${maxFileSize / 1024 / 1024} MB], now [${totalSize / 1024 / 1024} MB]")
|
|
|
return false
|