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);