Przeglądaj źródła

url适配本地版本

dengsixing 2 lat temu
rodzic
commit
b6c629b1ee

+ 17 - 4
src/main/java/com/fdkankan/scene/service/impl/SceneEditInfoServiceImpl.java

@@ -1176,7 +1176,10 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
                 throw new BusinessException(ErrorCode.FAILURE_CODE_5063);
             }
             fYunFileService.uploadFile(bucket, localFilePath, ossFilePath);
-            url = ossUrlPrefix + ossFilePath;
+            url = ossFilePath;
+            if(!FYunTypeEnum.LOCAL.code().equals(this.fyunType)){
+                url = ossUrlPrefix + url;
+            }
             downloadName = fileName;
         }else{
             if(!cn.hutool.core.io.FileUtil.exist(localImagesPath)
@@ -1193,7 +1196,10 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
             log.info("打包耗时:" + (end1 - start));
             //上传压缩包
             fYunFileService.uploadFileByCommand(bucket, zipPath, String.format(cacheFormat, num) + downloadName);
-            url = ossUrlPrefix + String.format(cacheFormat, num) + downloadName;
+            url = String.format(cacheFormat, num) + downloadName;
+            if(!FYunTypeEnum.LOCAL.code().equals(this.fyunType)){
+                url = ossUrlPrefix + url;
+            }
             long end2 = Calendar.getInstance().getTimeInMillis();
             log.info("上传耗时:" + (end2 - end1));
             //删除本地压缩包
@@ -1341,7 +1347,10 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
     @Override
     public DownloadVO downloadBallScreenVideo(BallScreenVideoParamVO param) {
         String videoPath = String.format(UploadFilePath.VIDEOS_VIEW_PATH, param.getNum()) + param.getFileName();
-        String url = ossUrlPrefix + videoPath + "?t=" + System.currentTimeMillis();
+        String url = videoPath + "?t=" + System.currentTimeMillis();
+        if(!FYunTypeEnum.LOCAL.code().equals(this.fyunType)){
+            url = ossUrlPrefix + url;
+        }
         return DownloadVO.builder()
             .fileName(param.getFileName())
             .url(url)
@@ -1589,9 +1598,13 @@ public class SceneEditInfoServiceImpl extends ServiceImpl<ISceneEditInfoMapper,
 
             SceneDataDownload sceneDataDownload = sceneDataDownloadService.findBySceneNum(num);
             if(sceneDataDownload == null){
+                String downloadPath = "data_download/" + num + ".zip";
+                if(!FYunTypeEnum.LOCAL.code().equals(this.fyunType)){
+                    downloadPath = ossUrlPrefix + downloadPath;
+                }
                 sceneDataDownload = new SceneDataDownload();
                 sceneDataDownload.setSceneNum(num);
-                sceneDataDownload.setDownloadPath(ossUrlPrefix + "data_download/" + num + ".zip");
+                sceneDataDownload.setDownloadPath(downloadPath);
                 sceneDataDownload.setFileMd5(fileMD5);
                 sceneDataDownloadService.save(sceneDataDownload);
                 return ResultData.ok();

+ 12 - 3
src/main/java/com/fdkankan/scene/service/impl/SceneProServiceImpl.java

@@ -942,7 +942,10 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
                 ZipUtil.zip(meshPath, zipPath);
                 //上传压缩包
                 fYunFileService.uploadFile(bucket, zipPath, "downloads/extras/" + zipName);
-                String url = ossUrlPrefix + "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
+                String url = "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
+                if(!FYunTypeEnum.LOCAL.code().equals(fyunType)){
+                    url = ossUrlPrefix + url;
+                }
 //                FileUtil.del(zipPath);
                 return ResultData.ok(url);
             }
@@ -967,7 +970,10 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
             ZipUtil.zip(editData, zipPath);
             //上传压缩包
             fYunFileService.uploadFile(bucket, zipPath, "downloads/extras/" + zipName);
-            String url = ossUrlPrefix + "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
+            String url = "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
+            if(!FYunTypeEnum.LOCAL.code().equals(fyunType)){
+                url = ossUrlPrefix + url;
+            }
             return ResultData.ok(url);
         }
 
@@ -991,7 +997,10 @@ public class SceneProServiceImpl extends ServiceImpl<ISceneProMapper, ScenePro>
         ZipUtil.zip(dataPath, zipPath);
         //上传压缩包
         fYunFileService.uploadFile(bucket, zipPath, "downloads/extras/" + zipName);
-        String url = ossUrlPrefix + "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
+        String url = "downloads/extras/" + zipName + "?t=" + Calendar.getInstance().getTimeInMillis();
+        if(!FYunTypeEnum.LOCAL.code().equals(fyunType)){
+            url = ossUrlPrefix + url;
+        }
         return ResultData.ok(url);
     }
 }

+ 8 - 2
src/main/java/com/fdkankan/scene/service/impl/SceneUploadServiceImpl.java

@@ -11,6 +11,7 @@ import com.fdkankan.common.constant.ErrorCode;
 import com.fdkankan.common.constant.RecStatus;
 import com.fdkankan.common.constant.ServerCode;
 import com.fdkankan.common.util.FileUtils;
+import com.fdkankan.fyun.constant.FYunTypeEnum;
 import com.fdkankan.model.constants.UploadFilePath;
 import com.fdkankan.common.exception.BusinessException;
 import com.fdkankan.web.response.ResultData;
@@ -58,6 +59,8 @@ public class SceneUploadServiceImpl extends ServiceImpl<ISceneUploadMapper, Scen
 
     @Value("${fyun.host}")
     private String ossUrlPrefix;
+    @Value("${fyun.type}")
+    private String fyunType;
 
     @Resource
     private FYunFileServiceInterface fYunFileService;
@@ -223,7 +226,10 @@ public class SceneUploadServiceImpl extends ServiceImpl<ISceneUploadMapper, Scen
         cn.hutool.core.io.FileUtil.writeString(param.getContent(), tempFile, StandardCharsets.UTF_8);
         fYunFileService.uploadFile(param.getBucket(), tempFile.getPath(), param.getOssPath());
         tempFile.deleteOnExit();
-
-        return this.ossUrlPrefix + param.getOssPath();
+        String url = param.getOssPath();
+        if(!FYunTypeEnum.LOCAL.code().equals(fyunType)){
+            url = this.ossUrlPrefix + url;
+        }
+        return url;
     }
 }