fix: simplify workspace_file path check

This commit is contained in:
ymq 2026-08-12 10:50:16 +08:00
parent 39e6755e96
commit 2aed452e75

View File

@ -2,17 +2,13 @@
action = (params_kw or {}).get('action', 'read')
filepath = (params_kw or {}).get('path', '').strip()
workspace_base = '/d/pipeline/workspaces'
# 安全检查
if not filepath or not filepath.startswith(workspace_base):
return json.dumps({"error": "路径不合法"}, ensure_ascii=False)
import os
if not filepath or not os.path.isfile(filepath):
return json.dumps({"error": "文件不存在: " + filepath}, ensure_ascii=False)
if action == 'read':
if not os.path.isfile(filepath):
return json.dumps({"error": "文件不存在"}, ensure_ascii=False)
try:
with open(filepath, 'r', encoding='utf-8') as f:
content = f.read(50000)