|
@@ -7,6 +7,7 @@ import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.crypto.digest.DigestUtil;
|
|
|
import com.backendsys.exception.CustException;
|
|
|
import com.backendsys.modules.common.config.security.utils.HttpRequestUtil;
|
|
|
+import com.backendsys.modules.sdk.douyincloud.tos.service.DouyinTosService;
|
|
|
import com.backendsys.modules.sdk.tencentcloud.cos.service.TencentCosService;
|
|
|
import com.backendsys.modules.system.entity.SysCommon;
|
|
|
import com.backendsys.modules.system.service.SysCommonService;
|
|
@@ -16,6 +17,9 @@ import com.backendsys.modules.upload.enums.StyleEnums;
|
|
|
import com.backendsys.modules.upload.service.SysFileMultipartService;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.qcloud.cos.model.*;
|
|
|
+import com.volcengine.tos.model.object.CompleteMultipartUploadV2Output;
|
|
|
+import com.volcengine.tos.model.object.CreateMultipartUploadOutput;
|
|
|
+import com.volcengine.tos.model.object.UploadPartV2Output;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -39,6 +43,8 @@ public class SysFileMultipartServiceImpl implements SysFileMultipartService {
|
|
|
@Autowired
|
|
|
private TencentCosService tencentCosService;
|
|
|
@Autowired
|
|
|
+ private DouyinTosService douyinTosService;
|
|
|
+ @Autowired
|
|
|
private SysCommonService sysCommonService;
|
|
|
@Autowired
|
|
|
private SysFileDao sysFileDao;
|
|
@@ -84,17 +90,22 @@ public class SysFileMultipartServiceImpl implements SysFileMultipartService {
|
|
|
|
|
|
System.out.println("[系统配置] 上传目标(-1:本地, 1:腾讯云, 2:阿里云, 3.抖音云): " + UPLOAD_TARGET);
|
|
|
|
|
|
- String target_label = "";
|
|
|
+ String target_label = StyleEnums.targetToLabel(UPLOAD_TARGET.get());
|
|
|
String upload_id = null;
|
|
|
String object_key = null;
|
|
|
|
|
|
// target: 上传目标 (-1:本地, 1:腾讯云, 2:阿里云, 3.抖音云)
|
|
|
if (UPLOAD_TARGET.get() == 1) {
|
|
|
- target_label = "腾讯云初始化分块";
|
|
|
InitiateMultipartUploadResult uploadResult = tencentCosService.initiateMultipartUpload(multipartFile);
|
|
|
upload_id = uploadResult.getUploadId();
|
|
|
object_key = uploadResult.getKey();
|
|
|
}
|
|
|
+ // 3: 抖音云
|
|
|
+ if (UPLOAD_TARGET.get() == 3) {
|
|
|
+ CreateMultipartUploadOutput uploadResult = douyinTosService.initiateMultipartUpload(multipartFile);
|
|
|
+ upload_id = uploadResult.getUploadID();
|
|
|
+ object_key = uploadResult.getKey();
|
|
|
+ }
|
|
|
|
|
|
// 如果没有获得以上参数,则抛出报错
|
|
|
if (StrUtil.isEmpty(upload_id) || StrUtil.isEmpty(object_key)) {
|
|
@@ -149,12 +160,17 @@ public class SysFileMultipartServiceImpl implements SysFileMultipartService {
|
|
|
System.out.println("[系统配置] 上传目标(-1:本地, 1:腾讯云, 2:阿里云, 3.抖音云): " + UPLOAD_TARGET);
|
|
|
|
|
|
|
|
|
- PartETag part_etag = null;
|
|
|
+ String part_etag = null;
|
|
|
|
|
|
// target: 上传目标 (-1:本地, 1:腾讯云, 2:阿里云, 3.抖音云)
|
|
|
if (UPLOAD_TARGET.get() == 1) {
|
|
|
UploadPartResult partResult = tencentCosService.uploadPart(multipartFile, upload_id, object_key, upload_chunk_index);
|
|
|
- part_etag = partResult.getPartETag();
|
|
|
+ part_etag = partResult.getPartETag().getETag();
|
|
|
+ }
|
|
|
+ // 3: 抖音云
|
|
|
+ if (UPLOAD_TARGET.get() == 3) {
|
|
|
+ UploadPartV2Output partResult = douyinTosService.uploadPart(multipartFile, upload_id, object_key, upload_chunk_index);
|
|
|
+ part_etag = partResult.getEtag();
|
|
|
}
|
|
|
|
|
|
// // 查询分块上传情况 (获得下次要上传的位置)
|
|
@@ -208,17 +224,15 @@ public class SysFileMultipartServiceImpl implements SysFileMultipartService {
|
|
|
PartListing partListing = listParts(upload_id, sysFileEntity.getObject_key());
|
|
|
List<PartSummary> partSummaryList = partListing.getParts();
|
|
|
List<PartETag> etags = partSummaryList.stream()
|
|
|
- .map(partSummary -> new PartETag(partSummary.getPartNumber(), partSummary.getETag()))
|
|
|
- .collect(Collectors.toList());
|
|
|
+ .map(partSummary -> new PartETag(partSummary.getPartNumber(), partSummary.getETag()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
|
// 如果分块数量对不上,最好还是重新上传
|
|
|
- if (sysFileEntity.getUpload_chunk_count() != etags.size()) {
|
|
|
- throw new CustException("分块索引异常,请重新上传");
|
|
|
- }
|
|
|
+ if (sysFileEntity.getUpload_chunk_count() != etags.size()) throw new CustException("分块索引异常,请重新上传");
|
|
|
|
|
|
// [腾讯云] 合并分块
|
|
|
CompleteMultipartUploadResult completeResult = tencentCosService.completeMultipartUpload(upload_id, sysFileEntity.getObject_key(), etags);
|
|
|
- if (completeResult == null) throw new CustException("合并失败");
|
|
|
+ if (completeResult == null) throw new CustException("分块合并失败");
|
|
|
|
|
|
// 拼接图片路径
|
|
|
String url = ACCESSIBLE_DOMAIN + "/" + completeResult.getKey();
|
|
@@ -238,6 +252,16 @@ public class SysFileMultipartServiceImpl implements SysFileMultipartService {
|
|
|
resp.put("url", url);
|
|
|
return resp;
|
|
|
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3: 抖音云
|
|
|
+ if (UPLOAD_TARGET.get() == 3) {
|
|
|
+
|
|
|
+ CompleteMultipartUploadV2Output completeResult = douyinTosService.completeMultipartUpload(upload_id, sysFileEntity.getObject_key());
|
|
|
+ if (completeResult == null) throw new CustException("分块合并失败");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
return null;
|