From 008eb77f9956cff2d8389693ef62c6528eac9003 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Paulius=20Preik=C5=A1a?= Date: Mon, 24 Jun 2024 14:18:51 +0300 Subject: [PATCH] fix: fixed BE file handling --- GUI/back-end/routes/workspace.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/GUI/back-end/routes/workspace.py b/GUI/back-end/routes/workspace.py index 3e365a5..5c44418 100644 --- a/GUI/back-end/routes/workspace.py +++ b/GUI/back-end/routes/workspace.py @@ -43,23 +43,27 @@ def delete_workspace(workspace): else: return make_response(jsonify({'message': 'Workspace not found!'}), 404) -@route_workspace_bp.route('/workspace//file', methods=['POST']) -def upload_file(workspace): +@route_workspace_bp.route('/workspace/file/upload', methods=['POST']) +def upload_file(): + workspace = request.form.get('workspace') + filename = request.form.get('file_name') if 'file' not in request.files: return make_response(jsonify({'message': 'No file part in the request'}), 400) file = request.files['file'] - if file.filename == '': + if filename == '': return make_response(jsonify({'message': 'No file selected for uploading'}), 400) - if not re.match(FILENAME_REGEX, file.filename): + if not re.match(FILENAME_REGEX, filename): return make_response(jsonify({'message': 'Invalid file name!'}), 400) if not os.path.exists(f"{PATH_TO_WORKSPACE}/{workspace}"): return make_response(jsonify({'message': 'Workspace not found!'}), 404) + file.filename = filename + if file and file.filename.endswith('.txt'): path = f"{PATH_TO_WORKSPACE}/{workspace}/{file.filename}" file.save(path) @@ -67,9 +71,10 @@ def upload_file(workspace): return make_response(jsonify({'message': 'File must be a .txt file'}), 400) -@route_workspace_bp.route('/workspace//file', methods=['DELETE']) -def delete_file(workspace): +@route_workspace_bp.route('/workspace/file/delete', methods=['DELETE']) +def delete_file(): file_name = request.json.get('file_name') + workspace = request.json.get('workspace') if not re.match(FILENAME_REGEX, file_name): return make_response(jsonify({'message': 'Invalid file name!'}), 400)