main #2
@ -50,7 +50,7 @@ def _get_team_user_names(apps):
|
||||
|
||||
|
||||
@jingrow.whitelist(allow_guest=True)
|
||||
def get_local_apps(filters=None, order_by=None, limit_start=None, limit_page_length=None):
|
||||
def get_local_app_list(filters=None, order_by=None, limit_start=None, limit_page_length=None):
|
||||
"""获取本地应用列表"""
|
||||
|
||||
# 构建查询条件
|
||||
@ -359,6 +359,110 @@ def get_my_local_node_list(filters=None, order_by=None, limit_start=None, limit_
|
||||
return result
|
||||
|
||||
|
||||
@jingrow.whitelist(allow_guest=True)
|
||||
def get_local_node(name):
|
||||
"""获取本地节点详情"""
|
||||
|
||||
if not jingrow.db.exists("Local Node", name):
|
||||
return {"success": False, "message": "节点不存在"}
|
||||
|
||||
node = jingrow.get_pg("Local Node", name)
|
||||
|
||||
# 获取团队关联用户的名称
|
||||
team_user_names = _get_team_user_names([node])
|
||||
|
||||
node_data = {
|
||||
"name": node.name,
|
||||
"node_type": node.node_type,
|
||||
"title": node.title,
|
||||
"subtitle": node.subtitle,
|
||||
"description": node.description,
|
||||
"enabled": node.enabled,
|
||||
"public": node.public,
|
||||
"team": team_user_names.get(node.team),
|
||||
"status": node.status,
|
||||
"repository_url": node.repository_url,
|
||||
"file_url": node.file_url,
|
||||
"node_image": node.node_image,
|
||||
"creation": node.creation,
|
||||
"modified": node.modified
|
||||
}
|
||||
|
||||
return node_data
|
||||
|
||||
|
||||
@dashboard_whitelist()
|
||||
def create_local_node(node_data):
|
||||
"""创建本地节点"""
|
||||
team = get_current_team()
|
||||
|
||||
if isinstance(node_data, str):
|
||||
import json
|
||||
node_data = json.loads(node_data)
|
||||
|
||||
# 检查节点类型是否已存在
|
||||
existing_node = jingrow.db.exists("Local Node", {"node_type": node_data["node_type"]})
|
||||
if existing_node:
|
||||
return {"error": "节点类型已存在,请使用其他类型"}
|
||||
|
||||
# 创建节点
|
||||
node = jingrow.get_pg({
|
||||
"pagetype": "Local Node",
|
||||
"node_type": node_data["node_type"],
|
||||
"title": node_data["title"],
|
||||
"subtitle": node_data.get("subtitle", ""),
|
||||
"description": node_data.get("description", ""),
|
||||
"team": team,
|
||||
"repository_url": node_data.get("repository_url"),
|
||||
"file_url": node_data.get("file_url"),
|
||||
"node_image": node_data.get("node_image")
|
||||
})
|
||||
|
||||
node.insert()
|
||||
return {"success": True, "name": node.name, "message": "节点创建成功"}
|
||||
|
||||
|
||||
@dashboard_whitelist()
|
||||
def update_local_node(name, node_data):
|
||||
"""更新本地节点"""
|
||||
|
||||
team = get_current_team()
|
||||
if not team:
|
||||
return {"success": False, "message": "未找到当前团队信息"}
|
||||
|
||||
if not jingrow.db.exists("Local Node", name):
|
||||
return {"success": False, "message": "节点不存在"}
|
||||
|
||||
node = jingrow.get_pg("Local Node", name)
|
||||
|
||||
# 验证权限:只能更新自己团队的节点
|
||||
if node.team != team:
|
||||
return {"success": False, "message": "您没有权限操作此节点"}
|
||||
|
||||
# 解析 JSON 数据
|
||||
if isinstance(node_data, str):
|
||||
try:
|
||||
import json
|
||||
node_data = json.loads(node_data)
|
||||
except json.JSONDecodeError:
|
||||
return {"success": False, "message": "JSON 数据格式错误"}
|
||||
|
||||
# 更新字段
|
||||
updated_fields = []
|
||||
for field, value in node_data.items():
|
||||
if hasattr(node, field):
|
||||
setattr(node, field, value)
|
||||
updated_fields.append(field)
|
||||
|
||||
# 检查是否有字段被更新
|
||||
if not updated_fields:
|
||||
return {"success": False, "message": "没有有效的字段被更新"}
|
||||
|
||||
# 使用 ignore_permissions=True 因为我们已经手动验证了团队权限
|
||||
node.save(ignore_permissions=True)
|
||||
return {"success": True, "name": node.name, "updated_fields": updated_fields, "message": "节点更新成功"}
|
||||
|
||||
|
||||
@dashboard_whitelist()
|
||||
def get_my_local_agent_list(filters=None, order_by=None, limit_start=None, limit_page_length=None):
|
||||
"""获取当前团队的Agent列表"""
|
||||
@ -420,6 +524,110 @@ def get_my_local_agent_list(filters=None, order_by=None, limit_start=None, limit
|
||||
return result
|
||||
|
||||
|
||||
@jingrow.whitelist(allow_guest=True)
|
||||
def get_local_agent(name):
|
||||
"""获取本地Agent详情"""
|
||||
|
||||
if not jingrow.db.exists("Local Agent", name):
|
||||
return {"success": False, "message": "Agent不存在"}
|
||||
|
||||
agent = jingrow.get_pg("Local Agent", name)
|
||||
|
||||
# 获取团队关联用户的名称
|
||||
team_user_names = _get_team_user_names([agent])
|
||||
|
||||
agent_data = {
|
||||
"name": agent.name,
|
||||
"agent_name": agent.agent_name,
|
||||
"title": agent.title,
|
||||
"subtitle": agent.subtitle,
|
||||
"description": agent.description,
|
||||
"enabled": agent.enabled,
|
||||
"public": agent.public,
|
||||
"team": team_user_names.get(agent.team),
|
||||
"status": agent.status,
|
||||
"repository_url": agent.repository_url,
|
||||
"file_url": agent.file_url,
|
||||
"agent_image": agent.agent_image,
|
||||
"creation": agent.creation,
|
||||
"modified": agent.modified
|
||||
}
|
||||
|
||||
return agent_data
|
||||
|
||||
|
||||
@dashboard_whitelist()
|
||||
def create_local_agent(agent_data):
|
||||
"""创建本地Agent"""
|
||||
team = get_current_team()
|
||||
|
||||
if isinstance(agent_data, str):
|
||||
import json
|
||||
agent_data = json.loads(agent_data)
|
||||
|
||||
# 检查Agent名称是否已存在
|
||||
existing_agent = jingrow.db.exists("Local Agent", {"agent_name": agent_data["agent_name"]})
|
||||
if existing_agent:
|
||||
return {"error": "Agent名称已存在,请使用其他名称"}
|
||||
|
||||
# 创建Agent
|
||||
agent = jingrow.get_pg({
|
||||
"pagetype": "Local Agent",
|
||||
"agent_name": agent_data["agent_name"],
|
||||
"title": agent_data["title"],
|
||||
"subtitle": agent_data.get("subtitle", ""),
|
||||
"description": agent_data.get("description", ""),
|
||||
"team": team,
|
||||
"repository_url": agent_data.get("repository_url"),
|
||||
"file_url": agent_data.get("file_url"),
|
||||
"agent_image": agent_data.get("agent_image")
|
||||
})
|
||||
|
||||
agent.insert()
|
||||
return {"success": True, "name": agent.name, "message": "Agent创建成功"}
|
||||
|
||||
|
||||
@dashboard_whitelist()
|
||||
def update_local_agent(name, agent_data):
|
||||
"""更新本地Agent"""
|
||||
|
||||
team = get_current_team()
|
||||
if not team:
|
||||
return {"success": False, "message": "未找到当前团队信息"}
|
||||
|
||||
if not jingrow.db.exists("Local Agent", name):
|
||||
return {"success": False, "message": "Agent不存在"}
|
||||
|
||||
agent = jingrow.get_pg("Local Agent", name)
|
||||
|
||||
# 验证权限:只能更新自己团队的Agent
|
||||
if agent.team != team:
|
||||
return {"success": False, "message": "您没有权限操作此Agent"}
|
||||
|
||||
# 解析 JSON 数据
|
||||
if isinstance(agent_data, str):
|
||||
try:
|
||||
import json
|
||||
agent_data = json.loads(agent_data)
|
||||
except json.JSONDecodeError:
|
||||
return {"success": False, "message": "JSON 数据格式错误"}
|
||||
|
||||
# 更新字段
|
||||
updated_fields = []
|
||||
for field, value in agent_data.items():
|
||||
if hasattr(agent, field):
|
||||
setattr(agent, field, value)
|
||||
updated_fields.append(field)
|
||||
|
||||
# 检查是否有字段被更新
|
||||
if not updated_fields:
|
||||
return {"success": False, "message": "没有有效的字段被更新"}
|
||||
|
||||
# 使用 ignore_permissions=True 因为我们已经手动验证了团队权限
|
||||
agent.save(ignore_permissions=True)
|
||||
return {"success": True, "name": agent.name, "updated_fields": updated_fields, "message": "Agent更新成功"}
|
||||
|
||||
|
||||
@dashboard_whitelist()
|
||||
def delete_local_node(name):
|
||||
"""删除本地节点"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user