fix: simplify workspace_file path check
This commit is contained in:
parent
39e6755e96
commit
2aed452e75
@ -2,17 +2,13 @@
|
|||||||
|
|
||||||
action = (params_kw or {}).get('action', 'read')
|
action = (params_kw or {}).get('action', 'read')
|
||||||
filepath = (params_kw or {}).get('path', '').strip()
|
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
|
import os
|
||||||
|
|
||||||
|
if not filepath or not os.path.isfile(filepath):
|
||||||
|
return json.dumps({"error": "文件不存在: " + filepath}, ensure_ascii=False)
|
||||||
|
|
||||||
if action == 'read':
|
if action == 'read':
|
||||||
if not os.path.isfile(filepath):
|
|
||||||
return json.dumps({"error": "文件不存在"}, ensure_ascii=False)
|
|
||||||
try:
|
try:
|
||||||
with open(filepath, 'r', encoding='utf-8') as f:
|
with open(filepath, 'r', encoding='utf-8') as f:
|
||||||
content = f.read(50000)
|
content = f.read(50000)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user