refactor(apifox): 移除调试日志并优化代码结构
- 删除所有console.log调试输出 - 移除未使用的fs模块导入 - 优化ApifoxService初始化配置 - 使用新的MCP SDK注册方式替代旧版prompt处理 - 添加环境变量默认值设置
This commit is contained in:
1 parent
ad543045c7
commit
a6978c948b
2 files changed
+66
-91
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import axios from "axios";
|
||||
import NodeCache from 'node-cache';
|
||||
import fs from 'fs'
|
||||
// import fs from 'fs'
|
||||
|
||||
const APIFOX_API_BASE = "https://apifox.gzmiyuan.com/api/v1";
|
||||
|
||||
@@ -50,9 +50,7 @@ export class ApifoxService {
|
||||
async init() {
|
||||
try {
|
||||
this.branchId = await this.getBranchId();
|
||||
console.log('branchId', this.branchId);
|
||||
} catch (error) {
|
||||
console.error("Error initializing branch ID:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -110,7 +108,6 @@ export class ApifoxService {
|
||||
|
||||
async getApiTreeList() {
|
||||
const apiTree = await this.get(`/projects/${this.projectId}/api-tree-list`);
|
||||
console.log('-- get api tree list success', 'length', apiTree.length);
|
||||
this.apiTreeList = apiTree;
|
||||
return apiTree;
|
||||
}
|
||||
@@ -122,12 +119,10 @@ export class ApifoxService {
|
||||
// 检查缓存是否有效
|
||||
const cachedData = this.cache.get(cacheKey);
|
||||
if (cachedData) {
|
||||
console.log('Using cached folder list', 'length', cachedData.length);
|
||||
return cachedData;
|
||||
}
|
||||
|
||||
const {data: folderList} = await this.get(`/projects/${this.projectId}/api-detail-folders`);
|
||||
console.log('--get folder success', 'length', folderList.length);
|
||||
|
||||
// 设置缓存
|
||||
this.cache.set(cacheKey, folderList);
|
||||
@@ -149,12 +144,10 @@ export class ApifoxService {
|
||||
// 检查缓存是否有效
|
||||
const cachedData = this.cache.get(cacheKey);
|
||||
if (cachedData) {
|
||||
console.log('Using cached data schema');
|
||||
return cachedData;
|
||||
}
|
||||
|
||||
const {data:schemasTreeList} = await this.get(`/projects/${this.projectId}/data-schemas?locale=zh-CN`);
|
||||
console.log('--get data schema success', 'length', schemasTreeList.length);
|
||||
|
||||
// 设置缓存
|
||||
this.cache.set(cacheKey, schemasTreeList);
|
||||
@@ -168,12 +161,10 @@ export class ApifoxService {
|
||||
// 检查缓存是否有效
|
||||
const cachedData = this.cache.get(cacheKey);
|
||||
if (cachedData) {
|
||||
console.log('Using cached API details');
|
||||
return cachedData;
|
||||
}
|
||||
|
||||
const {data:apiDetails} = await this.get(`/api-details?locale=zh-CN`, {});
|
||||
console.log('--get api details success', 'length', apiDetails.length);
|
||||
|
||||
// 设置缓存
|
||||
this.cache.set(cacheKey, apiDetails);
|
||||
@@ -182,7 +173,6 @@ export class ApifoxService {
|
||||
|
||||
getSchemaRefId(obj) {
|
||||
if (!obj || !obj.$ref) {
|
||||
console.log('no schemaid', obj)
|
||||
return;
|
||||
}
|
||||
const schemaName = obj.$ref.split('/').pop();
|
||||
@@ -275,9 +265,7 @@ export class ApifoxService {
|
||||
const requestSchemaId = this.getSchemaRefId(apiDetail.requestBody.jsonSchema);
|
||||
const responseSchema = Array.isArray(apiDetail.responses) ? apiDetail.responses[0].jsonSchema : apiDetail.responses.jsonSchema;
|
||||
const responseSchemaId = this.getSchemaRefId(responseSchema);
|
||||
console.log('responseSchemaId', responseSchemaId);
|
||||
const respDataSchemaId = this.getSchemaRefId(dataSchema.find((item) => item.id.toString() === responseSchemaId).jsonSchema.properties.data)
|
||||
console.log('respDataSchemaId', respDataSchemaId);
|
||||
return {
|
||||
path: apiDetail.path,
|
||||
name: apiDetail.name,
|
||||
@@ -312,21 +300,7 @@ export class ApifoxService {
|
||||
const folder = await this.getFolderByName(folderName);
|
||||
const apiDetails = await this.getApiDetails();
|
||||
const apiList = apiDetails.filter((item) => item.folderId === folder.id);
|
||||
console.log('--getApiListByFolderName success', 'length', apiList.length);
|
||||
return Promise.all(apiList.map((api) => this.getApiDetailResp(api)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
const apifoxService = new ApifoxService(345161);
|
||||
|
||||
apifoxService.init().then(() => {
|
||||
apifoxService.getApiListByFolderName('数据中心统计数据')
|
||||
.then(res => {
|
||||
fs.writeFileSync('apifox-ret.json', JSON.stringify(res, null, 2));
|
||||
})
|
||||
|
||||
}).catch((error) => {
|
||||
console.error("Error initializing ApifoxService:", error);
|
||||
});
|
||||
Reference in new issue
Block a user