|
@@ -10,6 +10,8 @@ import com.backendsys.modules.sdk.tencentcloud.cos.entity.Progress;
|
|
|
import com.backendsys.modules.sdk.tencentcloud.cos.entity.ProgressData;
|
|
|
import com.backendsys.modules.sdk.tencentcloud.cos.service.TencentCosService;
|
|
|
import com.backendsys.modules.sdk.tencentcloud.cos.utils.TencentCosUtil;
|
|
|
+import com.backendsys.modules.sse.entity.SseResponse;
|
|
|
+import com.backendsys.modules.sse.entity.SseResponseEnum;
|
|
|
import com.backendsys.modules.sse.utils.SseUtil;
|
|
|
import com.backendsys.modules.upload.entity.SysUploadResult;
|
|
|
import com.qcloud.cos.COSClient;
|
|
@@ -79,11 +81,12 @@ public class TencentCosServiceImpl implements TencentCosService {
|
|
|
// [腾讯云COS][高级接口] 获取进度函数
|
|
|
private void showTransferProgress(String filename, Transfer transfer) {
|
|
|
|
|
|
- Progress progress = new Progress();
|
|
|
- progress.setState("Init");
|
|
|
-
|
|
|
String emitterKey = APPLICATION_NAME + "-userid-" + Convert.toStr(SecurityUtil.getUserId());
|
|
|
- sseUtil.send(emitterKey, progress);
|
|
|
+
|
|
|
+ // [SSE] 进度回传
|
|
|
+ Progress progress = new Progress();
|
|
|
+ progress.setState("init");
|
|
|
+ sseUtil.send(emitterKey, (new SseResponse(SseResponseEnum.UPLOAD, progress)).toJsonStr());
|
|
|
|
|
|
// 查询上传是否已经完成
|
|
|
while (transfer.isDone() == false) {
|
|
@@ -97,15 +100,14 @@ public class TencentCosServiceImpl implements TencentCosService {
|
|
|
String state = Convert.toStr(transfer.getState());
|
|
|
System.out.printf("Upload progress: [%d / %d] = %.02f%% (%s)\n", current, total, percent, state);
|
|
|
|
|
|
- ProgressData progressData = new ProgressData();
|
|
|
- progressData.setFilename(filename);
|
|
|
- progressData.setCurrent(current);
|
|
|
- progressData.setTotal(total);
|
|
|
- progressData.setPercent(percent);
|
|
|
-
|
|
|
- progress.setState(state);
|
|
|
- progress.setData(progressData);
|
|
|
- sseUtil.send(emitterKey, progress);
|
|
|
+ // [SSE] 进度回传
|
|
|
+ progress.setFilename(filename);
|
|
|
+ progress.setCurrent(current);
|
|
|
+ progress.setTotal(total);
|
|
|
+ progress.setPercent(percent);
|
|
|
+ progress.setState(state.toLowerCase());
|
|
|
+ String dataStr = (new SseResponse(SseResponseEnum.UPLOAD, progress)).toJsonStr();
|
|
|
+ sseUtil.send(emitterKey, dataStr);
|
|
|
|
|
|
// state: (完成 Completed, 失败 Failed)
|
|
|
// System.out.println(transfer.getState());
|