zhangnaiwen 1 سال پیش
والد
کامیت
3dd6ab1918
3فایلهای تغییر یافته به همراه39 افزوده شده و 8 حذف شده
  1. 8 0
      src/app/api/mission.py
  2. 2 2
      src/app/defines/__init__.py
  3. 29 6
      src/app/utils/utils.py

+ 8 - 0
src/app/api/mission.py

@@ -62,6 +62,14 @@ class MissionAPI(Resource):
             if not data_path:
                 return jsonify(code=StatesCode.PARA_ERROR, message='输入路径错误')
 
+            file_list = []
+            for file in os.listdir(data_path):
+                if file.endswith('.tif'):
+                    file_list.append(file)
+
+            if not file_list:
+                return jsonify(code=StatesCode.PARA_ERROR, message='路径无有效文件')
+
             err_file = []
             # 验证数据有错误数据直接返回错误数据
             for file_name in os.listdir(data_path):

+ 2 - 2
src/app/defines/__init__.py

@@ -1,6 +1,6 @@
 class StatesCode:
     UNKNOWN_ERROR = -2  # 未知错误
-    SUCCESS = 0  # 成功
+    SUCCESS = 200  # 成功
     PARA_MISSING = 10  # 参数缺失
     NO_DATA = 11  # 数据不存在
     MISSION_TYPE_EOORE = 12  # 产品类型错误
@@ -15,7 +15,7 @@ class StatesCode:
 
 class TILE_GRID_TYPE:
     GoogleEarthQuad = "GoogleEarthQuad"
-    WGS1984Quad     = "WGS1984Quad"
+    WGS1984Quad = "WGS1984Quad"
     WebMercatorQuad = "WebMercatorQuad"
 
     ALL = [GoogleEarthQuad, WGS1984Quad, WebMercatorQuad, ]

+ 29 - 6
src/app/utils/utils.py

@@ -18,10 +18,10 @@ def get_directory_tree(path):
 
 
 def filter_file(item, condition):
-    if condition == '.tif':
-        result = os.path.splitext(item)[-1] == condition
+    # if condition == '.tif':
+    #     result = os.path.splitext(item)[-1] == condition
 
-    elif condition == 'tileset.json':
+    if condition == 'tileset.json':
         result = os.path.basename(item) == condition
 
     else:
@@ -30,18 +30,41 @@ def filter_file(item, condition):
     return result
 
 
+def path_replace(path, ext):
+    if ext == '.tif':
+        result = path
+    elif ext == 'tileset.json':
+        result = path.replace(config.common.TILESET_PATH, '')
+    else:
+        result = False
+
+    return result
+
+
 def dir_and_file_tree(path, ext, temp_list=[]):
     path_tree = os.listdir(path)  # 获取当前目录下的文件和目录
     for item in path_tree:
         subtree = path + '/' + item
         if os.path.isdir(subtree):  # 判断是否为目录
             x1 = []
-            item_dict = {'label': item, 'type': 'directory', 'value': path.replace(config.common.TILESET_PATH, ''),
-                         'children': x1}
+            item_dict = {
+                'label': item,
+                'type': 'directory',
+                'node': path_replace(path, ext),
+                'value': path_replace(subtree, ext),
+                'children': x1
+            }
             temp_list.append(item_dict)
             dir_and_file_tree(subtree, ext, x1)  # 递归深度优先遍历
         else:
             if filter_file(item, ext):
-                temp_list.append({'label': item, 'type': 'file', 'value': path.replace(config.common.TILESET_PATH, '')})
+                temp_list.append(
+                    {
+                        'label': item,
+                        'type': 'file',
+                        'node': path_replace(path, ext),
+                        'value': path_replace(subtree, ext)
+                    }
+                )
 
     return temp_list