|
@@ -10,10 +10,10 @@ import org.apache.commons.io.FilenameUtils;
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
+import org.apache.poi.util.TempFile;
|
|
|
import org.bytedeco.javacv.FFmpegFrameGrabber;
|
|
import org.bytedeco.javacv.FFmpegFrameGrabber;
|
|
|
import org.bytedeco.javacv.Frame;
|
|
import org.bytedeco.javacv.Frame;
|
|
|
import org.bytedeco.javacv.Java2DFrameConverter;
|
|
import org.bytedeco.javacv.Java2DFrameConverter;
|
|
|
-import org.pngquant.PngQuant;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
@@ -26,10 +26,7 @@ import java.awt.image.BufferedImage;
|
|
|
import java.io.*;
|
|
import java.io.*;
|
|
|
import java.net.URLConnection;
|
|
import java.net.URLConnection;
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.Base64;
|
|
|
|
|
-import java.util.Date;
|
|
|
|
|
-import java.util.Objects;
|
|
|
|
|
-import java.util.Optional;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
|
|
|
|
@@ -182,4 +179,30 @@ public class FileUploadController {
|
|
|
|
|
|
|
|
return new FileObject(file.getOriginalFilename(), url, thumbUrl, file.getContentType());
|
|
return new FileObject(file.getOriginalFilename(), url, thumbUrl, file.getContentType());
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @PostMapping("/3dModel")
|
|
|
|
|
+ public FileObject upload3dModel(@RequestParam("file") MultipartFile file) throws IOException {
|
|
|
|
|
+ if (!"zip".equalsIgnoreCase(FilenameUtils.getExtension(file.getOriginalFilename()))) {
|
|
|
|
|
+ throw new BusinessException("只能上传zip");
|
|
|
|
|
+ }
|
|
|
|
|
+ File destDir = TempFile.createTempDirectory(RandomStringUtils.randomAlphabetic(20));
|
|
|
|
|
+ com.izouma.nineth.utils.FileUtils.unzip(file.getInputStream(), destDir);
|
|
|
|
|
+ File fbxFile = com.izouma.nineth.utils.FileUtils.findInDir(destDir, ".fbx");
|
|
|
|
|
+ if (fbxFile == null) {
|
|
|
|
|
+ throw new BusinessException("找不到fbx文件");
|
|
|
|
|
+ }
|
|
|
|
|
+ File fbxDir = fbxFile.getParentFile();
|
|
|
|
|
+ String basePath = "fbx/"
|
|
|
|
|
+ + new SimpleDateFormat("yyyy-MM_dd-HH").format(new Date()) + "/"
|
|
|
|
|
+ + RandomStringUtils.randomAlphabetic(16);
|
|
|
|
|
+ List<String> urls = new ArrayList<>();
|
|
|
|
|
+ for (File listFile : fbxDir.listFiles()) {
|
|
|
|
|
+ if (!listFile.isHidden() && !listFile.isDirectory()) {
|
|
|
|
|
+ urls.add(storageService.uploadFromInputStream(new FileInputStream(listFile), basePath + "/" + listFile.getName()));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ String fbxUrl = urls.stream().filter(s -> s.toLowerCase().endsWith(".fbx")).findAny()
|
|
|
|
|
+ .orElseThrow(new BusinessException("找不到fbx文件"));
|
|
|
|
|
+ return new FileObject(fbxFile.getName(), fbxUrl, null, "fbx");
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|