|
@@ -1,6 +1,14 @@
|
|
|
package com.fdkankan.scene.controller;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.lang.UUID;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import com.fdkankan.common.constant.ErrorCode;
|
|
|
import com.fdkankan.common.constant.SceneInfoReqType;
|
|
|
+import com.fdkankan.common.constant.UploadFilePath;
|
|
|
+import com.fdkankan.common.exception.BusinessException;
|
|
|
+import com.fdkankan.common.util.BASE64DecodedMultipartFile;
|
|
|
import com.fdkankan.common.util.ESAPIUtil;
|
|
|
import com.fdkankan.scene.annotation.CheckToken;
|
|
|
import com.fdkankan.scene.annotation.InitEditInfo;
|
|
@@ -8,12 +16,23 @@ import com.fdkankan.scene.bean.ResultData;
|
|
|
import com.fdkankan.scene.service.*;
|
|
|
import com.fdkankan.scene.vo.*;
|
|
|
import lombok.extern.log4j.Log4j2;
|
|
|
+import org.apache.commons.fileupload.FileItem;
|
|
|
+import org.apache.commons.fileupload.FileItemFactory;
|
|
|
+import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
|
|
+import org.apache.commons.fileupload.servlet.ServletFileUpload;
|
|
|
+import org.apache.commons.lang.StringEscapeUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.owasp.esapi.errors.EncodingException;
|
|
|
+import org.owasp.esapi.errors.ValidationException;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* 场景编辑管理
|
|
@@ -247,7 +266,7 @@ public class SceneEditController extends BaseController{
|
|
|
* @return
|
|
|
**/
|
|
|
@PostMapping(value = "/cad/rename")
|
|
|
- public ResultData renameCad(@RequestBody @Validated RenameCadParamVO param) throws IOException {
|
|
|
+ public ResultData renameCad(@RequestBody @Validated RenameCadParamVO param) throws IOException, EncodingException, ValidationException {
|
|
|
param.setSubgroup(this.getSubgroup());
|
|
|
param.setUpTimeKey(this.getUpTime());
|
|
|
return sceneEditInfoService.renameCad(param);
|
|
@@ -268,7 +287,7 @@ public class SceneEditController extends BaseController{
|
|
|
public SceneInfoVO getInfo(@Validated SceneInfoParamVO param) throws Exception{
|
|
|
param.setReqType(SceneInfoReqType.EDIT.code());
|
|
|
response.setHeader("Set-Cookie","cookiename=cookievalue; path=/; Domain=domainvaule; Max-age=seconds; HttpOnly");
|
|
|
- return sceneEditInfoService.getSceneInfo(param.getNum(), param.getSubgroup(), param.getUpTimeKey(), (byte)2);
|
|
|
+ return sceneEditInfoService.getSceneInfo(StringEscapeUtils.escapeHtml(param.getNum()), param.getSubgroup(), param.getUpTimeKey(), (byte)2);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -329,8 +348,18 @@ public class SceneEditController extends BaseController{
|
|
|
// return sceneProService.uploadModel(num, this.getSubgroup(), this.getUpTime(), file);
|
|
|
// }
|
|
|
|
|
|
+ private static Map<String, String> FILE_SIGNATURES;
|
|
|
+
|
|
|
+ static {
|
|
|
+ FILE_SIGNATURES = new HashMap<>();
|
|
|
+ FILE_SIGNATURES.put("jpg", "FFD8FF");
|
|
|
+ FILE_SIGNATURES.put("png", "89504E47");
|
|
|
+ }
|
|
|
+ @Resource
|
|
|
+ private FYunFileService fYunFileService;
|
|
|
+
|
|
|
@RequestMapping(value = "/upload/files", method = RequestMethod.POST)
|
|
|
- public String uploads(@RequestParam(value = "base64",required = false) String imgStr,
|
|
|
+ public String uploads(@RequestParam(value = "base64",required = false) String base64,
|
|
|
@RequestParam(value = "fileName",required = false) String fileName,
|
|
|
@RequestParam(value = "bizType",required = false) String bizType,
|
|
|
@RequestParam(value = "files",required = false) MultipartFile[] files,
|
|
@@ -339,8 +368,85 @@ public class SceneEditController extends BaseController{
|
|
|
@RequestParam(value = "uploadPath",required = false) String uploadPath) throws Exception {
|
|
|
Integer subgroup = this.getSubgroup();
|
|
|
String upTime = this.getUpTime();
|
|
|
- response.setHeader("Set-Cookie","cookiename=cookievalue; path=/; Domain=domainvaule; Max-age=seconds; HttpOnly");
|
|
|
- return sceneUploadService.uploads(imgStr,fileName,bizType,files,num,type,uploadPath, subgroup, upTime);
|
|
|
+ num = StringEscapeUtils.escapeHtml(num);
|
|
|
+ fileName = StringEscapeUtils.escapeHtml(fileName);
|
|
|
+ uploadPath = StringEscapeUtils.escapeHtml(uploadPath);
|
|
|
+ List<String> urlList = new ArrayList<>();
|
|
|
+// return sceneUploadService.uploads(base64,fileName,bizType,files,num,type,uploadPath, subgroup, upTime);
|
|
|
+ if(Objects.nonNull(files) && files.length > 0){
|
|
|
+ for (MultipartFile file : files) {
|
|
|
+ String originalFilename = StringEscapeUtils.escapeHtml(file.getOriginalFilename());
|
|
|
+ if(files.length == 1 && StrUtil.isNotEmpty(fileName)){
|
|
|
+ originalFilename = fileName;
|
|
|
+ }
|
|
|
+ String oldExtName = cn.hutool.core.io.FileUtil.extName(originalFilename);
|
|
|
+ String newExtName = oldExtName.toLowerCase();
|
|
|
+ originalFilename = originalFilename.substring(0, originalFilename.lastIndexOf(oldExtName)) + newExtName;
|
|
|
+ String suffix = "." + FileUtil.getSuffix(originalFilename);
|
|
|
+ File tempFile = FileUtil.createTempFile(UUID.fastUUID().toString(), suffix, new File(ESAPIUtil.validFilePath(ESAPIUtil.getRealPath("temp"))), true);
|
|
|
+ file.transferTo(tempFile);
|
|
|
+ String path = tempFile.getAbsolutePath();
|
|
|
+
|
|
|
+ String key = StrUtil.isNotBlank(uploadPath) ? uploadPath : (String.format(UploadFilePath.USER_VIEW_PATH , num) + originalFilename);
|
|
|
+ fYunFileService.uploadFile(num, subgroup, upTime, path, key);
|
|
|
+
|
|
|
+ urlList.add(originalFilename);
|
|
|
+
|
|
|
+ FileUtil.del(path);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(StrUtil.isNotEmpty(base64)){
|
|
|
+ String suffix = "." + FileUtil.getSuffix(fileName);
|
|
|
+ MultipartFile file = BASE64DecodedMultipartFile.base64ToMultipart(base64);
|
|
|
+ File tempFile = FileUtil.createTempFile(UUID.fastUUID().toString(), suffix, new File(ESAPIUtil.validFilePath(ESAPIUtil.getRealPath("temp"))), true);
|
|
|
+ file.transferTo(tempFile);
|
|
|
+ String path = tempFile.getAbsolutePath();
|
|
|
+
|
|
|
+ String originalFilename = StringEscapeUtils.escapeHtml(file.getOriginalFilename());
|
|
|
+ if(StringUtils.isNotBlank(fileName)){
|
|
|
+ originalFilename = fileName ;
|
|
|
+ }
|
|
|
+ String oldExtName = cn.hutool.core.io.FileUtil.extName(originalFilename);
|
|
|
+ String newExtName = oldExtName.toLowerCase();
|
|
|
+ originalFilename = originalFilename.substring(0, originalFilename.lastIndexOf(oldExtName)) + newExtName;
|
|
|
+ String key = StrUtil.isNotBlank(uploadPath) ? uploadPath : (String.format(UploadFilePath.USER_VIEW_PATH , num) + originalFilename);
|
|
|
+ fYunFileService.uploadFile(num, subgroup, upTime, path, key);
|
|
|
+ urlList.add(originalFilename);
|
|
|
+
|
|
|
+ FileUtil.del(path);
|
|
|
+ }
|
|
|
+
|
|
|
+ StringBuilder returnString = new StringBuilder();
|
|
|
+ for (String res : urlList) {
|
|
|
+ if(StringUtils.isNotBlank(returnString)){
|
|
|
+ returnString.append(",");
|
|
|
+ }
|
|
|
+ returnString.append(res);
|
|
|
+ }
|
|
|
+ return returnString.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ private String bytesToHex(byte[] bytes) {
|
|
|
+ StringBuilder sb = new StringBuilder();
|
|
|
+ for (byte b : bytes) {
|
|
|
+ sb.append(String.format("%02X", b));
|
|
|
+ }
|
|
|
+ return sb.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ String sanitizeFileName(String fileName) {
|
|
|
+ return fileName.replaceAll("[^a-zA-Z0-9._-]", "");
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean isValidFile(String fileName) {
|
|
|
+ String[] allowedExtensions = {".jpg", ".jpeg", ".png", ".gif"};
|
|
|
+ for (String ext : allowedExtensions) {
|
|
|
+ if (fileName.toLowerCase().endsWith(ext)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
}
|
|
|
|
|
|
/**
|