mm_os 4.3.7 → 5.0.0
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/README.md +101 -504
- package/index.js +26 -19
- package/lib/loader.js +787 -0
- package/lib/os.js +369 -0
- package/package.json +55 -84
- package/LICENSE +0 -21
- package/README_EN.md +0 -505
- package/adapter/adapter.js +0 -484
- package/adapter/custom_persistence.js +0 -661
- package/adapter/mqtt.js +0 -254
- package/adapter/socket.js +0 -244
- package/adapter/web.js +0 -92
- package/adapter/websocket.js +0 -43
- package/ai.js +0 -130
- package/com/api/README.md +0 -3
- package/com/api/com.json +0 -5
- package/com/api/config.tpl.json +0 -41
- package/com/api/drive.js +0 -732
- package/com/api/index.js +0 -201
- package/com/api/oauth.js +0 -200
- package/com/api/script.tpl.js +0 -32
- package/com/cmd/README.md +0 -11
- package/com/cmd/com.json +0 -5
- package/com/cmd/config.tpl.json +0 -48
- package/com/cmd/drive.js +0 -176
- package/com/cmd/index.js +0 -287
- package/com/cmd/job/config.json +0 -66
- package/com/cmd/job/index.js +0 -241
- package/com/cmd/job/test.js +0 -188
- package/com/cmd/msg.json +0 -48
- package/com/cmd/script.tpl.js +0 -12
- package/com/db/README.md +0 -3
- package/com/db/com.json +0 -5
- package/com/db/drive.js +0 -2206
- package/com/db/index.js +0 -241
- package/com/event/README.md +0 -4
- package/com/event/com.json +0 -5
- package/com/event/config.tpl.json +0 -20
- package/com/event/drive.js +0 -61
- package/com/event/index.js +0 -438
- package/com/event/script.tpl.js +0 -23
- package/com/mqtt/README.md +0 -47
- package/com/mqtt/com.json +0 -5
- package/com/mqtt/config.tpl.json +0 -42
- package/com/mqtt/drive.js +0 -704
- package/com/mqtt/index.js +0 -1052
- package/com/mqtt/index.test.js +0 -503
- package/com/mqtt/script.tpl.js +0 -719
- package/com/nav/README.md +0 -2
- package/com/nav/com.json +0 -5
- package/com/nav/config.tpl.json +0 -84
- package/com/nav/drive.js +0 -702
- package/com/nav/index.js +0 -228
- package/com/nav/tpl/admin_pc/page_channel.vue +0 -305
- package/com/nav/tpl/admin_pc/page_config.vue +0 -280
- package/com/nav/tpl/admin_pc/page_config_form.vue +0 -194
- package/com/nav/tpl/admin_pc/page_default.vue +0 -247
- package/com/nav/tpl/admin_pc/page_form.vue +0 -180
- package/com/nav/tpl/admin_pc/page_lang.vue +0 -264
- package/com/nav/tpl/admin_pc/page_nav.vue +0 -321
- package/com/nav/tpl/admin_pc/page_table.vue +0 -296
- package/com/nav/tpl/admin_pc/page_type.vue +0 -321
- package/com/nav/tpl/admin_pc/page_view.vue +0 -124
- package/com/nav/tpl/dev_pc/page_channel.vue +0 -253
- package/com/nav/tpl/dev_pc/page_config.vue +0 -253
- package/com/nav/tpl/dev_pc/page_default.vue +0 -247
- package/com/nav/tpl/dev_pc/page_form.vue +0 -162
- package/com/nav/tpl/dev_pc/page_nav.vue +0 -253
- package/com/nav/tpl/dev_pc/page_table.vue +0 -247
- package/com/nav/tpl/dev_pc/page_type.vue +0 -313
- package/com/nav/tpl/home_pc/page_channel.vue +0 -234
- package/com/nav/tpl/home_pc/page_default.vue +0 -234
- package/com/nav/tpl/home_pc/page_form.vue +0 -137
- package/com/nav/tpl/home_pc/page_list.vue +0 -234
- package/com/nav/tpl/home_pc/page_nav.vue +0 -221
- package/com/nav/tpl/home_pc/page_type.vue +0 -234
- package/com/nav/tpl/home_pc/page_view.vue +0 -125
- package/com/nav/tpl/home_phone/page_channel.vue +0 -234
- package/com/nav/tpl/home_phone/page_default.vue +0 -234
- package/com/nav/tpl/home_phone/page_form.vue +0 -137
- package/com/nav/tpl/home_phone/page_list.vue +0 -234
- package/com/nav/tpl/home_phone/page_nav.vue +0 -237
- package/com/nav/tpl/home_phone/page_type.vue +0 -234
- package/com/nav/tpl/home_phone/page_view.vue +0 -125
- package/com/nav/viewmodel.js +0 -446
- package/com/param/README.md +0 -2
- package/com/param/com.json +0 -5
- package/com/param/config.tpl.json +0 -136
- package/com/param/drive.js +0 -502
- package/com/param/index.js +0 -158
- package/com/param/script.tpl.js +0 -12
- package/com/pendant/README.md +0 -3
- package/com/pendant/com.json +0 -5
- package/com/pendant/config.tpl.json +0 -32
- package/com/pendant/drive.js +0 -204
- package/com/pendant/index.js +0 -467
- package/com/pendant/pendant.html +0 -16
- package/com/pendant/script.tpl.js +0 -18
- package/com/socket/README.md +0 -47
- package/com/socket/com.json +0 -5
- package/com/socket/config.tpl.json +0 -12
- package/com/socket/drive.js +0 -679
- package/com/socket/index.js +0 -402
- package/com/socket/script.tpl.js +0 -41
- package/com/sql/README.md +0 -3
- package/com/sql/com.json +0 -5
- package/com/sql/config.tpl.json +0 -74
- package/com/sql/drive.js +0 -1328
- package/com/sql/index.js +0 -152
- package/com/sql/script.tpl.js +0 -47
- package/com/static/README.md +0 -2
- package/com/static/com.json +0 -5
- package/com/static/config.tpl.json +0 -24
- package/com/static/drive.js +0 -194
- package/com/static/index.js +0 -237
- package/com/static/script.tpl.js +0 -28
- package/com/task/README.md +0 -3
- package/com/task/com.json +0 -5
- package/com/task/config.tpl.json +0 -24
- package/com/task/drive.js +0 -428
- package/com/task/index.js +0 -159
- package/com/task/script.tpl.js +0 -40
- package/com/template/com.json +0 -5
- package/com/template/config.tpl.json +0 -16
- package/com/template/drive.js +0 -81
- package/com/template/index.js +0 -141
- package/com.js +0 -237
- package/common/README.md +0 -2
- package/common/middleware/web_after/index.js +0 -26
- package/common/middleware/web_after/middleware.json +0 -9
- package/common/middleware/web_base/index.js +0 -113
- package/common/middleware/web_base/middleware.json +0 -19
- package/common/middleware/web_before/index.js +0 -33
- package/common/middleware/web_before/middleware.json +0 -9
- package/common/middleware/web_cors/index.js +0 -87
- package/common/middleware/web_cors/middleware.json +0 -24
- package/common/middleware/web_error/index.js +0 -131
- package/common/middleware/web_error/middleware.json +0 -19
- package/common/middleware/web_ip/index.js +0 -15
- package/common/middleware/web_ip/middleware.json +0 -14
- package/common/middleware/web_logger/index.js +0 -156
- package/common/middleware/web_logger/middleware.json +0 -14
- package/common/middleware/web_main/index.js +0 -26
- package/common/middleware/web_main/middleware.json +0 -9
- package/common/middleware/web_static/index.js +0 -73
- package/common/middleware/web_static/middleware.json +0 -54
- package/common/middleware/web_waf/index.js +0 -395
- package/common/middleware/web_waf/middleware.json +0 -13
- package/core/app/config.tpl.json +0 -67
- package/core/app/index.js +0 -711
- package/core/app/script.tpl.js +0 -52
- package/core/channel/index.js +0 -899
- package/core/channel/matcher.js +0 -585
- package/core/com/config.tpl.json +0 -16
- package/core/com/index.js +0 -77
- package/core/com/script.tpl.js +0 -5
- package/core/component/component.js +0 -42
- package/core/component/config.tpl.json +0 -63
- package/core/component/index.js +0 -273
- package/core/component/script.tpl.js +0 -19
- package/core/controller/config.tpl.json +0 -14
- package/core/controller/index.js +0 -371
- package/core/controller/script.tpl.js +0 -27
- package/core/factory/config.tpl.json +0 -14
- package/core/factory/entity.js +0 -275
- package/core/factory/index.js +0 -241
- package/core/factory/script.tpl.js +0 -16
- package/core/game/bat/index.js +0 -137
- package/core/game/bat/world.js +0 -622
- package/core/game/config.tpl.json +0 -16
- package/core/game/entity_admin.js +0 -230
- package/core/game/index.js +0 -186
- package/core/handler/config.tpl.json +0 -22
- package/core/handler/index.js +0 -181
- package/core/handler/script.tpl.js +0 -23
- package/core/logic/config.tpl.json +0 -14
- package/core/logic/index.js +0 -59
- package/core/logic/script.tpl.js +0 -19
- package/core/middleware/config.tpl.json +0 -16
- package/core/middleware/index.js +0 -117
- package/core/middleware/script.tpl.js +0 -37
- package/core/mod/config.tpl.json +0 -22
- package/core/mod/index.js +0 -136
- package/core/mod/script.tpl.js +0 -34
- package/core/model/config.tpl.json +0 -219
- package/core/model/index.js +0 -272
- package/core/model/model.js +0 -27
- package/core/model/script.tpl.js +0 -20
- package/core/notifier/config.tpl.json +0 -14
- package/core/notifier/index.js +0 -77
- package/core/notifier/script.tpl.js +0 -20
- package/core/plugin/config.tpl.json +0 -36
- package/core/plugin/index.js +0 -267
- package/core/plugin/script.tpl.js +0 -51
- package/core/pusher/config.tpl.json +0 -14
- package/core/pusher/index.js +0 -158
- package/core/pusher/script.tpl.js +0 -20
- package/core/room/bat/index.js +0 -170
- package/core/room/bat/room.js +0 -524
- package/core/room/config.tpl.json +0 -20
- package/core/room/index.js +0 -249
- package/core/room/room.js +0 -61
- package/core/scene/config.tpl.json +0 -14
- package/core/scene/index.js +0 -467
- package/core/scene/loop.js +0 -1306
- package/core/scene/map.js +0 -28
- package/core/scene/script.tpl.js +0 -22
- package/core/sender/config.tpl.json +0 -14
- package/core/sender/index.js +0 -79
- package/core/sender/script.tpl.js +0 -20
- package/core/service/config.tpl.json +0 -14
- package/core/service/index.js +0 -100
- package/core/service/script.tpl.js +0 -25
- package/core/store/config.tpl.json +0 -26
- package/core/store/index.js +0 -1794
- package/core/store/script.tpl.js +0 -22
- package/core/system/config.tpl.json +0 -18
- package/core/system/index.js +0 -312
- package/core/system/script.tpl.js +0 -77
- package/core/view/config.tpl.json +0 -14
- package/core/view/index.js +0 -91
- package/core/view/script.tpl.js +0 -20
- package/core/zone/bat/index.js +0 -744
- package/core/zone/config.tpl.json +0 -54
- package/core/zone/index.js +0 -655
- package/core/zone/script.tpl.js +0 -10
- package/core/zone/zone_bat.js +0 -136
- package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +0 -24
- package/os.js +0 -53
- package/server.js +0 -602
- package/ulits/id_gen.js +0 -134
- package/ulits/word.js +0 -206
package/com/api/index.js
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
const Manager = require("mm_machine").Manager;
|
|
2
|
-
const Drive = require("./drive");
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Api接口类
|
|
6
|
-
* @class
|
|
7
|
-
* @augments {Manager}
|
|
8
|
-
*/
|
|
9
|
-
class Api extends Manager {
|
|
10
|
-
/**
|
|
11
|
-
* 配置参数
|
|
12
|
-
* @type {object}
|
|
13
|
-
*/
|
|
14
|
-
static config = {
|
|
15
|
-
/**
|
|
16
|
-
* 名称
|
|
17
|
-
* @type {string}
|
|
18
|
-
*/
|
|
19
|
-
name: "",
|
|
20
|
-
/**
|
|
21
|
-
* 标题
|
|
22
|
-
* @type {string}
|
|
23
|
-
*/
|
|
24
|
-
title: "API接口",
|
|
25
|
-
/**
|
|
26
|
-
* 描述
|
|
27
|
-
* @type {string}
|
|
28
|
-
*/
|
|
29
|
-
description: "这是API接口管理器",
|
|
30
|
-
/**
|
|
31
|
-
* 检索文件名
|
|
32
|
-
* @type {string}
|
|
33
|
-
*/
|
|
34
|
-
filename: "api.json",
|
|
35
|
-
/**
|
|
36
|
-
* 模板目录
|
|
37
|
-
* @type {string}
|
|
38
|
-
*/
|
|
39
|
-
tpl_dir: __dirname,
|
|
40
|
-
/**
|
|
41
|
-
* 基础目录
|
|
42
|
-
* @type {string}
|
|
43
|
-
*/
|
|
44
|
-
base_dir: "../common/api".fullname(__dirname),
|
|
45
|
-
/**
|
|
46
|
-
* 自定义目录,加载项目自定义资源
|
|
47
|
-
* @type {string}
|
|
48
|
-
*/
|
|
49
|
-
dir: "./app".fullname(),
|
|
50
|
-
/**
|
|
51
|
-
* 搜索模式 dir按目录搜索 | file按文件名搜索
|
|
52
|
-
* @type {string}
|
|
53
|
-
*/
|
|
54
|
-
search_way: "dir",
|
|
55
|
-
/**
|
|
56
|
-
* 是否懒加载
|
|
57
|
-
* @type {boolean}
|
|
58
|
-
*/
|
|
59
|
-
lazy_load: true,
|
|
60
|
-
/**
|
|
61
|
-
* 模式
|
|
62
|
-
* 1.生产模式,改变文件不会重新加载
|
|
63
|
-
* 2.热更新模式,改变配置文件会重新加载配置,不重新加载脚本
|
|
64
|
-
* 3.热重载模式,改变配置文件都会加载配置和脚本
|
|
65
|
-
* 4.重载模式,执行完后重新加载脚本,避免变量污染
|
|
66
|
-
* 5.热更新+重载模式,改变配置文件重新加载配置和脚本,执行完后重新加载脚本
|
|
67
|
-
* @type {number}
|
|
68
|
-
*/
|
|
69
|
-
mode: process.env.NODE_ENV === "production" ? 1 : 3,
|
|
70
|
-
/**
|
|
71
|
-
* 最大深度
|
|
72
|
-
* @type {number}
|
|
73
|
-
*/
|
|
74
|
-
max_depth: 6
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
/**
|
|
78
|
-
* 构造函数
|
|
79
|
-
* @param {object} config 配置参数
|
|
80
|
-
* @param {object} parent 父级模块
|
|
81
|
-
*/
|
|
82
|
-
constructor(config, parent) {
|
|
83
|
-
super({ ...Api.config, ...config }, parent);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Api驱动类
|
|
89
|
-
*/
|
|
90
|
-
Api.prototype.Drive = Drive;
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* 接口排序
|
|
94
|
-
*/
|
|
95
|
-
Api.prototype._sort = function () {
|
|
96
|
-
let sort_key = this.config.sort_key || "sort";
|
|
97
|
-
let infos = this.getInfos();
|
|
98
|
-
infos.sort((o1, o2) => {
|
|
99
|
-
let m1 = this.getMod(o1.name);
|
|
100
|
-
let m2 = this.getMod(o2.name);
|
|
101
|
-
var p1 = m1.config.path;
|
|
102
|
-
var p2 = m2.config.path;
|
|
103
|
-
var n = p2.length - p1.length;
|
|
104
|
-
if (n) {
|
|
105
|
-
return n;
|
|
106
|
-
} else {
|
|
107
|
-
return m1.config[sort_key] - m2.config[sort_key];
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* 匹配目标
|
|
114
|
-
* @param {string} str 目标
|
|
115
|
-
* @param {string} pattern 模式
|
|
116
|
-
* @returns {boolean} 是否匹配
|
|
117
|
-
*/
|
|
118
|
-
Api.prototype.isMatch = function (str, pattern) {
|
|
119
|
-
if (str === pattern) {
|
|
120
|
-
return true;
|
|
121
|
-
} else if (pattern.startsWith("*")) {
|
|
122
|
-
let clean = pattern.replaceAll("*", "");
|
|
123
|
-
if (pattern.endsWith("*")) {
|
|
124
|
-
return str.indexOf(clean) !== -1;
|
|
125
|
-
} else {
|
|
126
|
-
return str.endsWith(clean);
|
|
127
|
-
}
|
|
128
|
-
} else if (pattern.endsWith("*")) {
|
|
129
|
-
let clean = pattern.replaceAll("*", "");
|
|
130
|
-
return str.startsWith(clean);
|
|
131
|
-
} else {
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* 执行Api
|
|
138
|
-
* @param {object} ctx 请求上下文
|
|
139
|
-
* @param {object} db 数据管理器
|
|
140
|
-
* @returns {object | string} 返回一个对象或字符串
|
|
141
|
-
*/
|
|
142
|
-
Api.prototype.run = async function (ctx, db = {}) {
|
|
143
|
-
let path = ctx.request.path;
|
|
144
|
-
let infos = this.getInfos();
|
|
145
|
-
|
|
146
|
-
for (var i = 0, info; (info = infos[i++]);) {
|
|
147
|
-
if (info.state === 1) {
|
|
148
|
-
let mod = this.getMod(info.name);
|
|
149
|
-
if (mod && this.isMatch(path, mod.config.path)) {
|
|
150
|
-
if (!mod.isLoaded()) {
|
|
151
|
-
await mod.do("load");
|
|
152
|
-
}
|
|
153
|
-
var ret = await mod.run(ctx, db);
|
|
154
|
-
if (this.config.mode > 4) {
|
|
155
|
-
mod.do("reload");
|
|
156
|
-
}
|
|
157
|
-
if (ret) {
|
|
158
|
-
db.ret = ret;
|
|
159
|
-
break;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
return db.ret;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* @module 导出API类
|
|
169
|
-
*/
|
|
170
|
-
exports.Api = Api;
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* 创建全局管理器
|
|
174
|
-
*/
|
|
175
|
-
if (!$.pool.api) {
|
|
176
|
-
$.pool.api = {};
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/**
|
|
180
|
-
* API管理器,用于创建缓存
|
|
181
|
-
* @param {string} scope 作用域
|
|
182
|
-
* @param {string} title 标题
|
|
183
|
-
* @returns {object} 返回一个缓存类
|
|
184
|
-
*/
|
|
185
|
-
function apiAdmin(scope, title) {
|
|
186
|
-
var sc = scope || $.val.scope + "";
|
|
187
|
-
var obj = $.pool.api[sc];
|
|
188
|
-
if (!obj) {
|
|
189
|
-
$.pool.api[sc] = new Api({
|
|
190
|
-
name: sc,
|
|
191
|
-
title: title,
|
|
192
|
-
});
|
|
193
|
-
obj = $.pool.api[sc];
|
|
194
|
-
}
|
|
195
|
-
return obj;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* @module 导出API管理器
|
|
200
|
-
*/
|
|
201
|
-
$.admin.api = apiAdmin;
|
package/com/api/oauth.js
DELETED
|
@@ -1,200 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Oauth身份验证驱动类
|
|
3
|
-
* @class
|
|
4
|
-
*/
|
|
5
|
-
class Oauth {
|
|
6
|
-
static config = {
|
|
7
|
-
// 是否登录
|
|
8
|
-
'sign_in': false,
|
|
9
|
-
// 要求会员级别
|
|
10
|
-
'vip': 0,
|
|
11
|
-
// 要求管理级别
|
|
12
|
-
'gm': 0,
|
|
13
|
-
// 要求商户级别
|
|
14
|
-
'mc': 0,
|
|
15
|
-
// 要求用户组
|
|
16
|
-
'user_group': [],
|
|
17
|
-
// 要求管理组
|
|
18
|
-
'user_admin': [],
|
|
19
|
-
// 文件路径, 当调用函数不存在时,会先从文件中加载
|
|
20
|
-
'main': ''
|
|
21
|
-
};
|
|
22
|
-
/**
|
|
23
|
-
* 构造函数
|
|
24
|
-
* @param {string} config 当前路径
|
|
25
|
-
* @class
|
|
26
|
-
*/
|
|
27
|
-
constructor(config) {
|
|
28
|
-
// 配置参数
|
|
29
|
-
this.config = { ...Oauth.config, ...config };
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 加载配置对象
|
|
35
|
-
* @param {object} obj 配置对象
|
|
36
|
-
*/
|
|
37
|
-
Oauth.prototype.loadObj = function (obj) {
|
|
38
|
-
$.push(this.config, obj);
|
|
39
|
-
var f = this.config.main;
|
|
40
|
-
if (f) {
|
|
41
|
-
var file = f.fullname(this.getDir());
|
|
42
|
-
if (file.hasFile()) {
|
|
43
|
-
var cs = require(file);
|
|
44
|
-
if (cs) {
|
|
45
|
-
$.push(this, cs);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* 身份验证主程序
|
|
53
|
-
* @param {object} ctx HTTP请求上下文
|
|
54
|
-
* @returns {object} 验证失败返回错误提示,验证通过返回null
|
|
55
|
-
*/
|
|
56
|
-
Oauth.prototype.main = async function (ctx) {
|
|
57
|
-
return null;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* 小校验
|
|
62
|
-
* @param {object} ctx HTTP请求上下文
|
|
63
|
-
*/
|
|
64
|
-
Oauth.prototype.checkSub = async function (ctx) {
|
|
65
|
-
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* 验证身份
|
|
70
|
-
* @param {object} ctx HTTP请求上下文
|
|
71
|
-
* @returns {object} 验证失败返回错误提示,验证通过返回null
|
|
72
|
-
*/
|
|
73
|
-
Oauth.prototype.check = async function (ctx) {
|
|
74
|
-
// 无需登录则不验证身份和权限
|
|
75
|
-
var cg = this.config;
|
|
76
|
-
var user = await this._getUser(ctx);
|
|
77
|
-
if (!cg.sign_in) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
var error = await this.main(ctx);
|
|
81
|
-
if (error) {
|
|
82
|
-
return error;
|
|
83
|
-
}
|
|
84
|
-
if (!user) {
|
|
85
|
-
return {
|
|
86
|
-
code: 60000,
|
|
87
|
-
message: '账户未登录!'
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
if (await this._checkAccess(user, cg)) {
|
|
91
|
-
return {
|
|
92
|
-
code: 70000,
|
|
93
|
-
message: '没有访问权限'
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
return null;
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* 获取用户信息
|
|
101
|
-
* @param {object} ctx HTTP请求上下文
|
|
102
|
-
* @returns {object|null} 用户信息
|
|
103
|
-
* @private
|
|
104
|
-
*/
|
|
105
|
-
Oauth.prototype._getUser = async function (ctx) {
|
|
106
|
-
var user = ctx.session?.user;
|
|
107
|
-
if (user) {
|
|
108
|
-
return user;
|
|
109
|
-
}
|
|
110
|
-
var token = ctx.headers[$.dict.token];
|
|
111
|
-
if (!token) {
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
var u = await $.cache.get($.dict.session_id + '_' + token);
|
|
115
|
-
if (!u) {
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
var user_info = this._extractUserFromCache(u);
|
|
119
|
-
if (user_info) {
|
|
120
|
-
ctx.session.user = user_info;
|
|
121
|
-
}
|
|
122
|
-
return user_info;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* 从缓存中提取用户信息
|
|
127
|
-
* @param {object|string} u 缓存数据
|
|
128
|
-
* @returns {object|null} 用户信息
|
|
129
|
-
* @private
|
|
130
|
-
*/
|
|
131
|
-
Oauth.prototype._extractUserFromCache = function (u) {
|
|
132
|
-
var type = typeof (u);
|
|
133
|
-
if (type === 'string') {
|
|
134
|
-
var o = u.toJson();
|
|
135
|
-
return o.user;
|
|
136
|
-
} else if (type === 'object' && Object.keys(u).length > 0) {
|
|
137
|
-
return u.user;
|
|
138
|
-
}
|
|
139
|
-
return null;
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* 检查用户访问权限
|
|
144
|
-
* @param {object} user 用户信息
|
|
145
|
-
* @param {object} config 配置信息
|
|
146
|
-
* @returns {boolean} 是否无权限
|
|
147
|
-
* @private
|
|
148
|
-
*/
|
|
149
|
-
Oauth.prototype._checkAccess = function (user, config) {
|
|
150
|
-
return this._checkAccessLevels(user, config) ||
|
|
151
|
-
this._checkUserGroups(user, config) ||
|
|
152
|
-
this._checkAdminGroups(user, config);
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* 检查用户级别权限
|
|
157
|
-
* @param {object} user 用户信息
|
|
158
|
-
* @param {object} config 配置信息
|
|
159
|
-
* @returns {boolean} 是否无权限
|
|
160
|
-
* @private
|
|
161
|
-
*/
|
|
162
|
-
Oauth.prototype._checkAccessLevels = function (user, config) {
|
|
163
|
-
return (config.gm !== 0 && user.gm < config.gm) ||
|
|
164
|
-
(config.vip !== 0 && user.vip < config.vip) ||
|
|
165
|
-
(config.mc !== 0 && user.mc < config.mc);
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* 检查用户组权限
|
|
170
|
-
* @param {object} user 用户信息
|
|
171
|
-
* @param {object} config 配置信息
|
|
172
|
-
* @returns {boolean} 是否无权限
|
|
173
|
-
* @private
|
|
174
|
-
*/
|
|
175
|
-
Oauth.prototype._checkUserGroups = function (user, config) {
|
|
176
|
-
if (config.user_group.length === 0) {
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
var user_groups = user.user_group.split(',');
|
|
180
|
-
var has_group = config.user_group.some(group => user_groups.includes(group));
|
|
181
|
-
return !has_group;
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* 检查管理组权限
|
|
186
|
-
* @param {object} user 用户信息
|
|
187
|
-
* @param {object} config 配置信息
|
|
188
|
-
* @returns {boolean} 是否无权限
|
|
189
|
-
* @private
|
|
190
|
-
*/
|
|
191
|
-
Oauth.prototype._checkAdminGroups = function (user, config) {
|
|
192
|
-
if (config.user_admin.length === 0) {
|
|
193
|
-
return false;
|
|
194
|
-
}
|
|
195
|
-
var admin_groups = user.user_admin.split(',');
|
|
196
|
-
var has_admin = config.user_admin.some(group => admin_groups.includes(group));
|
|
197
|
-
return !has_admin;
|
|
198
|
-
};
|
|
199
|
-
|
|
200
|
-
module.exports = Oauth;
|
package/com/api/script.tpl.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
module.exports = {
|
|
3
|
-
/**
|
|
4
|
-
* 接口主函数
|
|
5
|
-
* @param {object} ctx HTTP上下文
|
|
6
|
-
* @param {object} db 数据管理器,如: { next: async function{}, ret: {} }
|
|
7
|
-
* @returns {object} 执行结果
|
|
8
|
-
*/
|
|
9
|
-
async main(ctx, db) {
|
|
10
|
-
// 获取请求参数
|
|
11
|
-
var req = ctx.request;
|
|
12
|
-
var {
|
|
13
|
-
query,
|
|
14
|
-
body
|
|
15
|
-
} = req;
|
|
16
|
-
// return "hello world" + JSON.stringify(body);
|
|
17
|
-
|
|
18
|
-
// 操作sql模板
|
|
19
|
-
var m = query.method;
|
|
20
|
-
if (m === 'add') {
|
|
21
|
-
|
|
22
|
-
} else if (m === 'del') {
|
|
23
|
-
|
|
24
|
-
} else if (m === 'set') {
|
|
25
|
-
|
|
26
|
-
} else {
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
var ret = await this.sql.run(query, body, db);
|
|
30
|
-
return ret;
|
|
31
|
-
}
|
|
32
|
-
};
|
package/com/cmd/README.md
DELETED
package/com/cmd/com.json
DELETED
package/com/cmd/config.tpl.json
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// 指令名称, 用于动态增删改配置
|
|
3
|
-
"name": "{name || 'demo'}",
|
|
4
|
-
// 标题, 用于查询指令时
|
|
5
|
-
"title": "{title || '指令标题'}",
|
|
6
|
-
// 描述, 用于介绍该指令的作用
|
|
7
|
-
"description": "{description || '暂无描述'}",
|
|
8
|
-
// 文件名, 用于驱动脚本, 实现业务
|
|
9
|
-
"main": "{main || './index.js'}",
|
|
10
|
-
// 指令状态, 1为启用, 0为禁用
|
|
11
|
-
"state": 1,
|
|
12
|
-
// 时态, before之前、main主要、after之后
|
|
13
|
-
"tense": "{tense || 'main'}",
|
|
14
|
-
// 匹配关键词组, 消息内容包含任一关键词则触发指令
|
|
15
|
-
"match": ["触发词1", "触发词2"],
|
|
16
|
-
// 排除关键词组, 包含任一排除词则不触发指令
|
|
17
|
-
"not": [],
|
|
18
|
-
// 执行顺序, 数值越小越优先执行
|
|
19
|
-
"sort": 100,
|
|
20
|
-
// 结束标志: 1为匹配后不再执行后续指令, 0为继续执行
|
|
21
|
-
"end": 1,
|
|
22
|
-
// 指令参数, 类似于驱动脚本中使用 openAI 工具时传递参数
|
|
23
|
-
"params": {
|
|
24
|
-
"properties": {
|
|
25
|
-
"tracking_no": {
|
|
26
|
-
"type": "string",
|
|
27
|
-
"description": "快递单号",
|
|
28
|
-
"example": "1234567890",
|
|
29
|
-
"question": "快递单号多少?",
|
|
30
|
-
"error": "请输入正确的快递单号",
|
|
31
|
-
"match": "{数字}{英文}",
|
|
32
|
-
"default": null
|
|
33
|
-
},
|
|
34
|
-
"company": {
|
|
35
|
-
"type": "string",
|
|
36
|
-
"description": "快递公司",
|
|
37
|
-
"example": "顺丰",
|
|
38
|
-
"question": "快递公司多少?",
|
|
39
|
-
"error": "请输入正确的快递公司",
|
|
40
|
-
"match": "{中文}快递",
|
|
41
|
-
"enum": ["顺丰", "圆通", "中通", "韵达", "申通"],
|
|
42
|
-
"remove": ["快递"],
|
|
43
|
-
"default": null
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
"required": []
|
|
47
|
-
}
|
|
48
|
-
}
|
package/com/cmd/drive.js
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
require('mm_matchs');
|
|
2
|
-
const Item = require('mm_machine').Drive;
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 指令驱动类
|
|
6
|
-
*/
|
|
7
|
-
class Drive extends Item {
|
|
8
|
-
static config = {
|
|
9
|
-
app: 'server',
|
|
10
|
-
plugin: 'sys',
|
|
11
|
-
match: [],
|
|
12
|
-
not: [],
|
|
13
|
-
end: 1,
|
|
14
|
-
sort: 100,
|
|
15
|
-
tense: 'main',
|
|
16
|
-
params: null,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* 构造函数
|
|
21
|
-
* @param {object} config 配置参数
|
|
22
|
-
* @param {object} parent 父对象
|
|
23
|
-
*/
|
|
24
|
-
constructor(config, parent) {
|
|
25
|
-
super({ ...Drive.config, ...config }, parent);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* 匹配指令
|
|
31
|
-
*
|
|
32
|
-
* 支持三种匹配方式:
|
|
33
|
-
* 1. 正则表达式 - 以 "/" 开头的字符串, 如 "/[0-9]+/"
|
|
34
|
-
* 2. 语义占位符 - 含 {xxx} 的字符串, 如 "{数字}"、"{日期}"、"{城市}"、"{手机号码}" 等
|
|
35
|
-
* 3. 纯字符串 - 默认匹配
|
|
36
|
-
*
|
|
37
|
-
* @param {string} content 消息内容
|
|
38
|
-
* @returns {string} 匹配返回关键词字符串, 否则返回空字符串
|
|
39
|
-
*/
|
|
40
|
-
Drive.prototype.match = function (content) {
|
|
41
|
-
var match_arr = this.config.match;
|
|
42
|
-
if (!match_arr || match_arr.length === 0) {
|
|
43
|
-
return '';
|
|
44
|
-
}
|
|
45
|
-
var not_arr = this.config.not;
|
|
46
|
-
if (not_arr && not_arr.length > 0) {
|
|
47
|
-
for (var i = 0; i < not_arr.length; i++) {
|
|
48
|
-
if (content.matchs(not_arr[i])) {
|
|
49
|
-
return '';
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
for (var i = 0; i < match_arr.length; i++) {
|
|
54
|
-
var ret = content.matchs(match_arr[i]);
|
|
55
|
-
if (ret) {
|
|
56
|
-
return ret;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return '';
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* 执行指令
|
|
64
|
-
* @param {object} msg 消息对象
|
|
65
|
-
* @param {object} db 数据管理器
|
|
66
|
-
* @returns {object|string} 返回执行结果, 不匹配返回null
|
|
67
|
-
*/
|
|
68
|
-
Drive.prototype.run = async function (msg, db) {
|
|
69
|
-
if (!msg || !msg.content) {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
// msg.cmd已设置表示会话恢复, 跳过关键字匹配
|
|
73
|
-
if (!msg.cmd) {
|
|
74
|
-
if (!this.match(msg.content)) {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
msg.cmd = this.name;
|
|
78
|
-
}
|
|
79
|
-
try {
|
|
80
|
-
var ret;
|
|
81
|
-
if (this.config.params) {
|
|
82
|
-
ret = this._fillParams(msg);
|
|
83
|
-
if (ret !== null) {
|
|
84
|
-
return typeof ret === 'string' ? { content: ret } : ret;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
ret = await this.call('main', msg, db);
|
|
88
|
-
return typeof ret === 'string' ? { content: ret } : ret;
|
|
89
|
-
} catch (error) {
|
|
90
|
-
this.log('error', '指令执行失败', error.message);
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* 槽位填充
|
|
97
|
-
*
|
|
98
|
-
* 遍历 params.properties, 从 msg.content 中提取参数值。
|
|
99
|
-
* 已填充的参数跳过, 缺失的必填参数返回 question 提示语。
|
|
100
|
-
* 全部必填项满足时返回 null, 交由 main() 执行。
|
|
101
|
-
*
|
|
102
|
-
* @param {object} msg 消息对象
|
|
103
|
-
* @returns {string|null} 返回追问内容, 全部满足返回null
|
|
104
|
-
* @private
|
|
105
|
-
*/
|
|
106
|
-
Drive.prototype._fillParams = function (msg) {
|
|
107
|
-
var params = this.config.params;
|
|
108
|
-
if (!params || !params.properties) {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
if (!msg.form) {
|
|
112
|
-
msg.form = {};
|
|
113
|
-
}
|
|
114
|
-
var props = params.properties;
|
|
115
|
-
for (var k in props) {
|
|
116
|
-
this._tryExtractParam(msg, k, props[k]);
|
|
117
|
-
}
|
|
118
|
-
var required = params.required || [];
|
|
119
|
-
for (var i = 0; i < required.length; i++) {
|
|
120
|
-
var name = required[i];
|
|
121
|
-
if (!msg.form[name]) {
|
|
122
|
-
msg.end = 0;
|
|
123
|
-
return props[name].tip || props[name].question || '请填写' + name;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return null;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* 尝试从消息中提取单个参数
|
|
131
|
-
* @param {object} msg 消息对象
|
|
132
|
-
* @param {string} name 参数名
|
|
133
|
-
* @param {object} param 参数配置
|
|
134
|
-
* @private
|
|
135
|
-
*/
|
|
136
|
-
Drive.prototype._tryExtractParam = function (msg, name, param) {
|
|
137
|
-
if (msg.form[name]) {
|
|
138
|
-
return;
|
|
139
|
-
}
|
|
140
|
-
if (param.match) {
|
|
141
|
-
var val = this._cleanVal(msg.content.matchs(param.match), param);
|
|
142
|
-
if (val) {
|
|
143
|
-
var match_arr = this.config.match;
|
|
144
|
-
if (match_arr && match_arr.indexOf(val) !== -1) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
msg.form[name] = val;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
if (!msg.form[name] && param.default != null) {
|
|
151
|
-
msg.form[name] = param.default;
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* 清理提取值: 移除多余部分, 枚举验证
|
|
157
|
-
* @param {string} val 原始提取值
|
|
158
|
-
* @param {object} param 参数配置
|
|
159
|
-
* @returns {string} 清理后的值
|
|
160
|
-
* @private
|
|
161
|
-
*/
|
|
162
|
-
Drive.prototype._cleanVal = function (val, param) {
|
|
163
|
-
if (!val) return '';
|
|
164
|
-
var result = val;
|
|
165
|
-
if (param.remove && param.remove.length) {
|
|
166
|
-
for (var i = 0; i < param.remove.length; i++) {
|
|
167
|
-
result = result.replace(param.remove[i], '');
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
if (param.enum && param.enum.length && param.enum.indexOf(result) === -1) {
|
|
171
|
-
return '';
|
|
172
|
-
}
|
|
173
|
-
return result;
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
module.exports = Drive;
|