feat: 知识库递归导入(从指定父节点,不需要空间权限)
- feishu_service.py: import_space_nodes 改为 import_nodes_from_parent 从指定父节点递归获取子节点,不需要空间级别权限 - admin_knowledge.py: import API 增加 parent_node_token 参数 - api.ts/App.vue: 前端增加父节点 NodeToken 输入框
This commit is contained in:
@@ -330,6 +330,49 @@ class FeishuKnowledgeService:
|
||||
cls._content_cache.clear()
|
||||
return count
|
||||
|
||||
@classmethod
|
||||
def import_nodes_from_parent(
|
||||
cls,
|
||||
space_id: str,
|
||||
parent_node_token: str,
|
||||
db: Session | None = None,
|
||||
) -> list[dict]:
|
||||
"""从指定节点递归获取所有子节点,用于批量导入知识库。
|
||||
不需要空间级别权限,只需要对 parent_node_token 所在节点有查看权限。
|
||||
"""
|
||||
config = _feishu_retrieval_config(db)
|
||||
if not config.app_id or not config.app_secret:
|
||||
raise ExternalServiceError(
|
||||
"未配置飞书应用凭证,无法读取飞书知识库。",
|
||||
provider="feishu",
|
||||
)
|
||||
|
||||
all_nodes: list[dict] = []
|
||||
visited: set[str] = set()
|
||||
|
||||
def _fetch_children(parent_token: str) -> None:
|
||||
try:
|
||||
children = _get_wiki_children(space_id, parent_token, config)
|
||||
except ExternalServiceError:
|
||||
return
|
||||
for child in children:
|
||||
node_token = child.get("node_token", "")
|
||||
if not node_token or node_token in visited:
|
||||
continue
|
||||
visited.add(node_token)
|
||||
all_nodes.append({
|
||||
"name": child.get("title", node_token),
|
||||
"node_token": node_token,
|
||||
"space_id": space_id,
|
||||
"obj_type": child.get("obj_type", ""),
|
||||
"parent_token": parent_token,
|
||||
})
|
||||
if child.get("has_child", False):
|
||||
_fetch_children(node_token)
|
||||
|
||||
_fetch_children(parent_node_token)
|
||||
return all_nodes
|
||||
|
||||
@classmethod
|
||||
def retrieve(
|
||||
cls,
|
||||
|
||||
Reference in New Issue
Block a user