From cf3251e92561ad3f0a8da2ad1b8bfd76bd8ba2c9 Mon Sep 17 00:00:00 2001
From: 13693261870 <252740454@qq.com>
Date: 星期五, 13 九月 2024 17:21:23 +0800
Subject: [PATCH] 1

---
 src/main/java/com/se/simu/config/CorsConfig.java    |   60 ++++++++++++++++++++++++++++++
 src/main/java/com/se/simu/service/WaterService.java |   14 +++---
 src/main/resources/application.yml                  |    5 +-
 3 files changed, 70 insertions(+), 9 deletions(-)

diff --git a/src/main/java/com/se/simu/config/CorsConfig.java b/src/main/java/com/se/simu/config/CorsConfig.java
new file mode 100644
index 0000000..6fc92df
--- /dev/null
+++ b/src/main/java/com/se/simu/config/CorsConfig.java
@@ -0,0 +1,60 @@
+package com.se.simu.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.http.HttpHeaders;
+import org.springframework.http.HttpMethod;
+import org.springframework.http.HttpStatus;
+import org.springframework.http.server.reactive.ServerHttpRequest;
+import org.springframework.http.server.reactive.ServerHttpResponse;
+import org.springframework.web.cors.reactive.CorsUtils;
+import org.springframework.web.server.ServerWebExchange;
+import org.springframework.web.server.WebFilter;
+import org.springframework.web.server.WebFilterChain;
+import reactor.core.publisher.Mono;
+
+/**
+ * 璺ㄥ煙閰嶇疆
+ *
+ * @author se
+ * @date 2024-08-28
+ */
+//@Configuration
+@SuppressWarnings("ALL")
+public class CorsConfig
+{
+    /**
+     * 杩欓噷涓烘敮鎸佺殑璇锋眰澶达紝濡傛灉鏈夎嚜瀹氫箟鐨刪eader瀛楁璇疯嚜宸辨坊鍔�
+     */
+    // private static final String ALLOWED_HEADERS = "X-Requested-With, Content-Type, Authorization, credential, X-XSRF-TOKEN, token, Admin-Token, App-Token"
+    private static final String ALLOWED_HEADERS = "*";
+    private static final String ALLOWED_METHODS = "GET,POST,PUT,DELETE,OPTIONS,HEAD";
+    private static final String ALLOWED_ORIGIN = "*";
+    private static final String ALLOWED_EXPOSE = "*";
+    private static final String MAX_AGE = "18000L";
+
+    @Bean
+    public WebFilter corsFilter()
+    {
+        return (ServerWebExchange ctx, WebFilterChain chain) -> {
+            ServerHttpRequest request = ctx.getRequest();
+            if (CorsUtils.isCorsRequest(request))
+            {
+                ServerHttpResponse response = ctx.getResponse();
+                HttpHeaders headers = response.getHeaders();
+                headers.add("Access-Control-Allow-Headers", ALLOWED_HEADERS);
+                headers.add("Access-Control-Allow-Methods", ALLOWED_METHODS);
+                headers.add("Access-Control-Allow-Origin", ALLOWED_ORIGIN);
+                headers.add("Access-Control-Expose-Headers", ALLOWED_EXPOSE);
+                headers.add("Access-Control-Max-Age", MAX_AGE);
+                headers.add("Access-Control-Allow-Credentials", "true");
+                if (request.getMethod() == HttpMethod.OPTIONS)
+                {
+                    response.setStatusCode(HttpStatus.OK);
+                    return Mono.empty();
+                }
+            }
+            return chain.filter(ctx);
+        };
+    }
+}
diff --git a/src/main/java/com/se/simu/service/WaterService.java b/src/main/java/com/se/simu/service/WaterService.java
index d278139..474706e 100644
--- a/src/main/java/com/se/simu/service/WaterService.java
+++ b/src/main/java/com/se/simu/service/WaterService.java
@@ -23,15 +23,15 @@
     @Value("${sys.ver}")
     String ver;
 
-    @Value("${sys.path.data}")
-    String dataPath;
+    @Value("${sys.path.out}")
+    String outPath;
 
     /**
      * 鑾峰彇鍏冩暟鎹俊鎭�
      */
     public byte[] getLayerJson(String serviceName) {
         try {
-            String filePath = dataPath + File.separator + serviceName + File.separator + "layer.json";
+            String filePath = outPath + File.separator + serviceName + File.separator + "layer.json";
 
             File dat = new File(filePath);
             if (!dat.exists()) {
@@ -54,25 +54,25 @@
      * 鑾峰彇鍦板舰楂樺害鍥�
      */
     public String getTerraMap(String serviceName, Integer width, Integer height) {
-        return dataPath + File.separator + serviceName + File.separator + "terrain" + File.separator + width + "_" + height + ".png";
+        return outPath + File.separator + serviceName + File.separator + "terrain" + File.separator + width + "_" + height + ".png";
     }
 
     /**
      * 鑾峰彇姘撮潰楂樺害鍥�
      */
     public String getWaterMap(String serviceName, Integer width, Integer height, Long timestamp) {
-        return dataPath + File.separator + serviceName + File.separator + "waters" + File.separator + timestamp + File.separator + width + "_" + height + ".png";
+        return outPath + File.separator + serviceName + File.separator + "waters" + File.separator + timestamp + File.separator + width + "_" + height + ".png";
     }
 
     /**
      * 鑾峰彇姘存祦鍚戞祦閫熷浘
      */
     public String getFlowMap(String serviceName, Integer width, Integer height, Long timestamp) {
-        return dataPath + File.separator + serviceName + File.separator + "flows" + File.separator + timestamp + File.separator + width + "_" + height + ".png";
+        return outPath + File.separator + serviceName + File.separator + "flows" + File.separator + timestamp + File.separator + width + "_" + height + ".png";
     }
 
     /**
-     * 鑾峰彇鍥惧眰
+     * 鑾峰彇鍥惧眰 *
      */
     public Layer getLayer(String serviceName) {
         Layer layer = new Layer();
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
index 18ff479..5eec82d 100644
--- a/src/main/resources/application.yml
+++ b/src/main/resources/application.yml
@@ -37,9 +37,10 @@
   readTimeout: -1
 
 sys:
-  ver: 0.1
+  ver: 0.2
   path:
-    data: D:\simu
+    in: D:\simu\in
+    out: D:\simu\out
 
 sedb:
   host: http://106.120.22.26:8013/

--
Gitblit v1.9.3