|
@@ -1,9 +1,11 @@
|
|
package cn.com.qmth.examcloud.core.basic.api.controller;
|
|
package cn.com.qmth.examcloud.core.basic.api.controller;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.HashSet;
|
|
import java.util.Iterator;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
import java.util.Optional;
|
|
|
|
+import java.util.Set;
|
|
import java.util.regex.Pattern;
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
import javax.persistence.criteria.Predicate;
|
|
import javax.persistence.criteria.Predicate;
|
|
@@ -48,6 +50,14 @@ import io.swagger.annotations.ApiOperation;
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("${$rmp.ctr.basic}/resource")
|
|
@RequestMapping("${$rmp.ctr.basic}/resource")
|
|
public class ResourceController extends ControllerSupport {
|
|
public class ResourceController extends ControllerSupport {
|
|
|
|
+ private static int fileSize=10;
|
|
|
|
+ private static Set<String> suffSet=new HashSet<String>();
|
|
|
|
+ static {
|
|
|
|
+ suffSet.add("txt");
|
|
|
|
+ suffSet.add("xlsx");
|
|
|
|
+ suffSet.add("docx");
|
|
|
|
+ suffSet.add("pptx");
|
|
|
|
+ }
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private ResourceRepo resourceRepo;
|
|
private ResourceRepo resourceRepo;
|
|
@@ -131,6 +141,16 @@ public class ResourceController extends ControllerSupport {
|
|
if (!Pattern.matches(regex, fileName)) {
|
|
if (!Pattern.matches(regex, fileName)) {
|
|
throw new StatusException("100022", "文件名长度最大为50且只能包含字母,数字,'-','_','.'");
|
|
throw new StatusException("100022", "文件名长度最大为50且只能包含字母,数字,'-','_','.'");
|
|
}
|
|
}
|
|
|
|
+ if(fileName.indexOf(".")==-1||fileName.indexOf(".")==fileName.length()-1) {
|
|
|
|
+ throw new StatusException("100023", "文件类型未知");
|
|
|
|
+ }
|
|
|
|
+ String suff=fileName.substring(fileName.lastIndexOf(".")+1);
|
|
|
|
+ if(!suffSet.contains(suff.toLowerCase())) {
|
|
|
|
+ throw new StatusException("100024", "文件类型只能是"+StringUtils.join(suffSet, ','));
|
|
|
|
+ }
|
|
|
|
+ if(dataFile.getSize()>fileSize*1024*1024) {
|
|
|
|
+ throw new StatusException("100025", "文件大小限制为"+fileSize+"M");
|
|
|
|
+ }
|
|
resourceService.addFile(rootOrgId, parentId, dataFile);
|
|
resourceService.addFile(rootOrgId, parentId, dataFile);
|
|
}
|
|
}
|
|
|
|
|