From dec3115831d09c95261ce522f5f2b2e0f1bdd0c6 Mon Sep 17 00:00:00 2001 From: maxmon <541182180@qq.com> Date: Sun, 16 Apr 2023 17:45:16 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=94=AF=E6=8C=81=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E6=8D=A2=E8=A1=8C=E5=88=86=E5=89=B2=E7=9A=84.txt=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- be/app/api/v1/project.py | 31 +++++++++++++++++++++++++++++++ fe/src/components/home/index.vue | 4 +++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/be/app/api/v1/project.py b/be/app/api/v1/project.py index b84e53e..033213f 100644 --- a/be/app/api/v1/project.py +++ b/be/app/api/v1/project.py @@ -102,6 +102,37 @@ def get_jsonl_data(): return json.dumps(ret_info, default=lambda o: o.__dict__) +@api.route('/get_txt_data', methods=['POST']) +def get_txt_data(): + ret_info = ReturnInfo() + try: + project_name = request.form.get('projectName') + + upload_file = request.files['file'] + file_path = os.path.join(PROJECT_PATH.format(project_name), upload_file.filename) + file_name = upload_file.filename.replace('.txt', '') + target_path = PROJECT_PATH.format(project_name) + '/data' + upload_file.save(file_path) + + with open(file_path, 'r', encoding='utf-8') as fh: + l = fh.readline().strip() + idx = 0 + while l: + idx += 1 + _idx = ('000000'+str(idx))[-6:] + if len(str(idx)) > 6: + _idx = str(idx) + open(f'{target_path}/{file_name}_{_idx}', 'w', encoding='utf-8').write(l) + l = fh.readline().strip() + os.remove(file_path) + + except Exception as e: + print(e) + ret_info.errCode = 404 + ret_info.errMsg = str(e) + + return json.dumps(ret_info, default=lambda o: o.__dict__) + @api.route('/create', methods=['POST']) def create_project(): diff --git a/fe/src/components/home/index.vue b/fe/src/components/home/index.vue index bb23d80..a807512 100644 --- a/fe/src/components/home/index.vue +++ b/fe/src/components/home/index.vue @@ -53,7 +53,7 @@

上传文本:

(请选择包含文本文件的zip、tar文件)

- +

@@ -178,6 +178,8 @@ export default { form('/v1/project/get_zipped_data', formData) } else if (file.name.endsWith('.jsonl')) { form('/v1/project/get_jsonl_data', formData) + } else if (file.name.endsWith('.txt')) { + form('/v1/project/get_txt_data', formData) } } })