Bladeren bron

修改:更改文件访问路径,新增排除校验条目

GDW 8 maanden geleden
bovenliggende
commit
08e57914e8

+ 22 - 9
src/main/java/cn/lttc/modules/config/SaTokenConfigure.java

@@ -20,17 +20,30 @@ public class SaTokenConfigure implements WebMvcConfigurer {
         // 注册 Sa-Token 拦截器,校验规则为 StpUtil.checkLogin() 登录校验。
         ArrayList<String> list = new ArrayList<>();
         list.add("/samplescan/user/login");
-        list.add("/samplescan/api/getimg/**");
+        list.add("/samplescan/api/upload/**");
+        list.add("/favicon.ico");
+        list.add("/error");
         registry.addInterceptor(new SaInterceptor(handle -> StpUtil.checkLogin()))
                 .addPathPatterns("/**")
                 .excludePathPatterns(list);
-
-//        registry.addInterceptor(new SaInterceptor(handler -> {
-//            // 指定一条 match 规则
-//            SaRouter.match("/**")    // 拦截的 path 列表,可以写多个 */
-//                    .notMatch("/samplescan/user/login")
-//                    .notMatch("/samplescan/api/getimg/**")
-//                    .check(r -> StpUtil.checkLogin());
-//        })).addPathPatterns("/**");
     }
+
+//    @Override
+//    public void addInterceptors(InterceptorRegistry registry) {
+//        ArrayList<String> list = new ArrayList<>();
+//        list.add("/samplescan/user/login");
+//        list.add("/samplescan/api/upload/**");
+//        list.add("/favicon.ico");
+//        list.add("/error");
+//        registry.addInterceptor(new SaInterceptor(handle -> {
+//            try {
+//                System.out.println("-------- 前端访问path:" + SaHolder.getRequest().getRequestPath());
+//                StpUtil.checkLogin();
+//                System.out.println("-------- 此 path 校验成功:" + SaHolder.getRequest().getRequestPath());
+//            } catch (Exception e) {
+//                System.out.println("-------- 此 path 校验失败:" + SaHolder.getRequest().getRequestPath());
+//                throw e;
+//            }
+//        })).addPathPatterns("/**").excludePathPatterns(list);;
+//    }
 }

+ 1 - 1
src/main/java/cn/lttc/modules/lttcsamplescan/controller/SampleScanController.java

@@ -50,7 +50,7 @@ public class SampleScanController {
         return SaResult.data(jsonObject);
     }
 
-    @GetMapping("/getimg/{year}/{month}/{filename}")
+    @GetMapping("/upload/{year}/{month}/{filename}")
     ResponseEntity<byte[]> getImg(@PathVariable String year, @PathVariable String month, @PathVariable String filename) {
 
         ResponseEntity<byte[]> imgService = sampleScanService.getImgService(year, month, filename);

+ 4 - 4
src/main/java/cn/lttc/modules/lttcsamplescan/service/impl/SampleScanServiceImpl.java

@@ -141,9 +141,9 @@ public class SampleScanServiceImpl implements ISampleScanService {
             for (int i = 0; i < mainImgList.size(); i++) {
                 String originalFilename = mainImgList.get(i).getOriginalFilename();
                 if (i == mainImgList.size() - 1){
-                    mainFileList.append("https://xyxt.lttc.cn/samplescan/api/getimg/").append(currentYear).append("/").append(currentMonthStr).append("/").append(originalFilename);
+                    mainFileList.append("https://xyxt.lttc.cn/samplescan/api/upload/").append(currentYear).append("/").append(currentMonthStr).append("/").append(originalFilename);
                 } else {
-                    mainFileList.append("https://xyxt.lttc.cn/samplescan/api/getimg/").append(currentYear).append("/").append(currentMonthStr).append("/").append(originalFilename).append(";");
+                    mainFileList.append("https://xyxt.lttc.cn/samplescan/api/upload/").append(currentYear).append("/").append(currentMonthStr).append("/").append(originalFilename).append(";");
                 }
             }
             sampleScan.setFileSavePath(mainFileList.toString());
@@ -162,9 +162,9 @@ public class SampleScanServiceImpl implements ISampleScanService {
                     for (int i = 0; i < multipartFiles.size(); i++) {
                         String originalFilename = multipartFiles.get(i).getOriginalFilename();
                         if (i == multipartFiles.size() - 1){
-                            detailFileList.append("https://xyxt.lttc.cn/samplescan/api/getimg/").append(currentYear).append("/").append(currentMonthStr).append("/").append(originalFilename);
+                            detailFileList.append("https://xyxt.lttc.cn/samplescan/api/upload/").append(currentYear).append("/").append(currentMonthStr).append("/").append(originalFilename);
                         } else {
-                            detailFileList.append("https://xyxt.lttc.cn/samplescan/api/getimg/").append(currentYear).append("/").append(currentMonthStr).append("/").append(originalFilename).append(";");
+                            detailFileList.append("https://xyxt.lttc.cn/samplescan/api/upload/").append(currentYear).append("/").append(currentMonthStr).append("/").append(originalFilename).append(";");
                         }
                     }
                     sampleScanDetail.setFileSavePath(detailFileList.toString());

+ 1 - 1
src/main/java/cn/lttc/modules/utils/HttpUtils.java

@@ -40,7 +40,7 @@ public class HttpUtils {
         InputStream inputStream = null;
         File file = new File(urlPath);
 
-            inputStream = new FileInputStream(file);
+        inputStream = new FileInputStream(file);
 
 
         return inputStream;