浏览代码

fix: 增加上传校验

liaoyitao 2 月之前
父节点
当前提交
6d841e24c5

+ 4 - 0
src/main/java/com/lqkj/link/config/ThreadPoolConfig.java

@@ -5,6 +5,7 @@ import org.springframework.context.annotation.Configuration;
5 5
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
6 6
 
7 7
 import java.util.concurrent.Executor;
8
+import java.util.concurrent.ThreadPoolExecutor;
8 9
 
9 10
 @Configuration
10 11
 public class ThreadPoolConfig {
@@ -15,6 +16,9 @@ public class ThreadPoolConfig {
15 16
         executor.setCorePoolSize(20); // 核心线程池大小
16 17
         executor.setMaxPoolSize(50); // 最大线程池大小
17 18
         executor.setQueueCapacity(500); // 队列容量
19
+        executor.setKeepAliveSeconds(300);
20
+        executor.setWaitForTasksToCompleteOnShutdown(true);
21
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
18 22
         executor.setThreadNamePrefix("Async-"); // 线程名称前缀
19 23
         executor.initialize();
20 24
         return executor;

+ 4 - 0
src/main/java/com/lqkj/link/module/base/service/BaseService.java

@@ -90,6 +90,10 @@ public class BaseService {
90 90
     }
91 91
 
92 92
     public String ossAddModel(MultipartFile file, String s) {
93
+        String fileName = file.getOriginalFilename();
94
+        String suffix = fileName == null ? "" : fileName.substring(fileName.lastIndexOf(".") + 1);
95
+        if (!suffix.equals("obj") && !suffix.equals("fbx"))
96
+            throw new RuntimeException("上传文件类型必须是obj、fbx格式的压缩文件");
93 97
         if (aliOSSUtils.ossCheckCapacity(s) + file.getSize() >= 21474836480L)
94 98
             throw new RuntimeException("容量已满,无法上传文件");
95 99
         try {

+ 11 - 0
src/main/java/com/lqkj/link/module/zone/controller/ResourceController.java

@@ -250,6 +250,11 @@ public class ResourceController {
250 250
         return MessageBean.ok(baseService.ossUpload(file), "oss上传");
251 251
     }
252 252
 
253
+    /**
254
+     * 检查本地容量
255
+     * @param request
256
+     * @return
257
+     */
253 258
     @GetMapping("/checkCapacity")
254 259
     public MessageBean<String> checkCapacity(HttpServletRequest request){
255 260
         String authHeader = request.getHeader("Authorization");
@@ -273,6 +278,12 @@ public class ResourceController {
273 278
         return MessageBean.ok(baseService.ossAddModel(file, "resource/model/" + userId + "/"), "oss上传");
274 279
     }
275 280
 
281
+
282
+    /**
283
+     * 阿里云检查容量
284
+     * @param request
285
+     * @return
286
+     */
276 287
     @GetMapping("/oss/checkCapacity")
277 288
     public MessageBean<String> ossCheckCapacity(HttpServletRequest request){
278 289
         String authHeader = request.getHeader("Authorization");

+ 10 - 0
src/main/java/com/lqkj/link/module/zone/service/ResourceService.java

@@ -166,6 +166,11 @@ public class ResourceService {
166 166
         return userInfo.getRefreshResource() != null && userInfo.getRefreshResource();
167 167
     }
168 168
 
169
+    /**
170
+     * 检查本地个人库容量
171
+     * @param userCode
172
+     * @return
173
+     */
169 174
     public String checkCapacity(String userCode) {
170 175
         UserInfo userInfo = userInfoRepository.findByUserCode(userCode);
171 176
         String filePath = "./upload/resource/model/" + userInfo.getUserId();
@@ -174,6 +179,11 @@ public class ResourceService {
174 179
         return "个人库 已使用" + FileUtils.convertBytes(FileUtils.getFolderSize(new File(filePath))) + "/20G";
175 180
     }
176 181
 
182
+    /**
183
+     * 检查OSS个人库容量
184
+     * @param userCode
185
+     * @return
186
+     */
177 187
     public String ossCheckCapacity(String userCode) {
178 188
         UserInfo userInfo = userInfoRepository.findByUserCode(userCode);
179 189
         Long aLong = aliOSSUtils.ossCheckCapacity("resource/model/" + userInfo.getUserId() + "/");