whistle.mock-plugins 1.1.1-dev.8 → 1.1.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.
- package/VERSION.md +14 -16
- package/app/cgi-bin/interfaces.js +70 -9
- package/app/public/js/index.js +1 -1
- package/app/public/js/index.js.LICENSE.txt +6 -0
- package/lib/routes/interfaces.js +171 -0
- package/package.json +1 -1
- package/ui/src/pages/InterfaceManagement.js +568 -84
- package/ui/src/styles/interface-management.css +292 -16
|
@@ -111,6 +111,8 @@
|
|
|
111
111
|
|
|
112
112
|
/** */
|
|
113
113
|
|
|
114
|
+
/** */
|
|
115
|
+
|
|
114
116
|
/** */
|
|
115
117
|
|
|
116
118
|
/** */
|
|
@@ -145,6 +147,8 @@
|
|
|
145
147
|
|
|
146
148
|
/** */
|
|
147
149
|
|
|
150
|
+
/** */
|
|
151
|
+
|
|
148
152
|
/** */
|
|
149
153
|
|
|
150
154
|
/** */
|
|
@@ -157,4 +161,6 @@
|
|
|
157
161
|
|
|
158
162
|
/** */
|
|
159
163
|
|
|
164
|
+
/** */
|
|
165
|
+
|
|
160
166
|
/** */
|
package/lib/routes/interfaces.js
CHANGED
|
@@ -23,6 +23,7 @@ const processInterfaceData = (data) => {
|
|
|
23
23
|
console.log('=== 开始处理接口数据 ===');
|
|
24
24
|
console.log('原始数据:', JSON.stringify({
|
|
25
25
|
name: result.name,
|
|
26
|
+
group: result.group, // 添加分组信息的日志
|
|
26
27
|
hasResponses: !!result.responses,
|
|
27
28
|
responsesType: typeof result.responses,
|
|
28
29
|
responsesLength: result.responses ? result.responses.length : 0,
|
|
@@ -108,6 +109,7 @@ const processInterfaceData = (data) => {
|
|
|
108
109
|
console.log('=== 处理后的最终接口数据 ===');
|
|
109
110
|
console.log('最终数据:', JSON.stringify({
|
|
110
111
|
name: result.name,
|
|
112
|
+
group: result.group, // 添加分组信息的日志
|
|
111
113
|
responsesLength: result.responses.length,
|
|
112
114
|
responses: result.responses,
|
|
113
115
|
activeResponseId: result.activeResponseId,
|
|
@@ -516,6 +518,175 @@ const initRouter = () => {
|
|
|
516
518
|
}
|
|
517
519
|
});
|
|
518
520
|
|
|
521
|
+
// 批量更新接口状态
|
|
522
|
+
router.patch('/interfaces', (req, res) => {
|
|
523
|
+
try {
|
|
524
|
+
const { active } = req.query;
|
|
525
|
+
const { featureId, group } = req.body;
|
|
526
|
+
|
|
527
|
+
if (active === undefined) {
|
|
528
|
+
return res.status(400).json({
|
|
529
|
+
code: 1,
|
|
530
|
+
message: '状态参数为必填项'
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
if (!featureId) {
|
|
535
|
+
return res.status(400).json({
|
|
536
|
+
code: 1,
|
|
537
|
+
message: '功能ID为必填项'
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// 检查功能是否存在
|
|
542
|
+
const featuresFile = path.join(DATA_DIR, 'features.json');
|
|
543
|
+
if (!fs.existsSync(featuresFile)) {
|
|
544
|
+
return res.status(404).json({
|
|
545
|
+
code: 1,
|
|
546
|
+
message: '功能不存在'
|
|
547
|
+
});
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
const features = fs.readJsonSync(featuresFile);
|
|
551
|
+
const feature = features.find(f => f.id === featureId);
|
|
552
|
+
if (!feature) {
|
|
553
|
+
return res.status(404).json({
|
|
554
|
+
code: 1,
|
|
555
|
+
message: '功能不存在'
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// 读取接口列表
|
|
560
|
+
const interfacesFile = path.join(DATA_DIR, `interfaces-${featureId}.json`);
|
|
561
|
+
if (!fs.existsSync(interfacesFile)) {
|
|
562
|
+
return res.status(404).json({
|
|
563
|
+
code: 1,
|
|
564
|
+
message: '接口列表不存在'
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
const interfaces = fs.readJsonSync(interfacesFile);
|
|
569
|
+
|
|
570
|
+
// 根据分组筛选要更新的接口
|
|
571
|
+
let updatedCount = 0;
|
|
572
|
+
const updatedInterfaces = interfaces.map(item => {
|
|
573
|
+
// 如果指定了分组,只更新该分组下的接口
|
|
574
|
+
if (group && item.group !== group) {
|
|
575
|
+
return item;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
// 更新接口状态
|
|
579
|
+
if (item.active !== (active === 'true')) {
|
|
580
|
+
updatedCount++;
|
|
581
|
+
return {
|
|
582
|
+
...item,
|
|
583
|
+
active: active === 'true',
|
|
584
|
+
updatedAt: new Date().toISOString()
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
return item;
|
|
589
|
+
});
|
|
590
|
+
|
|
591
|
+
// 保存更新后的接口列表
|
|
592
|
+
fs.writeJsonSync(interfacesFile, updatedInterfaces, { spaces: 2 });
|
|
593
|
+
|
|
594
|
+
res.json({
|
|
595
|
+
code: 0,
|
|
596
|
+
message: `成功${active === 'true' ? '启用' : '禁用'} ${updatedCount} 个接口`,
|
|
597
|
+
data: { updatedCount }
|
|
598
|
+
});
|
|
599
|
+
} catch (err) {
|
|
600
|
+
console.error('批量更新接口状态失败:', err);
|
|
601
|
+
res.status(500).json({
|
|
602
|
+
code: 1,
|
|
603
|
+
message: '批量更新接口状态失败: ' + err.message
|
|
604
|
+
});
|
|
605
|
+
}
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
// 部分更新接口
|
|
609
|
+
router.patch('/interfaces/:id', (req, res) => {
|
|
610
|
+
try {
|
|
611
|
+
const { id } = req.params;
|
|
612
|
+
const updateData = req.body;
|
|
613
|
+
|
|
614
|
+
if (!id) {
|
|
615
|
+
return res.status(400).json({
|
|
616
|
+
code: 1,
|
|
617
|
+
message: '接口ID为必填项'
|
|
618
|
+
});
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// 检查功能是否存在
|
|
622
|
+
const featuresFile = path.join(DATA_DIR, 'features.json');
|
|
623
|
+
if (!fs.existsSync(featuresFile)) {
|
|
624
|
+
return res.status(404).json({
|
|
625
|
+
code: 1,
|
|
626
|
+
message: '功能不存在'
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
const features = fs.readJsonSync(featuresFile);
|
|
631
|
+
|
|
632
|
+
// 在所有功能模块中查找接口
|
|
633
|
+
let foundInterface = null;
|
|
634
|
+
let foundFeature = null;
|
|
635
|
+
let foundInterfaceIndex = -1;
|
|
636
|
+
let interfacesFile = '';
|
|
637
|
+
|
|
638
|
+
for (const feature of features) {
|
|
639
|
+
const featureInterfacesFile = path.join(DATA_DIR, `interfaces-${feature.id}.json`);
|
|
640
|
+
if (fs.existsSync(featureInterfacesFile)) {
|
|
641
|
+
const interfaces = fs.readJsonSync(featureInterfacesFile);
|
|
642
|
+
const index = interfaces.findIndex(item => item.id === id);
|
|
643
|
+
|
|
644
|
+
if (index !== -1) {
|
|
645
|
+
foundInterface = interfaces[index];
|
|
646
|
+
foundFeature = feature;
|
|
647
|
+
foundInterfaceIndex = index;
|
|
648
|
+
interfacesFile = featureInterfacesFile;
|
|
649
|
+
break;
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
if (!foundInterface) {
|
|
655
|
+
return res.status(404).json({
|
|
656
|
+
code: 1,
|
|
657
|
+
message: '接口不存在'
|
|
658
|
+
});
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
// 读取接口所在文件的所有接口
|
|
662
|
+
const interfaces = fs.readJsonSync(interfacesFile);
|
|
663
|
+
|
|
664
|
+
// 更新接口
|
|
665
|
+
const updatedInterface = {
|
|
666
|
+
...foundInterface,
|
|
667
|
+
...updateData,
|
|
668
|
+
updatedAt: new Date().toISOString()
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
interfaces[foundInterfaceIndex] = updatedInterface;
|
|
672
|
+
|
|
673
|
+
// 保存更新后的接口列表
|
|
674
|
+
fs.writeJsonSync(interfacesFile, interfaces, { spaces: 2 });
|
|
675
|
+
|
|
676
|
+
res.json({
|
|
677
|
+
code: 0,
|
|
678
|
+
message: '接口更新成功',
|
|
679
|
+
data: updatedInterface
|
|
680
|
+
});
|
|
681
|
+
} catch (err) {
|
|
682
|
+
console.error('更新接口失败:', err);
|
|
683
|
+
res.status(500).json({
|
|
684
|
+
code: 1,
|
|
685
|
+
message: '更新接口失败: ' + err.message
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
});
|
|
689
|
+
|
|
519
690
|
return router;
|
|
520
691
|
};
|
|
521
692
|
|