change back

This commit is contained in:
Cai
2025-09-20 06:28:42 +00:00
parent 7d7ca83b71
commit b1f832a2fb

View File

@@ -12,8 +12,7 @@ def create_folder():
filepath = request.json.get('path', '') filepath = request.json.get('path', '')
path = session.get('path') path = session.get('path')
parent = request.json.get('parent', '') parent = request.json.get('parent', '')
root_workspace_path = current_app.config['ROOT_WORKSPACE_PATH'] base_path = f'{path}'
base_path = f'{root_workspace_path}/{path}'
filepath = f'{base_path}/{parent}/{filepath}' filepath = f'{base_path}/{parent}/{filepath}'
try: try:
os.makedirs(filepath) os.makedirs(filepath)
@@ -27,8 +26,7 @@ def create_file():
filepath = request.json.get('path', '') filepath = request.json.get('path', '')
path = session.get('path') path = session.get('path')
parent = request.json.get('parent', '') parent = request.json.get('parent', '')
root_workspace_path = current_app.config['ROOT_WORKSPACE_PATH'] base_path = f'{path}'
base_path = f'{root_workspace_path}/{path}'
filepath = f'{base_path}/{parent}/{filepath}' filepath = f'{base_path}/{parent}/{filepath}'
try: try:
open(filepath, 'w').close() open(filepath, 'w').close()
@@ -41,8 +39,7 @@ def rename_file():
user_root = session.get('path') user_root = session.get('path')
path = request.json.get('path', '') path = request.json.get('path', '')
new_name = request.json.get('newName', '') new_name = request.json.get('newName', '')
root_workspace_path = current_app.config['ROOT_WORKSPACE_PATH'] base_path = f'{user_root}'
base_path = f'{root_workspace_path}/{user_root}'
filepath = f'{base_path}/{path}' filepath = f'{base_path}/{path}'
try: try:
path_list = filepath.split('/') path_list = filepath.split('/')
@@ -58,8 +55,7 @@ def rename_folder():
user_root = session.get('path') user_root = session.get('path')
path = request.json.get('path', '') path = request.json.get('path', '')
new_name = request.json.get('newName', '') new_name = request.json.get('newName', '')
root_workspace_path = current_app.config['ROOT_WORKSPACE_PATH'] base_path = f'{user_root}'
base_path = f'{root_workspace_path}/{user_root}'
folderpath = f'{base_path}/{path}' folderpath = f'{base_path}/{path}'
try: try:
path_list = folderpath.split('/') path_list = folderpath.split('/')
@@ -74,9 +70,8 @@ def rename_folder():
def copy_files(): def copy_files():
old_path = request.json.get('oldPath', '') old_path = request.json.get('oldPath', '')
new_path = request.json.get('newPath', '') new_path = request.json.get('newPath', '')
root_workspace_path = current_app.config['ROOT_WORKSPACE_PATH']
user_root = session.get('path') user_root = session.get('path')
base_path = f'{root_workspace_path}/{user_root}' base_path = f'{user_root}'
old_path = f'{base_path}/{old_path}' old_path = f'{base_path}/{old_path}'
new_path = f'{base_path}/{new_path}' new_path = f'{base_path}/{new_path}'
# oldpath的父目录就是newpath的话,对oldpath进行重命名 # oldpath的父目录就是newpath的话,对oldpath进行重命名
@@ -106,9 +101,8 @@ def copy_files():
@file_bp.route('/delete-file', methods=['POST']) @file_bp.route('/delete-file', methods=['POST'])
def delete_file(): def delete_file():
path = request.json.get('path', '') path = request.json.get('path', '')
root_workspace_path = current_app.config['ROOT_WORKSPACE_PATH']
user_root = session.get('path') user_root = session.get('path')
base_path = f'{root_workspace_path}/{user_root}' base_path = f'{user_root}'
filepath = f'{base_path}/{path}' filepath = f'{base_path}/{path}'
if os.path.isdir(filepath): if os.path.isdir(filepath):
shutil.rmtree(filepath) shutil.rmtree(filepath)
@@ -119,8 +113,7 @@ def delete_file():
@file_bp.route('/file-content', methods=['POST']) @file_bp.route('/file-content', methods=['POST'])
def file_content(): def file_content():
path = session.get('path') path = session.get('path')
root_workspace_path = current_app.config['ROOT_WORKSPACE_PATH'] base_path = f'{path}'
base_path = f'{root_workspace_path}/{path}'
filepath = request.json.get('path', '') filepath = request.json.get('path', '')
filepath = f'{base_path}/{filepath}' filepath = f'{base_path}/{filepath}'
if not os.path.exists(filepath): if not os.path.exists(filepath):
@@ -135,8 +128,7 @@ def file_content():
@file_bp.route('/save-file', methods=['POST']) @file_bp.route('/save-file', methods=['POST'])
def save_file(): def save_file():
path = session.get('path') path = session.get('path')
root_workspace_path = current_app.config['ROOT_WORKSPACE_PATH'] base_path = f'{path}'
base_path = f'{root_workspace_path}/{path}'
filepath = request.json.get('path', '') filepath = request.json.get('path', '')
filepath = f'{base_path}/{filepath}' filepath = f'{base_path}/{filepath}'
content = request.json.get('content', '') content = request.json.get('content', '')
@@ -155,8 +147,7 @@ def file_tree():
user_id = session.get('user_id') user_id = session.get('user_id')
if not path: if not path:
return jsonify({"error": "Missing path parameter"}), 400 return jsonify({"error": "Missing path parameter"}), 400
root_workspace_path = current_app.config['ROOT_WORKSPACE_PATH'] base_path = os.path.join(user_id, path)
base_path = os.path.join(root_workspace_path, user_id, path)
print(base_path) print(base_path)
if not os.path.exists(base_path): if not os.path.exists(base_path):