fix: workspace path with org_id
This commit is contained in:
parent
5ccaba3505
commit
454eaed30c
@ -8,7 +8,6 @@ dbname = get_module_dbname('pipeline-sdlc')
|
|||||||
workspace_base = '/d/pipeline/workspaces'
|
workspace_base = '/d/pipeline/workspaces'
|
||||||
|
|
||||||
async with DBPools().sqlorContext(dbname) as sor:
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
# 获取当前项目和工作空间目录
|
|
||||||
recs = await sor.sqlExe(
|
recs = await sor.sqlExe(
|
||||||
"SELECT current_project_id FROM pipeline_agent_settings WHERE user_id=${u}$",
|
"SELECT current_project_id FROM pipeline_agent_settings WHERE user_id=${u}$",
|
||||||
{"u": uid})
|
{"u": uid})
|
||||||
@ -17,48 +16,46 @@ async with DBPools().sqlorContext(dbname) as sor:
|
|||||||
ws_dir = ''
|
ws_dir = ''
|
||||||
if pid:
|
if pid:
|
||||||
proj = await sor.sqlExe(
|
proj = await sor.sqlExe(
|
||||||
"SELECT name, workspace_dir FROM sd_projects WHERE id=${p}$",
|
"SELECT name, org_id, workspace_dir FROM sd_projects WHERE id=${p}$",
|
||||||
{"p": pid})
|
{"p": pid})
|
||||||
if proj:
|
if proj:
|
||||||
pname = getattr(proj[0], 'name', '')
|
pname = getattr(proj[0], 'name', '')
|
||||||
|
org_id = getattr(proj[0], 'org_id', '0') or '0'
|
||||||
ws = getattr(proj[0], 'workspace_dir', '') or ''
|
ws = getattr(proj[0], 'workspace_dir', '') or ''
|
||||||
ws_dir = ws if ws.startswith('/') else workspace_base + '/' + pname
|
if ws and ws.startswith('/'):
|
||||||
|
ws_dir = ws
|
||||||
|
else:
|
||||||
|
ws_dir = workspace_base + '/' + org_id + '/' + pname
|
||||||
|
|
||||||
# 安全限制
|
if not ws_dir or not os.path.isdir(ws_dir):
|
||||||
if not ws_dir or not ws_dir.startswith(workspace_base):
|
return json.dumps({"error": "工作空间不存在: " + ws_dir, "tree": {"name": "", "children": [], "files": []}}, ensure_ascii=False)
|
||||||
return json.dumps({"error": "工作空间不可用"}, ensure_ascii=False)
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
def build_tree(path, base):
|
def build_tree(path):
|
||||||
"""递归构建目录树"""
|
result = {"name": os.path.basename(path) or path, "path": path, "children": [], "files": []}
|
||||||
result = {"name": os.path.basename(path) or path, "path": path, "children": []}
|
|
||||||
try:
|
try:
|
||||||
items = sorted(os.listdir(path))
|
items = sorted(os.listdir(path))
|
||||||
except Exception:
|
except Exception:
|
||||||
return result
|
return result
|
||||||
|
|
||||||
dirs = []
|
|
||||||
files = []
|
|
||||||
for item in items:
|
for item in items:
|
||||||
full = os.path.join(path, item)
|
full = os.path.join(path, item)
|
||||||
if os.path.isdir(full) and not item.startswith('.') and item != '__pycache__':
|
if os.path.isdir(full) and not item.startswith('.') and item != '__pycache__':
|
||||||
dirs.append(build_tree(full, base))
|
result["children"].append(build_tree(full))
|
||||||
elif os.path.isfile(full) and not item.startswith('.'):
|
elif os.path.isfile(full) and not item.startswith('.'):
|
||||||
size = os.path.getsize(full)
|
size = os.path.getsize(full)
|
||||||
ext = os.path.splitext(item)[1].lower()
|
ext = os.path.splitext(item)[1].lower()
|
||||||
files.append({
|
result["files"].append({
|
||||||
"name": item, "path": full, "size": size, "ext": ext,
|
"name": item, "path": full, "size": size, "ext": ext,
|
||||||
"is_text": ext in ['.md','.py','.js','.html','.css','.json','.txt',
|
"is_text": ext in ['.md','.py','.js','.html','.css','.json','.txt',
|
||||||
'.xml','.yaml','.yml','.toml','.cfg','.sh','.sql',
|
'.xml','.yaml','.yml','.toml','.cfg','.sh','.sql',
|
||||||
'.dspy','.ui','.java','.go','.rs','.ts','.tsx','.vue'],
|
'.dspy','.ui','.java','.go','.rs','.ts','.tsx','.vue'],
|
||||||
"is_media": ext in ['.png','.jpg','.jpeg','.gif','.svg','.mp4','.webm','.mp3','.wav'],
|
"is_media": ext in ['.png','.jpg','.jpeg','.gif','.svg','.mp4','.webm','.mp3','.wav'],
|
||||||
})
|
})
|
||||||
result["children"] = dirs
|
|
||||||
result["files"] = files
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
tree = build_tree(ws_dir, ws_dir)
|
tree = build_tree(ws_dir)
|
||||||
|
|
||||||
return json.dumps({
|
return json.dumps({
|
||||||
"workspace": ws_dir,
|
"workspace": ws_dir,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user