From 87878ceca17cb35f843aae2e44ea64834d259858 Mon Sep 17 00:00:00 2001 From: zhangguoyun Date: Wed, 3 Dec 2025 10:58:02 +0800 Subject: [PATCH] =?UTF-8?q?refactor(ApifoxService):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E9=80=BB=E8=BE=91=E5=92=8C=E9=A1=B9?= =?UTF-8?q?=E7=9B=AEID=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改init方法接收projectId参数并简化错误处理 - 统一通过init方法设置projectId - 移除getApiDetailsById中冗余的projectId处理 - 为getApiListByFolderName添加projectId参数支持 --- apifox.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/apifox.js b/apifox.js index 693a152..0f257df 100644 --- a/apifox.js +++ b/apifox.js @@ -47,11 +47,10 @@ export class ApifoxService { * 初始化服务,获取branchId * @returns {Promise} */ - async init() { - try { + async init(projectId) { + if (projectId) { + this.projectId = projectId; this.branchId = await this.getBranchId(); - } catch (error) { - throw error; } } @@ -278,7 +277,7 @@ export class ApifoxService { async getApiDetailByPath(path, projectId) { if (projectId) { - this.projectId = projectId; + await this.init(projectId); } const apiDetails = await this.getApiDetails(); const apiDetail = apiDetails.find((item) => item.path === path); @@ -288,10 +287,7 @@ export class ApifoxService { return this.getApiDetailResp(apiDetail); } - async getApiDetailsById(apiId, projectId) { - if (projectId) { - this.projectId = projectId; - } + async getApiDetailsById(apiId) { const apiDetails = await this.getApiDetails(); const apiDetail = apiDetails.find((item) => item.id === apiId); if (!apiDetail) { @@ -302,7 +298,10 @@ export class ApifoxService { // TODO: - async getApiListByFolderName(folderName) { + async getApiListByFolderName(folderName, projectId) { + if (projectId) { + await this.init(projectId); + } const folder = await this.getFolderByName(folderName); const apiDetails = await this.getApiDetails(); const apiList = apiDetails.filter((item) => item.folderId === folder.id);