whistle.mockbubu 2.1.2 → 2.1.5
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.
|
@@ -27,10 +27,7 @@ const pluginModeManager = require('../plugin-mode-manager')
|
|
|
27
27
|
module.exports = (server, options) => {
|
|
28
28
|
console.log('[mockbubu] 🚀 server.js 模块已加载!')
|
|
29
29
|
const { storage } = options
|
|
30
|
-
|
|
31
|
-
// 使用 StorageAdapter 包装 Whistle storage
|
|
32
|
-
const actualBaseDir = options.config.baseDir
|
|
33
|
-
const storageAdapter = new StorageAdapter({ baseDir: actualBaseDir })
|
|
30
|
+
const storageAdapter = new StorageAdapter(options)
|
|
34
31
|
|
|
35
32
|
// 初始化组管理器(使用适配器)
|
|
36
33
|
const groupManager = new GroupManager(storageAdapter)
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
*
|
|
16
16
|
* 使用示例:
|
|
17
17
|
* ```javascript
|
|
18
|
-
* const adapter = new StorageAdapter(
|
|
18
|
+
* const adapter = new StorageAdapter(options)
|
|
19
19
|
* await adapter.init()
|
|
20
20
|
* await adapter.writeFile('default/https://api.test.com', '{"data": {...}}')
|
|
21
21
|
* const content = await adapter.readFile('default/https://api.test.com')
|
|
@@ -37,29 +37,25 @@ class StorageAdapter {
|
|
|
37
37
|
* 构造函数
|
|
38
38
|
*
|
|
39
39
|
* @param {Object} options - 配置选项
|
|
40
|
-
* @param {string} options.
|
|
40
|
+
* @param {string} options.pluginBaseDir - 插件存储目录路径
|
|
41
41
|
*
|
|
42
42
|
* @example
|
|
43
|
-
* const adapter = new StorageAdapter(
|
|
44
|
-
* baseDir: '~/.whistle'
|
|
45
|
-
* })
|
|
43
|
+
* const adapter = new StorageAdapter(options)
|
|
46
44
|
*/
|
|
47
45
|
constructor(options) {
|
|
48
46
|
// 初始化 logger
|
|
49
47
|
this.logger = createLogger('storage-adapter')
|
|
50
48
|
|
|
51
|
-
//
|
|
49
|
+
// 兜底存储目录路径
|
|
52
50
|
let baseDir = path.join(
|
|
53
51
|
process.env.HOME,
|
|
54
52
|
'.WhistleAppData/.whistle/.plugins/whistle.mockbubu',
|
|
55
53
|
)
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
// 实际存储目录路径
|
|
55
|
+
if (options?.config?.pluginBaseDir) {
|
|
56
|
+
baseDir = options.config.pluginBaseDir
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
// 记录基础目录(生产环境可保留,便于问题排查)
|
|
61
|
-
this.logger.log('基础目录:', baseDir)
|
|
62
|
-
|
|
63
59
|
// 初始化 V3 存储实例
|
|
64
60
|
this.v3Storage = new FileSystemStorage(baseDir)
|
|
65
61
|
this.currentGroupId = 'default'
|
package/lib/uiServer/index.js
CHANGED
|
@@ -13,16 +13,8 @@ const MAX_AGE = 1000 * 60 * 5
|
|
|
13
13
|
|
|
14
14
|
module.exports = (server, options) => {
|
|
15
15
|
const app = new Koa()
|
|
16
|
-
const { storage } = options
|
|
17
|
-
|
|
18
16
|
console.log('[mockbubu] 插件开始初始化...')
|
|
19
|
-
|
|
20
|
-
// 使用 StorageAdapter 包装 Whistle storage
|
|
21
|
-
// Whistle storage 对象直接有 baseDir 属性
|
|
22
|
-
const actualBaseDir = options.config.baseDir
|
|
23
|
-
console.log('[mockbubu] 🔍 UI Server storage.baseDir:', storage.baseDir)
|
|
24
|
-
console.log('[mockbubu] 🔍 UI Server 使用 baseDir:', actualBaseDir)
|
|
25
|
-
const storageAdapter = new StorageAdapter({ baseDir: actualBaseDir })
|
|
17
|
+
const storageAdapter = new StorageAdapter(options)
|
|
26
18
|
|
|
27
19
|
// 同步初始化:确保初始化完成后再处理请求
|
|
28
20
|
let isInitialized = false
|
package/package.json
CHANGED
package/public/js/app.js
CHANGED
|
@@ -1964,6 +1964,7 @@ const __default__ = {
|
|
|
1964
1964
|
content: {}
|
|
1965
1965
|
});
|
|
1966
1966
|
const hasJsonError = (0,vue__WEBPACK_IMPORTED_MODULE_9__.ref)(false); // JSON 格式错误标志
|
|
1967
|
+
const hasFullScreenJsonError = (0,vue__WEBPACK_IMPORTED_MODULE_9__.ref)(false); // 全屏编辑器 JSON 格式错误标志
|
|
1967
1968
|
const versionModal = (0,vue__WEBPACK_IMPORTED_MODULE_9__.reactive)({
|
|
1968
1969
|
visible: false,
|
|
1969
1970
|
status: 'create',
|
|
@@ -2569,6 +2570,8 @@ const __default__ = {
|
|
|
2569
2570
|
const handleFullScreen = () => {
|
|
2570
2571
|
// 深拷贝当前内容到全屏编辑器
|
|
2571
2572
|
fullScreenModal.content = JSON.parse(JSON.stringify(currentFile.value.content));
|
|
2573
|
+
// 重置错误状态
|
|
2574
|
+
hasFullScreenJsonError.value = false;
|
|
2572
2575
|
fullScreenModal.visible = true;
|
|
2573
2576
|
};
|
|
2574
2577
|
|
|
@@ -2581,6 +2584,8 @@ const __default__ = {
|
|
|
2581
2584
|
const handleFullScreenClosed = () => {
|
|
2582
2585
|
// 弹窗关闭后清空内容
|
|
2583
2586
|
fullScreenModal.content = {};
|
|
2587
|
+
// 重置错误状态
|
|
2588
|
+
hasFullScreenJsonError.value = false;
|
|
2584
2589
|
};
|
|
2585
2590
|
|
|
2586
2591
|
// 全屏编辑器内容变化时同步到主编辑器
|
|
@@ -2650,6 +2655,12 @@ const __default__ = {
|
|
|
2650
2655
|
return;
|
|
2651
2656
|
}
|
|
2652
2657
|
|
|
2658
|
+
// 如果 JSON 格式错误,禁止保存
|
|
2659
|
+
if (hasFullScreenJsonError.value) {
|
|
2660
|
+
element_ui_lib_message__WEBPACK_IMPORTED_MODULE_2___default().error('JSON 格式错误,请修正后再保存');
|
|
2661
|
+
return;
|
|
2662
|
+
}
|
|
2663
|
+
|
|
2653
2664
|
// 确保内容已同步
|
|
2654
2665
|
currentFile.value.content = JSON.parse(JSON.stringify(fullScreenModal.content));
|
|
2655
2666
|
|
|
@@ -2741,6 +2752,7 @@ const __default__ = {
|
|
|
2741
2752
|
responseList,
|
|
2742
2753
|
currentFile,
|
|
2743
2754
|
hasJsonError,
|
|
2755
|
+
hasFullScreenJsonError,
|
|
2744
2756
|
versionModal,
|
|
2745
2757
|
fullScreenModal,
|
|
2746
2758
|
name,
|
|
@@ -4743,6 +4755,7 @@ var render = function render() {
|
|
|
4743
4755
|
}, [_c("i", {
|
|
4744
4756
|
staticClass: "el-icon-info"
|
|
4745
4757
|
}), _setup.isSourceReadonly ? _c("span", [_vm._v("快捷键: Ctrl/Cmd + F 查找 | ESC 关闭")]) : _c("span", [_vm._v("快捷键: Ctrl/Cmd + S 保存 | Ctrl/Cmd + F 查找 | ESC 关闭")])])], 1), _c(_setup.JsonEditor, {
|
|
4758
|
+
key: `fullscreen-editor-${_setup.currentFile.filename}-${_setup.isSourceReadonly}`,
|
|
4746
4759
|
ref: "fullScreenEditorRef",
|
|
4747
4760
|
attrs: {
|
|
4748
4761
|
"show-btns": false,
|
|
@@ -4753,7 +4766,13 @@ var render = function render() {
|
|
|
4753
4766
|
lang: "zh"
|
|
4754
4767
|
},
|
|
4755
4768
|
on: {
|
|
4756
|
-
input: _setup.handleFullScreenChange
|
|
4769
|
+
input: _setup.handleFullScreenChange,
|
|
4770
|
+
"has-error": function ($event) {
|
|
4771
|
+
_setup.hasFullScreenJsonError = true;
|
|
4772
|
+
},
|
|
4773
|
+
"json-change": function ($event) {
|
|
4774
|
+
_setup.hasFullScreenJsonError = false;
|
|
4775
|
+
}
|
|
4757
4776
|
},
|
|
4758
4777
|
nativeOn: {
|
|
4759
4778
|
keydown: [function ($event) {
|
|
@@ -4794,6 +4813,7 @@ var render = function render() {
|
|
|
4794
4813
|
}, [_vm._v(" 关闭 ")]), !_setup.isSourceReadonly ? _c("el-button", {
|
|
4795
4814
|
attrs: {
|
|
4796
4815
|
type: "primary",
|
|
4816
|
+
disabled: _setup.hasFullScreenJsonError,
|
|
4797
4817
|
size: "medium"
|
|
4798
4818
|
},
|
|
4799
4819
|
on: {
|