diff --git a/be/app/api/v1/project.py b/be/app/api/v1/project.py index b84f6b7..92e71d7 100644 --- a/be/app/api/v1/project.py +++ b/be/app/api/v1/project.py @@ -7,7 +7,7 @@ from ...libs.redprint import RedPrint from flask import request import json import os -from ...libs.tools import make_dir, write_json, read_json_file, unzip_file +from ...libs.tools import make_dir, write_json, read_json_file, unzip_file, get_cn_name from ...entities.entities import Project, ReturnInfo @@ -57,8 +57,8 @@ def get_zipped_data(): shutil.copy(folder_path + '/' + file, folder_path + '/../') # Here to deal with chinese encode in module zipfile and rarfile if file_type == 'zip': - os.rename(folder_path + '/../' + file, - folder_path + '/../' + file.encode('cp437').decode('GBK')) + os.replace(folder_path + '/../' + file, + folder_path + '/../' + get_cn_name(file)) shutil.rmtree(folder_path) except Exception as e: print(e) diff --git a/be/app/libs/tools.py b/be/app/libs/tools.py index b450f0d..6c48dab 100644 --- a/be/app/libs/tools.py +++ b/be/app/libs/tools.py @@ -10,6 +10,11 @@ from os import listdir from shutil import move import base64 +def get_cn_name(name): + try: + return name.encode('cp437').decode('GBK') + except: + return name def make_dir(path): folder = os.path.exists(path) @@ -72,6 +77,8 @@ def unzip_file(zip_src, dst_dir): fz = zipfile.ZipFile(zip_src, "r") for file in fz.namelist(): fz.extract(file, dst_dir) + # Here to deal with chinese encode in module zipfile and rarfile + os.replace(dst_dir + '/' + file, dst_dir + '/' + get_cn_name(file)) return "unzip .zip file success" # elif rarfile.is_rarfile(zip_src): # fr = rarfile.RarFile(zip_src, "r")