whistle.mock-plugins 1.1.1-dev.14 → 1.1.1-dev.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/cgi-bin/interfaces.js +65 -9
- package/app/public/js/index.js +1 -1
- package/package.json +1 -1
|
@@ -383,17 +383,9 @@ module.exports = function(req, res) {
|
|
|
383
383
|
|
|
384
384
|
// 处理 PATCH 请求 - 部分更新接口(如启用/禁用状态)
|
|
385
385
|
if (req.method === 'PATCH') {
|
|
386
|
-
const { id } = req.query;
|
|
386
|
+
const { id, active } = req.query;
|
|
387
387
|
const patchData = req.body;
|
|
388
388
|
|
|
389
|
-
if (!id) {
|
|
390
|
-
return res.status(400).json({
|
|
391
|
-
code: 400,
|
|
392
|
-
message: '接口ID不能为空',
|
|
393
|
-
data: null
|
|
394
|
-
});
|
|
395
|
-
}
|
|
396
|
-
|
|
397
389
|
// 读取接口数据
|
|
398
390
|
let interfacesData;
|
|
399
391
|
try {
|
|
@@ -410,6 +402,70 @@ module.exports = function(req, res) {
|
|
|
410
402
|
});
|
|
411
403
|
}
|
|
412
404
|
|
|
405
|
+
// 批量更新接口状态
|
|
406
|
+
if (active !== undefined) {
|
|
407
|
+
const { featureId, group } = patchData;
|
|
408
|
+
|
|
409
|
+
if (!featureId) {
|
|
410
|
+
return res.status(400).json({
|
|
411
|
+
code: 400,
|
|
412
|
+
message: '功能ID不能为空',
|
|
413
|
+
data: null
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// 根据分组筛选要更新的接口
|
|
418
|
+
let updatedCount = 0;
|
|
419
|
+
interfacesData.interfaces = interfacesData.interfaces.map(item => {
|
|
420
|
+
// 只更新指定功能模块下的接口
|
|
421
|
+
if (item.featureId !== featureId) {
|
|
422
|
+
return item;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// 如果指定了分组,只更新该分组下的接口
|
|
426
|
+
if (group && item.group !== group) {
|
|
427
|
+
return item;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
// 更新接口状态
|
|
431
|
+
const isActive = active === 'true';
|
|
432
|
+
if (item.active !== isActive) {
|
|
433
|
+
updatedCount++;
|
|
434
|
+
return {
|
|
435
|
+
...item,
|
|
436
|
+
active: isActive,
|
|
437
|
+
updatedAt: new Date().toISOString()
|
|
438
|
+
};
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
return item;
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
// 保存更新后的接口列表
|
|
445
|
+
fs.writeJsonSync(interfacesFile, interfacesData, { spaces: 2 });
|
|
446
|
+
|
|
447
|
+
console.log(`批量${active === 'true' ? '启用' : '禁用'}接口:`, {
|
|
448
|
+
featureId,
|
|
449
|
+
group,
|
|
450
|
+
updatedCount
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
return res.json({
|
|
454
|
+
code: 0,
|
|
455
|
+
message: `成功${active === 'true' ? '启用' : '禁用'} ${updatedCount} 个接口`,
|
|
456
|
+
data: { updatedCount }
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
// 单个接口更新
|
|
461
|
+
if (!id) {
|
|
462
|
+
return res.status(400).json({
|
|
463
|
+
code: 400,
|
|
464
|
+
message: '接口ID不能为空',
|
|
465
|
+
data: null
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
|
|
413
469
|
// 查找接口
|
|
414
470
|
const index = interfacesData.interfaces.findIndex(item => item.id === id);
|
|
415
471
|
|