This commit is contained in:
maxmon 2021-07-09 22:55:51 +08:00
commit 0b280bc42c
3 changed files with 12 additions and 8 deletions

1
be/.gitignore vendored
View File

@ -6,3 +6,4 @@ __pycache__
/app/projects/* /app/projects/*
!/app/projects/test/

View File

@ -66,7 +66,8 @@ def query_file():
def get_json(): def get_json():
ret_info = ReturnInfo() ret_info = ReturnInfo()
try: try:
project_name = request.args.get("projectName").strip()
project_name = request.args.get("projectName")
download_json = [] download_json = []
anno_data = read_json_file(PROJECT_PATH.format(project_name)+'/anno.json') anno_data = read_json_file(PROJECT_PATH.format(project_name)+'/anno.json')
for item in anno_data: for item in anno_data:
@ -98,9 +99,9 @@ def get_json():
# 本线默认目录时app下所以不需要再加/app了所以不能用PROJECT_PATH # 本线默认目录时app下所以不需要再加/app了所以不能用PROJECT_PATH
# 2.创建response对象返回数据 # 2.创建response对象返回数据
#使用response可以将result.json再删除掉 #使用response可以将result.json再删除掉
response = make_response(send_from_directory('', filename=DOWNLOAD_FILE_LOCATION.format(project_name), response = make_response(send_from_directory(directory='', path=DOWNLOAD_FILE_LOCATION.format(project_name),
as_attachment=True)) as_attachment=True))
response.headers["Content-disposition"] = 'attachment; filename={}_result.json'.format(project_name) response.headers["Content-disposition"] = 'attachment; filename=result.json'
# print(PROJECT_PATH.format(project_name)+'/result.json') # print(PROJECT_PATH.format(project_name)+'/result.json')
# os.remove(PROJECT_PATH.format(project_name)+'/result.json') # os.remove(PROJECT_PATH.format(project_name)+'/result.json')

View File

@ -34,15 +34,17 @@ def get_zipped_data():
# Put files in the folder directly under the project directory # Put files in the folder directly under the project directory
for item in os.listdir(target_path): for item in os.listdir(target_path):
# If item is a folder,copy files in item to project folder,then remove this folder # If item is a folder,copy files in item to project folder,then remove this folder
folder_path = target_path + '/' + item folder_path = target_path + '/' + item
if os.path.isdir(folder_path): if os.path.isdir(folder_path):
for file in os.listdir(folder_path): for file in os.listdir(folder_path):
shutil.copy(folder_path + '/' + file, folder_path + '/../') if file.split('.')[-1] == 'txt':
# Here to deal with chinese encode in module zipfile and rarfile shutil.copy(folder_path + '/' + file, folder_path + '/../')
if file_type == 'zip': # Here to deal with chinese encode in module zipfile and rarfile
os.rename(folder_path + '/../' + file, if file_type == 'zip':
folder_path + '/../' + file.encode('cp437').decode('GBK')) os.rename(folder_path + '/../' + file,
folder_path + '/../' + file.encode('cp437').decode('GBK'))
shutil.rmtree(folder_path) shutil.rmtree(folder_path)
except Exception as e: except Exception as e:
print(e) print(e)