From ba73ade2a04c50a300405a1846aa29be7a62cbf7 Mon Sep 17 00:00:00 2001 From: lixiangcheng1 Date: Fri, 6 Feb 2026 18:18:15 +0800 Subject: [PATCH 1/2] [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) + From e3074b833fc99d7170687b33983ffec37312e1b0 Mon Sep 17 00:00:00 2001 From: lixiangcheng1 Date: Tue, 10 Feb 2026 12:12:07 +0800 Subject: [PATCH 2/2] [MODIFY] sync file path --- api/app/tasks.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/api/app/tasks.py b/api/app/tasks.py index 29b0e485..712c0ee5 100644 --- a/api/app/tasks.py +++ b/api/app/tasks.py @@ -439,7 +439,7 @@ def sync_knowledge_for_kb(kb_id: uuid.UUID): db.commit() db.refresh(db_file) # Construct a save path:/files/{kb_id}/{parent_id}/{file.id}{file_extension} - save_dir = os.path.join(settings.FILE_PATH, str(db_knowledge.id), str(db_knowledge.parent_id)) + save_dir = os.path.join(settings.FILE_PATH, str(db_knowledge.id), str(db_knowledge.id)) Path(save_dir).mkdir(parents=True, exist_ok=True) # Ensure that the directory exists save_path = os.path.join(save_dir, f"{db_file.id}{db_file.file_ext}") # update file @@ -571,7 +571,7 @@ def sync_knowledge_for_kb(kb_id: uuid.UUID): else: # --update # 1. update file # Construct a save path:/files/{kb_id}/{parent_id}/{file.id}{file_extension} - save_dir = os.path.join(settings.FILE_PATH, str(db_knowledge.id), str(db_knowledge.parent_id)) + save_dir = os.path.join(settings.FILE_PATH, str(db_knowledge.id), str(db_knowledge.id)) Path(save_dir).mkdir(parents=True, exist_ok=True) # Ensure that the directory exists # download document from Feishu FileInfo @@ -613,7 +613,7 @@ def sync_knowledge_for_kb(kb_id: uuid.UUID): else: # --add # 1. update file # Construct a save path:/files/{kb_id}/{parent_id}/{file.id}{file_extension} - save_dir = os.path.join(settings.FILE_PATH, str(db_knowledge.id), str(db_knowledge.parent_id)) + save_dir = os.path.join(settings.FILE_PATH, str(db_knowledge.id), str(db_knowledge.id)) Path(save_dir).mkdir(parents=True, exist_ok=True) # Ensure that the directory exists # download document from Feishu FileInfo @@ -727,7 +727,7 @@ def sync_knowledge_for_kb(kb_id: uuid.UUID): # 1. update file # Construct a save path:/files/{kb_id}/{parent_id}/{file.id}{file_extension} save_dir = os.path.join(settings.FILE_PATH, str(db_knowledge.id), - str(db_knowledge.parent_id)) + str(db_knowledge.id)) Path(save_dir).mkdir(parents=True, exist_ok=True) # Ensure that the directory exists # download document from Feishu FileInfo async def async_download_document(api_client: FeishuAPIClient, doc: FileInfo, save_dir: str): @@ -768,7 +768,7 @@ def sync_knowledge_for_kb(kb_id: uuid.UUID): # 1. update file # Construct a save path:/files/{kb_id}/{parent_id}/{file.id}{file_extension} save_dir = os.path.join(settings.FILE_PATH, str(db_knowledge.id), - str(db_knowledge.parent_id)) + str(db_knowledge.id)) Path(save_dir).mkdir(parents=True, exist_ok=True) # Ensure that the directory exists # download document from Feishu FileInfo async def async_download_document(api_client: FeishuAPIClient, doc: FileInfo, save_dir: str):