Browse Source

fix: 增加上传校验

liaoyitao 2 months ago
parent
commit
6d841e24c5

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

@@ -5,6 +5,7 @@ import org.springframework.context.annotation.Configuration;
5
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
5
 import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
6
 
6
 
7
 import java.util.concurrent.Executor;
7
 import java.util.concurrent.Executor;
8
+import java.util.concurrent.ThreadPoolExecutor;
8
 
9
 
9
 @Configuration
10
 @Configuration
10
 public class ThreadPoolConfig {
11
 public class ThreadPoolConfig {
@@ -15,6 +16,9 @@ public class ThreadPoolConfig {
15
         executor.setCorePoolSize(20); // 核心线程池大小
16
         executor.setCorePoolSize(20); // 核心线程池大小
16
         executor.setMaxPoolSize(50); // 最大线程池大小
17
         executor.setMaxPoolSize(50); // 最大线程池大小
17
         executor.setQueueCapacity(500); // 队列容量
18
         executor.setQueueCapacity(500); // 队列容量
19
+        executor.setKeepAliveSeconds(300);
20
+        executor.setWaitForTasksToCompleteOnShutdown(true);
21
+        executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
18
         executor.setThreadNamePrefix("Async-"); // 线程名称前缀
22
         executor.setThreadNamePrefix("Async-"); // 线程名称前缀
19
         executor.initialize();
23
         executor.initialize();
20
         return executor;
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
     public String ossAddModel(MultipartFile file, String s) {
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
         if (aliOSSUtils.ossCheckCapacity(s) + file.getSize() >= 21474836480L)
97
         if (aliOSSUtils.ossCheckCapacity(s) + file.getSize() >= 21474836480L)
94
             throw new RuntimeException("容量已满,无法上传文件");
98
             throw new RuntimeException("容量已满,无法上传文件");
95
         try {
99
         try {

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

@@ -250,6 +250,11 @@ public class ResourceController {
250
         return MessageBean.ok(baseService.ossUpload(file), "oss上传");
250
         return MessageBean.ok(baseService.ossUpload(file), "oss上传");
251
     }
251
     }
252
 
252
 
253
+    /**
254
+     * 检查本地容量
255
+     * @param request
256
+     * @return
257
+     */
253
     @GetMapping("/checkCapacity")
258
     @GetMapping("/checkCapacity")
254
     public MessageBean<String> checkCapacity(HttpServletRequest request){
259
     public MessageBean<String> checkCapacity(HttpServletRequest request){
255
         String authHeader = request.getHeader("Authorization");
260
         String authHeader = request.getHeader("Authorization");
@@ -273,6 +278,12 @@ public class ResourceController {
273
         return MessageBean.ok(baseService.ossAddModel(file, "resource/model/" + userId + "/"), "oss上传");
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
     @GetMapping("/oss/checkCapacity")
287
     @GetMapping("/oss/checkCapacity")
277
     public MessageBean<String> ossCheckCapacity(HttpServletRequest request){
288
     public MessageBean<String> ossCheckCapacity(HttpServletRequest request){
278
         String authHeader = request.getHeader("Authorization");
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
         return userInfo.getRefreshResource() != null && userInfo.getRefreshResource();
166
         return userInfo.getRefreshResource() != null && userInfo.getRefreshResource();
167
     }
167
     }
168
 
168
 
169
+    /**
170
+     * 检查本地个人库容量
171
+     * @param userCode
172
+     * @return
173
+     */
169
     public String checkCapacity(String userCode) {
174
     public String checkCapacity(String userCode) {
170
         UserInfo userInfo = userInfoRepository.findByUserCode(userCode);
175
         UserInfo userInfo = userInfoRepository.findByUserCode(userCode);
171
         String filePath = "./upload/resource/model/" + userInfo.getUserId();
176
         String filePath = "./upload/resource/model/" + userInfo.getUserId();
@@ -174,6 +179,11 @@ public class ResourceService {
174
         return "个人库 已使用" + FileUtils.convertBytes(FileUtils.getFolderSize(new File(filePath))) + "/20G";
179
         return "个人库 已使用" + FileUtils.convertBytes(FileUtils.getFolderSize(new File(filePath))) + "/20G";
175
     }
180
     }
176
 
181
 
182
+    /**
183
+     * 检查OSS个人库容量
184
+     * @param userCode
185
+     * @return
186
+     */
177
     public String ossCheckCapacity(String userCode) {
187
     public String ossCheckCapacity(String userCode) {
178
         UserInfo userInfo = userInfoRepository.findByUserCode(userCode);
188
         UserInfo userInfo = userInfoRepository.findByUserCode(userCode);
179
         Long aLong = aliOSSUtils.ossCheckCapacity("resource/model/" + userInfo.getUserId() + "/");
189
         Long aLong = aliOSSUtils.ossCheckCapacity("resource/model/" + userInfo.getUserId() + "/");