workspace: tree lazy-load with id param
This commit is contained in:
parent
f106d330a4
commit
340dcf0fd0
@ -1,4 +1,8 @@
|
|||||||
# workspace_tree.dspy - 只返回目录树,不含文件
|
# workspace_tree.dspy - 返回目录子节点(支持 id 参数做懒加载)
|
||||||
|
|
||||||
|
import os
|
||||||
|
|
||||||
|
node_id = (params_kw or {}).get('id', '').strip()
|
||||||
|
|
||||||
uid = await get_user()
|
uid = await get_user()
|
||||||
if not uid:
|
if not uid:
|
||||||
@ -6,7 +10,6 @@ if not uid:
|
|||||||
|
|
||||||
dbname = get_module_dbname('pipeline-sdlc')
|
dbname = get_module_dbname('pipeline-sdlc')
|
||||||
workspace_base = '/d/pipeline/workspaces'
|
workspace_base = '/d/pipeline/workspaces'
|
||||||
import os
|
|
||||||
|
|
||||||
async with DBPools().sqlorContext(dbname) as sor:
|
async with DBPools().sqlorContext(dbname) as sor:
|
||||||
recs = await sor.sqlExe(
|
recs = await sor.sqlExe(
|
||||||
@ -26,29 +29,50 @@ async with DBPools().sqlorContext(dbname) as sor:
|
|||||||
ws_dir = ws if ws.startswith('/') else workspace_base + '/' + org_id + '/' + pname
|
ws_dir = ws if ws.startswith('/') else workspace_base + '/' + org_id + '/' + pname
|
||||||
|
|
||||||
if not ws_dir or not os.path.isdir(ws_dir):
|
if not ws_dir or not os.path.isdir(ws_dir):
|
||||||
return [{"id": "__root__", "parentid": "", "label": "📁 工作空间(不可用)", "path": ""}]
|
if not node_id or node_id == '__root__':
|
||||||
|
return [{"id": "__root__", "parentid": "", "label": "📁 工作空间(不可用)", "path": "", "is_leaf": False}]
|
||||||
|
return []
|
||||||
|
|
||||||
items = [{"id": "__root__", "parentid": "", "label": "📁 " + os.path.basename(ws_dir), "path": ws_dir, "is_leaf": False}]
|
# 确定要扫描的目录
|
||||||
|
if not node_id or node_id == '__root__':
|
||||||
|
# 初始加载:返回根节点
|
||||||
|
return [{
|
||||||
|
"id": "__root__",
|
||||||
|
"parentid": "",
|
||||||
|
"label": "📁 " + os.path.basename(ws_dir),
|
||||||
|
"path": ws_dir,
|
||||||
|
"is_leaf": False
|
||||||
|
}]
|
||||||
|
|
||||||
def scan_dir(path, parent_id, rel_prefix):
|
# 展开节点:返回该目录的直接子目录
|
||||||
try:
|
if node_id == '__root__':
|
||||||
entries = sorted(os.listdir(path))
|
scan_path = ws_dir
|
||||||
except Exception:
|
rel_prefix = ""
|
||||||
return
|
else:
|
||||||
for name in entries:
|
scan_path = ws_dir + '/' + node_id
|
||||||
full = os.path.join(path, name)
|
rel_prefix = node_id
|
||||||
if name.startswith('.') or name == '__pycache__':
|
|
||||||
continue
|
if not os.path.isdir(scan_path):
|
||||||
if os.path.isdir(full):
|
return []
|
||||||
rel_path = rel_prefix + '/' + name if rel_prefix else name
|
|
||||||
items.append({
|
items = []
|
||||||
"id": rel_path,
|
try:
|
||||||
"parentid": parent_id,
|
entries = sorted(os.listdir(scan_path))
|
||||||
"label": "📁 " + name,
|
except Exception:
|
||||||
"path": full,
|
return []
|
||||||
"is_leaf": False
|
|
||||||
})
|
for name in entries:
|
||||||
scan_dir(full, rel_path, rel_path)
|
full = os.path.join(scan_path, name)
|
||||||
|
if name.startswith('.') or name == '__pycache__':
|
||||||
|
continue
|
||||||
|
if os.path.isdir(full):
|
||||||
|
rel_path = rel_prefix + '/' + name if rel_prefix else name
|
||||||
|
items.append({
|
||||||
|
"id": rel_path,
|
||||||
|
"parentid": node_id,
|
||||||
|
"label": "📁 " + name,
|
||||||
|
"path": full,
|
||||||
|
"is_leaf": False
|
||||||
|
})
|
||||||
|
|
||||||
scan_dir(ws_dir, "__root__", "")
|
|
||||||
return items
|
return items
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user