Explorar el Código

四川日报项目需求,上传空间模型接口支持glb格式

dengsixing hace 10 meses
padre
commit
1c17101d62

+ 24 - 18
src/main/java/com/fdkankan/scene/service/impl/BoxModelServiceImpl.java

@@ -74,35 +74,41 @@ public class BoxModelServiceImpl implements IBoxModelService {
         ScenePlusExt scenePlusExt = scenePlusExtService.getScenePlusExtByPlusId(scenePlus.getId());
         String bucket = scenePlusExt.getYunFileBucket();
 
-        if(!file.getOriginalFilename().endsWith(".zip")){
-            throw new BusinessException(ErrorCode.FAILURE_CODE_7015);
+        if(!file.getOriginalFilename().endsWith(".zip")  && !file.getOriginalFilename().endsWith(".glb")){
+            throw new BusinessException(ErrorCode.FAILURE_CODE_7007.code(), ErrorCode.FAILURE_CODE_7007.formatMessage("zip或者glb"));
         }
 
-        if(!FileUtils.checkFileSizeIsLimit(file.getSize(), 5, "M")){
-            throw new BusinessException(ErrorCode.FAILURE_CODE_7023, "5M");
-        }
+//        if(!FileUtils.checkFileSizeIsLimit(file.getSize(), 5, "M")){
+//            throw new BusinessException(ErrorCode.FAILURE_CODE_7023, "5M");
+//        }
         String path = String.format(ConstantFilePath.SCENE_USER_PATH_V4, num) + "boxModel/" + sid + "/";
         String zipPath = path + file.getOriginalFilename();
         String srcPath = path + "data/";
         String glbPath = path + sid + ".glb";
 
         FileUtil.del(path);
-        FileUtil.mkParentDirs(zipPath);
-        file.transferTo(new File(zipPath));
 
-        //解压
-        ZipUtil.unzip(zipPath,srcPath);
+        if(file.getOriginalFilename().endsWith(".zip")){
+            FileUtil.mkParentDirs(zipPath);
+            file.transferTo(new File(zipPath));
 
-        //校验是否包含目录,如果包含目录提示错误
-        File srcFile = new File(srcPath);
-        Arrays.stream(srcFile.listFiles()).forEach(subFile->{
-            if(subFile.isDirectory()){
-                throw new BusinessException(ErrorCode.FAILURE_CODE_5065);
-            }
-        });
+            //解压
+            ZipUtil.unzip(zipPath,srcPath);
 
-        //转glb
-        OBJToGLBUtil.objToGlb(srcPath, glbPath);
+            //校验是否包含目录,如果包含目录提示错误
+            File srcFile = new File(srcPath);
+            Arrays.stream(srcFile.listFiles()).forEach(subFile->{
+                if(subFile.isDirectory()){
+                    throw new BusinessException(ErrorCode.FAILURE_CODE_5065);
+                }
+            });
+
+            //转glb
+            OBJToGLBUtil.objToGlb(srcPath, glbPath);
+        }else{
+            FileUtil.mkParentDirs(glbPath);
+            file.transferTo(new File(glbPath));
+        }
 
         if(!ComputerUtil.checkComputeCompleted(glbPath, 3, 2000)){
             throw new BusinessException(ErrorCode.FAILURE_CODE_7013);