|
@@ -1,6 +1,7 @@
|
|
|
package cn.reghao.tnb.file.app.service;
|
|
package cn.reghao.tnb.file.app.service;
|
|
|
|
|
|
|
|
import cn.reghao.jutil.jdk.security.DigestUtil;
|
|
import cn.reghao.jutil.jdk.security.DigestUtil;
|
|
|
|
|
+import cn.reghao.tnb.file.app.util.redis.RedisKey;
|
|
|
import cn.reghao.tnb.file.app.util.redis.ds.RedisSet;
|
|
import cn.reghao.tnb.file.app.util.redis.ds.RedisSet;
|
|
|
import cn.reghao.tnb.file.app.config.PathUrl;
|
|
import cn.reghao.tnb.file.app.config.PathUrl;
|
|
|
import cn.reghao.tnb.file.app.db.repository.FileRepository;
|
|
import cn.reghao.tnb.file.app.db.repository.FileRepository;
|
|
@@ -67,13 +68,14 @@ public class FileUploadService {
|
|
|
String uploadId = uploadFile.getUploadId();
|
|
String uploadId = uploadFile.getUploadId();
|
|
|
FileInfo fileInfo = fileRepository.getFileInfoByUploadId(uploadId);
|
|
FileInfo fileInfo = fileRepository.getFileInfoByUploadId(uploadId);
|
|
|
if (!fileInfo.getUploaded()) {
|
|
if (!fileInfo.getUploaded()) {
|
|
|
- put(uploadFile.getFile(), fileInfo);
|
|
|
|
|
|
|
+ put(uploadFile.getFile(), fileInfo, uploadId);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public synchronized String put(MultipartFile multipartFile, FileInfo fileInfo) throws Exception {
|
|
|
|
|
|
|
+ public synchronized String put(MultipartFile multipartFile, FileInfo fileInfo, String uploadId) throws Exception {
|
|
|
byte[] bytes = multipartFile.getBytes();
|
|
byte[] bytes = multipartFile.getBytes();
|
|
|
|
|
+ long size = multipartFile.getSize();
|
|
|
String sha256sum = DigestUtil.sha256sum(bytes);
|
|
String sha256sum = DigestUtil.sha256sum(bytes);
|
|
|
if (!sha256sum.equals(fileInfo.getSha256sum())) {
|
|
if (!sha256sum.equals(fileInfo.getSha256sum())) {
|
|
|
throw new Exception("uploadId 和 sha256sum 不匹配!");
|
|
throw new Exception("uploadId 和 sha256sum 不匹配!");
|
|
@@ -85,9 +87,10 @@ public class FileUploadService {
|
|
|
PathUrl pathUrl;
|
|
PathUrl pathUrl;
|
|
|
if (contentType != null && contentType.startsWith("image")) {
|
|
if (contentType != null && contentType.startsWith("image")) {
|
|
|
ImageOps.Size size1 = ImageOps.info(new ByteArrayInputStream(bytes));
|
|
ImageOps.Size size1 = ImageOps.info(new ByteArrayInputStream(bytes));
|
|
|
- pathUrl = fileUrlService.getImagePathAndUrl(sha256sum, fileId, suffix, size1.getWidth(), size1.getHeight());
|
|
|
|
|
|
|
+ pathUrl = fileUrlService.getImagePathAndUrl(sha256sum, uploadId, size, fileId, suffix,
|
|
|
|
|
+ size1.getWidth(), size1.getHeight());
|
|
|
} else {
|
|
} else {
|
|
|
- pathUrl = fileUrlService.genPathAndUrl(sha256sum, fileId, suffix);
|
|
|
|
|
|
|
+ pathUrl = fileUrlService.genVideoPathAndUrl(sha256sum, uploadId, size, fileId, suffix);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
FileContentType fileType = fileTypeService.getFileType(contentType, pathUrl.getFilePath());
|
|
FileContentType fileType = fileTypeService.getFileType(contentType, pathUrl.getFilePath());
|