whistle.mock-plugins 1.1.1 → 1.1.2-dev.1

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.
@@ -383,9 +383,27 @@ module.exports = function(req, res) {
383
383
 
384
384
  // 处理 PATCH 请求 - 部分更新接口(如启用/禁用状态)
385
385
  if (req.method === 'PATCH') {
386
- const { id, active } = req.query;
386
+ // 支持从路径中获取ID (RESTful风格) 或 从查询参数获取ID
387
+ let id = req.query.id;
388
+
389
+ // 检查路径,支持 /cgi-bin/interfaces/123 形式的请求
390
+ const pathMatch = req.path.match(/\/interfaces\/([^\/]+)$/);
391
+ if (pathMatch && pathMatch[1]) {
392
+ id = pathMatch[1];
393
+ }
394
+
395
+ const { active } = req.query;
387
396
  const patchData = req.body;
388
397
 
398
+ // 记录请求信息
399
+ console.log('PATCH请求:', {
400
+ path: req.path,
401
+ pathMatch: pathMatch ? pathMatch[1] : null,
402
+ id,
403
+ active,
404
+ body: patchData
405
+ });
406
+
389
407
  // 读取接口数据
390
408
  let interfacesData;
391
409
  try {
@@ -402,8 +420,8 @@ module.exports = function(req, res) {
402
420
  });
403
421
  }
404
422
 
405
- // 批量更新接口状态
406
- if (active !== undefined) {
423
+ // 批量更新接口状态 - 按分组和功能模块
424
+ if (active !== undefined && !id && (patchData.featureId || patchData.group)) {
407
425
  const { featureId, group } = patchData;
408
426
 
409
427
  if (!featureId) {
@@ -414,6 +432,12 @@ module.exports = function(req, res) {
414
432
  });
415
433
  }
416
434
 
435
+ console.log('批量更新接口状态:', {
436
+ active,
437
+ featureId,
438
+ group
439
+ });
440
+
417
441
  // 根据分组筛选要更新的接口
418
442
  let updatedCount = 0;
419
443
  interfacesData.interfaces = interfacesData.interfaces.map(item => {
@@ -457,8 +481,9 @@ module.exports = function(req, res) {
457
481
  });
458
482
  }
459
483
 
460
- // 单个接口更新
484
+ // 处理单个接口状态更新或其他字段更新
461
485
  if (!id) {
486
+ console.error('单个接口更新错误: 缺少接口ID');
462
487
  return res.status(400).json({
463
488
  code: 400,
464
489
  message: '接口ID不能为空',
@@ -466,13 +491,19 @@ module.exports = function(req, res) {
466
491
  });
467
492
  }
468
493
 
494
+ console.log('更新单个接口状态,ID:', id, '数据:', patchData);
495
+
469
496
  // 查找接口
470
497
  const index = interfacesData.interfaces.findIndex(item => item.id === id);
471
498
 
472
499
  if (index === -1) {
500
+ console.error(`接口不存在,ID: ${id},当前共有 ${interfacesData.interfaces.length} 个接口`);
501
+ if (interfacesData.interfaces.length > 0) {
502
+ console.log('所有接口ID:', interfacesData.interfaces.map(i => i.id));
503
+ }
473
504
  return res.status(404).json({
474
505
  code: 404,
475
- message: '接口不存在',
506
+ message: `接口不存在 (ID: ${id})`,
476
507
  data: null
477
508
  });
478
509
  }
@@ -484,6 +515,12 @@ module.exports = function(req, res) {
484
515
  updatedAt: new Date().toISOString()
485
516
  };
486
517
 
518
+ console.log('接口更新成功,接口数据:', {
519
+ id: updatedInterface.id,
520
+ name: updatedInterface.name,
521
+ active: updatedInterface.active
522
+ });
523
+
487
524
  interfacesData.interfaces[index] = updatedInterface;
488
525
  fs.writeJsonSync(interfacesFile, interfacesData, { spaces: 2 });
489
526