From ba73ade2a04c50a300405a1846aa29be7a62cbf7 Mon Sep 17 00:00:00 2001 From: lixiangcheng1 Date: Fri, 6 Feb 2026 18:18:15 +0800 Subject: [PATCH] [ADD]Develop APIs and add knowledge base interfaces:Three party synchronization --- api/app/controllers/knowledge_controller.py | 6 +- .../service/rag_api_knowledge_controller.py | 70 +++++++++++++++++++ 2 files changed, 73 insertions(+), 3 deletions(-) diff --git a/api/app/controllers/knowledge_controller.py b/api/app/controllers/knowledge_controller.py index 01f89a3d..74b832cd 100644 --- a/api/app/controllers/knowledge_controller.py +++ b/api/app/controllers/knowledge_controller.py @@ -509,7 +509,7 @@ async def check_yuque_auth( async with api_client as client: repos = await client.get_user_repos() if repos: - return success(data=repos, msg="Successfully auth yuque info") + return success(msg="Successfully auth yuque info") return fail(BizCode.UNAUTHORIZED, msg="auth yuque info failed", error="user_id or token is incorrect") except HTTPException: raise @@ -519,7 +519,7 @@ async def check_yuque_auth( @router.get("/check/feishu/auth", response_model=ApiResponse) -async def check_yuque_auth( +async def check_feishu_auth( feishu_app_id: str, feishu_app_secret: str, feishu_folder_token: str, @@ -539,7 +539,7 @@ async def check_yuque_auth( async with api_client as client: files = await client.list_all_folder_files(feishu_folder_token, recursive=True) if files: - return success(data=files, msg="Successfully auth feishu info") + return success(msg="Successfully auth feishu info") return fail(BizCode.UNAUTHORIZED, msg="auth feishu info failed", error="app_id or app_secret or feishu_folder_token is incorrect") except HTTPException: raise diff --git a/api/app/controllers/service/rag_api_knowledge_controller.py b/api/app/controllers/service/rag_api_knowledge_controller.py index 72c4a1b5..cec53a65 100644 --- a/api/app/controllers/service/rag_api_knowledge_controller.py +++ b/api/app/controllers/service/rag_api_knowledge_controller.py @@ -246,3 +246,73 @@ async def rebuild_knowledge_graph( db=db, current_user=current_user) + +@router.get("/check/yuque/auth", response_model=ApiResponse) +@require_api_key(scopes=["rag"]) +async def check_yuque_auth( + yuque_user_id: str, + yuque_token: str, + request: Request, + api_key_auth: ApiKeyAuth = None, + db: Session = Depends(get_db), +): + """ + check yuque auth info + """ + api_key = api_key_service.ApiKeyService.get_api_key(db, api_key_auth.api_key_id, api_key_auth.workspace_id) + current_user = api_key.creator + current_user.current_workspace_id = api_key_auth.workspace_id + + api_logger.info(f"check yuque auth info, username: {current_user.username}") + + return await knowledge_controller.check_yuque_auth(yuque_user_id=yuque_user_id, + yuque_token=yuque_token, + db=db, + current_user=current_user) + + +@router.get("/check/feishu/auth", response_model=ApiResponse) +@require_api_key(scopes=["rag"]) +async def check_feishu_auth( + feishu_app_id: str, + feishu_app_secret: str, + feishu_folder_token: str, + request: Request, + api_key_auth: ApiKeyAuth = None, + db: Session = Depends(get_db), +): + """ + check feishu auth info + """ + api_key = api_key_service.ApiKeyService.get_api_key(db, api_key_auth.api_key_id, api_key_auth.workspace_id) + current_user = api_key.creator + current_user.current_workspace_id = api_key_auth.workspace_id + + api_logger.info(f"check feishu auth info, username: {current_user.username}") + + return await knowledge_controller.check_feishu_auth(feishu_app_id=feishu_app_id, + feishu_app_secret=feishu_app_secret, + feishu_folder_token=feishu_folder_token, + db=db, + current_user=current_user) + + +@router.post("/{knowledge_id}/sync", response_model=ApiResponse) +@require_api_key(scopes=["rag"]) +async def sync_knowledge( + knowledge_id: uuid.UUID, + request: Request, + api_key_auth: ApiKeyAuth = None, + db: Session = Depends(get_db), +): + """ + sync knowledge base information based on knowledge_id + """ + api_key = api_key_service.ApiKeyService.get_api_key(db, api_key_auth.api_key_id, api_key_auth.workspace_id) + current_user = api_key.creator + current_user.current_workspace_id = api_key_auth.workspace_id + + return await knowledge_controller.sync_knowledge(knowledge_id=knowledge_id, + db=db, + current_user=current_user) +