import json import os.path import traceback from flask import request, jsonify from flask_restx import Resource, Namespace, reqparse from app.defines import StatesCode from app.utils.utils import dir_and_file_tree, get_directory_tree from config import Config ns = Namespace('file', description='文件管理 API接口') config = Config() files_parser = reqparse.RequestParser(bundle_errors=True) files_parser.add_argument(name='type', type=str, location='args', required=False, help='数据类型 :tif、3Dtiles') @ns.route('/get_files') class GetFilesApi(Resource): @ns.doc(id='get_files', description='获取原始数据目录文件列表') @ns.expect(files_parser) def get(self): try: type = request.args.get('type') if type == 'tif': path = config.common.IMAGE_PATH ext = '.tif' elif type == '3Dtiles': path = config.common.TILESET_PATH ext = 'tileset.json' else: return jsonify(code=StatesCode.PARA_ERROR, message='数据类型错误') structure = dir_and_file_tree(path, ext, []) return jsonify(code=StatesCode.SUCCESS, message='获取成功', data=structure) except Exception as e: traceback.print_exc() return {'code': StatesCode.UNKNOWN_ERROR, 'message': str(e)}