mm_os 3.3.0 → 4.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/LICENSE +21 -201
- package/README.md +491 -99
- package/README_EN.md +498 -0
- package/adapter/adapter.js +431 -0
- package/adapter/custom_persistence.js +660 -0
- package/adapter/mqtt.js +273 -0
- package/adapter/socket.js +113 -0
- package/adapter/web.js +67 -0
- package/adapter/websocket.js +146 -0
- package/com/api/com.json +5 -0
- package/{core/com → com}/api/config.tpl.json +8 -8
- package/com/api/drive.js +708 -0
- package/com/api/index.js +198 -0
- package/com/api/oauth.js +200 -0
- package/com/api/script.tpl.js +32 -0
- package/com/cmd/README.md +11 -0
- package/com/cmd/com.json +5 -0
- package/com/cmd/config.tpl.json +122 -0
- package/com/cmd/drive.js +1548 -0
- package/com/cmd/index.js +1066 -0
- package/com/cmd/msg.json +48 -0
- package/com/cmd/nlp.js +525 -0
- package/com/cmd/script.tpl.js +32 -0
- package/com/db/com.json +5 -0
- package/com/db/drive.js +1999 -0
- package/com/db/index.js +242 -0
- package/com/event/com.json +5 -0
- package/{core/com → com}/event/config.tpl.json +8 -8
- package/com/event/drive.js +59 -0
- package/com/event/index.js +409 -0
- package/com/event/script.tpl.js +23 -0
- package/com/mqtt/com.json +5 -0
- package/{core/com → com}/mqtt/config.tpl.json +3 -5
- package/com/mqtt/drive.js +676 -0
- package/com/mqtt/index.js +822 -0
- package/com/mqtt/mm_mqtt.js +425 -0
- package/com/mqtt/script.tpl.js +723 -0
- package/com/nav/com.json +5 -0
- package/com/nav/config.tpl.json +84 -0
- package/com/nav/drive.js +702 -0
- package/com/nav/index.js +231 -0
- package/{core/com → com}/nav/tpl/admin_pc/page_config.vue +280 -280
- package/{core/com → com}/nav/tpl/admin_pc/page_config_form.vue +194 -194
- package/com/nav/tpl/admin_pc/page_form.vue +180 -0
- package/com/nav/tpl/admin_pc/page_view.vue +124 -0
- package/com/nav/tpl/dev_pc/page_default.vue +247 -0
- package/com/nav/tpl/dev_pc/page_type.vue +313 -0
- package/com/nav/tpl/home_pc/page_default.vue +234 -0
- package/com/nav/tpl/home_pc/page_form.vue +137 -0
- package/com/nav/tpl/home_pc/page_list.vue +234 -0
- package/com/nav/tpl/home_pc/page_nav.vue +221 -0
- package/com/nav/tpl/home_pc/page_type.vue +234 -0
- package/com/nav/tpl/home_pc/page_view.vue +125 -0
- package/com/nav/tpl/home_phone/page_channel.vue +234 -0
- package/com/nav/tpl/home_phone/page_default.vue +234 -0
- package/com/nav/tpl/home_phone/page_form.vue +137 -0
- package/com/nav/tpl/home_phone/page_nav.vue +237 -0
- package/com/nav/tpl/home_phone/page_type.vue +234 -0
- package/com/nav/tpl/home_phone/page_view.vue +125 -0
- package/com/nav/viewmodel.js +446 -0
- package/com/param/com.json +5 -0
- package/{core/com → com}/param/config.tpl.json +7 -1
- package/com/param/drive.js +502 -0
- package/com/param/index.js +155 -0
- package/com/param/script.tpl.js +12 -0
- package/com/pendant/com.json +5 -0
- package/{core/com/component → com/pendant}/config.tpl.json +15 -13
- package/com/pendant/drive.js +204 -0
- package/com/pendant/index.js +441 -0
- package/com/pendant/pendant.html +16 -0
- package/com/pendant/script.tpl.js +18 -0
- package/com/socket/com.json +5 -0
- package/com/socket/config.tpl.json +12 -0
- package/com/socket/drive.js +651 -0
- package/com/socket/index.js +351 -0
- package/com/socket/script.tpl.js +41 -0
- package/com/sql/com.json +5 -0
- package/{core/com → com}/sql/config.tpl.json +13 -9
- package/com/sql/drive.js +1259 -0
- package/com/sql/index.js +150 -0
- package/com/sql/script.tpl.js +47 -0
- package/com/static/com.json +5 -0
- package/{core/com → com}/static/config.tpl.json +10 -6
- package/com/static/drive.js +194 -0
- package/com/static/index.js +226 -0
- package/com/static/script.tpl.js +28 -0
- package/com/task/com.json +5 -0
- package/{core/com → com}/task/config.tpl.json +4 -6
- package/com/task/drive.js +405 -0
- package/com/task/index.js +148 -0
- package/com/task/script.tpl.js +37 -0
- package/com/template/com.json +5 -0
- package/com/template/config.tpl.json +16 -0
- package/com/template/drive.js +80 -0
- package/com/template/index.js +141 -0
- package/com.js +156 -0
- package/common/README.md +2 -0
- package/common/handler/msg/handler.json +22 -0
- package/common/handler/msg/index.js +23 -0
- package/common/handler/player/handler.json +22 -0
- package/common/handler/player/index.js +287 -0
- package/common/handler/user/handler.json +22 -0
- package/common/handler/user/index.js +23 -0
- package/common/middleware/web_after/index.js +29 -0
- package/common/middleware/web_after/middleware.json +9 -0
- package/common/middleware/web_base/index.js +113 -0
- package/common/middleware/web_base/middleware.json +19 -0
- package/common/middleware/web_before/index.js +33 -0
- package/common/middleware/web_before/middleware.json +9 -0
- package/common/middleware/web_cors/index.js +87 -0
- package/common/middleware/web_cors/middleware.json +24 -0
- package/common/middleware/web_error/index.js +119 -0
- package/common/middleware/web_error/middleware.json +18 -0
- package/common/middleware/web_ip/index.js +15 -0
- package/common/middleware/web_ip/middleware.json +14 -0
- package/common/middleware/web_logger/index.js +156 -0
- package/common/middleware/web_logger/middleware.json +14 -0
- package/common/middleware/web_main/index.js +24 -0
- package/common/middleware/web_main/middleware.json +9 -0
- package/common/middleware/web_static/index.js +73 -0
- package/common/middleware/web_static/middleware.json +54 -0
- package/common/middleware/web_waf/index.js +385 -0
- package/common/middleware/web_waf/middleware.json +13 -0
- package/common/model/msg/index.js +88 -0
- package/common/model/msg/model.json +401 -0
- package/common/model/player/index.js +63 -0
- package/common/model/player/model.json +185 -0
- package/common/model/user/index.js +11 -0
- package/common/model/user/model.json +219 -0
- package/core/app/config.tpl.json +67 -0
- package/core/app/index.js +632 -0
- package/core/app/script.tpl.js +52 -0
- package/core/channel/index.js +899 -0
- package/core/channel/matcher.js +585 -0
- package/core/com/config.tpl.json +16 -0
- package/core/com/index.js +74 -0
- package/core/com/script.tpl.js +5 -0
- package/core/component/component.js +42 -0
- package/core/component/config.tpl.json +63 -0
- package/core/component/index.js +273 -0
- package/core/component/script.tpl.js +19 -0
- package/core/controller/config.tpl.json +14 -0
- package/core/controller/index.js +373 -0
- package/core/controller/script.tpl.js +27 -0
- package/core/factory/config.tpl.json +14 -0
- package/core/factory/entity.js +275 -0
- package/core/factory/index.js +241 -0
- package/core/factory/script.tpl.js +16 -0
- package/core/game/bat/index.js +137 -0
- package/core/game/bat/world.js +622 -0
- package/core/game/config.tpl.json +16 -0
- package/core/game/entity_admin.js +230 -0
- package/core/game/index.js +186 -0
- package/core/handler/config.tpl.json +22 -0
- package/core/handler/index.js +181 -0
- package/core/handler/script.tpl.js +23 -0
- package/core/logic/config.tpl.json +14 -0
- package/core/logic/index.js +59 -0
- package/core/logic/script.tpl.js +19 -0
- package/core/middleware/config.tpl.json +16 -0
- package/core/middleware/index.js +125 -0
- package/core/middleware/script.tpl.js +37 -0
- package/core/mod/config.tpl.json +22 -0
- package/core/mod/index.js +130 -0
- package/core/mod/script.tpl.js +34 -0
- package/core/model/config.tpl.json +219 -0
- package/core/model/index.js +272 -0
- package/core/model/model.js +27 -0
- package/core/model/script.tpl.js +20 -0
- package/core/notifier/config.tpl.json +14 -0
- package/core/notifier/index.js +77 -0
- package/core/notifier/script.tpl.js +20 -0
- package/core/plugin/config.tpl.json +24 -0
- package/core/plugin/index.js +232 -0
- package/core/plugin/script.tpl.js +51 -0
- package/core/pusher/config.tpl.json +14 -0
- package/core/pusher/index.js +161 -0
- package/core/pusher/script.tpl.js +20 -0
- package/core/room/bat/index.js +170 -0
- package/core/room/bat/room.js +524 -0
- package/core/room/config.tpl.json +20 -0
- package/core/room/index.js +249 -0
- package/core/room/room.js +61 -0
- package/core/scene/config.tpl.json +14 -0
- package/core/scene/index.js +466 -0
- package/core/scene/loop.js +1255 -0
- package/core/scene/map.js +28 -0
- package/core/scene/script.tpl.js +22 -0
- package/core/sender/config.tpl.json +14 -0
- package/core/sender/index.js +79 -0
- package/core/sender/script.tpl.js +20 -0
- package/core/service/config.tpl.json +14 -0
- package/core/service/index.js +100 -0
- package/core/service/script.tpl.js +25 -0
- package/core/store/config.tpl.json +26 -0
- package/core/store/index.js +1755 -0
- package/core/store/script.tpl.js +22 -0
- package/core/store/sql.js +1464 -0
- package/core/system/config.tpl.json +18 -0
- package/core/system/index.js +312 -0
- package/core/system/script.tpl.js +77 -0
- package/core/view/config.tpl.json +14 -0
- package/core/view/index.js +91 -0
- package/core/view/script.tpl.js +20 -0
- package/core/zone/bat/index.js +725 -0
- package/core/zone/config.tpl.json +54 -0
- package/core/zone/index.js +614 -0
- package/core/zone/script.tpl.js +10 -0
- package/core/zone/zone_bat.js +136 -0
- package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +24 -0
- package/index.js +17 -314
- package/os.js +57 -0
- package/package.json +60 -58
- package/server.js +598 -0
- package/README.en.md +0 -36
- package/conf.json +0 -3
- package/core/base/mqtt/index.js +0 -1107
- package/core/base/mqtt/lib.js +0 -40
- package/core/base/web/index.js +0 -243
- package/core/com/api/com.json +0 -4
- package/core/com/api/drive.js +0 -668
- package/core/com/api/index.js +0 -108
- package/core/com/api/oauth.js +0 -158
- package/core/com/api/script.js +0 -32
- package/core/com/app/README.md +0 -3
- package/core/com/app/com.json +0 -4
- package/core/com/app/config.tpl.json +0 -16
- package/core/com/app/drive.js +0 -309
- package/core/com/app/index.js +0 -211
- package/core/com/app/script.js +0 -155
- package/core/com/cmd/com.json +0 -4
- package/core/com/cmd/config.tpl.json +0 -66
- package/core/com/cmd/drive.js +0 -513
- package/core/com/cmd/index.js +0 -354
- package/core/com/cmd/old/5w2h.js +0 -54
- package/core/com/cmd/old/drive.js +0 -423
- package/core/com/cmd/script.js +0 -11
- package/core/com/component/README.md +0 -3
- package/core/com/component/com.json +0 -4
- package/core/com/component/component.html +0 -16
- package/core/com/component/drive.js +0 -197
- package/core/com/component/index.js +0 -312
- package/core/com/component/script.js +0 -18
- package/core/com/db/com.json +0 -4
- package/core/com/db/drive.js +0 -1160
- package/core/com/db/index.js +0 -176
- package/core/com/event/com.json +0 -4
- package/core/com/event/drive.js +0 -133
- package/core/com/event/index.js +0 -345
- package/core/com/event/script.js +0 -26
- package/core/com/eventer/com.js +0 -477
- package/core/com/eventer/com.json +0 -4
- package/core/com/middleware/com.js +0 -153
- package/core/com/middleware/com.json +0 -4
- package/core/com/middleware/config.tpl.json +0 -8
- package/core/com/middleware/script.js +0 -9
- package/core/com/mqtt/com.json +0 -4
- package/core/com/mqtt/drive.js +0 -600
- package/core/com/mqtt/index.js +0 -572
- package/core/com/mqtt/mm_mqtt.js +0 -330
- package/core/com/mqtt/script.js +0 -604
- package/core/com/msg/com.js +0 -296
- package/core/com/msg/com.json +0 -4
- package/core/com/nav/com.json +0 -4
- package/core/com/nav/config.tpl.json +0 -75
- package/core/com/nav/drive.js +0 -549
- package/core/com/nav/index.js +0 -182
- package/core/com/nav/tpl/admin_pc/page_form.vue +0 -180
- package/core/com/nav/tpl/admin_pc/page_view.vue +0 -124
- package/core/com/nav/tpl/dev_pc/page_default.vue +0 -247
- package/core/com/nav/tpl/dev_pc/page_type.vue +0 -313
- package/core/com/nav/tpl/home_pc/page_default.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_form.vue +0 -137
- package/core/com/nav/tpl/home_pc/page_list.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_nav.vue +0 -221
- package/core/com/nav/tpl/home_pc/page_type.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_view.vue +0 -125
- package/core/com/nav/tpl/home_phone/page_channel.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_default.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_form.vue +0 -137
- package/core/com/nav/tpl/home_phone/page_nav.vue +0 -237
- package/core/com/nav/tpl/home_phone/page_type.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_view.vue +0 -125
- package/core/com/nav/viewmodel.js +0 -296
- package/core/com/param/drive.js +0 -366
- package/core/com/param/index.js +0 -80
- package/core/com/param/script.js +0 -12
- package/core/com/param/test.js +0 -98
- package/core/com/plugin/README.md +0 -3
- package/core/com/plugin/com.json +0 -4
- package/core/com/plugin/config.tpl.json +0 -26
- package/core/com/plugin/drive.js +0 -536
- package/core/com/plugin/index.js +0 -259
- package/core/com/plugin/script.js +0 -213
- package/core/com/rpc/com.json +0 -4
- package/core/com/rpc/drive.js +0 -160
- package/core/com/rpc/index.js +0 -87
- package/core/com/rpc/rpc.js +0 -118
- package/core/com/socket/com.json +0 -4
- package/core/com/socket/config.tpl.json +0 -14
- package/core/com/socket/drive.js +0 -403
- package/core/com/socket/index.js +0 -62
- package/core/com/socket/script.js +0 -42
- package/core/com/sql/drive.js +0 -1087
- package/core/com/sql/index.js +0 -83
- package/core/com/sql/script.js +0 -48
- package/core/com/static/com.json +0 -4
- package/core/com/static/drive.js +0 -220
- package/core/com/static/index.js +0 -149
- package/core/com/static/script.js +0 -28
- package/core/com/task/com.json +0 -4
- package/core/com/task/drive.js +0 -403
- package/core/com/task/index.js +0 -110
- package/core/com/task/script.js +0 -37
- package/core/com/timer/com.js +0 -217
- package/core/com/timer/com.json +0 -4
- package/core/com/tpl/com.js +0 -19
- package/core/com/tpl/com.json +0 -4
- package/lib/actions.js +0 -50
- package/lib/base.js +0 -361
- package/lib/com.js +0 -29
- package/lib/ref.js +0 -121
- package/middleware/mqtt_base/index.js +0 -10
- package/middleware/mqtt_base/middleware.json +0 -10
- package/middleware/performance/index.js +0 -151
- package/middleware/performance/middleware.json +0 -16
- package/middleware/security_audit/index.js +0 -549
- package/middleware/security_audit/middleware.json +0 -48
- package/middleware/security_headers/index.js +0 -487
- package/middleware/security_headers/middleware.json +0 -45
- package/middleware/waf/index.js +0 -348
- package/middleware/waf/middleware.json +0 -10
- package/middleware/waf_ddos/index.js +0 -520
- package/middleware/waf_ddos/middleware.json +0 -38
- package/middleware/waf_ip/index.js +0 -379
- package/middleware/waf_ip/middleware.json +0 -49
- package/middleware/waf_xss/index.js +0 -269
- package/middleware/waf_xss/middleware.json +0 -18
- package/middleware/web_after/index.js +0 -33
- package/middleware/web_after/middleware.json +0 -9
- package/middleware/web_base/index.js +0 -90
- package/middleware/web_base/middleware.json +0 -9
- package/middleware/web_before/index.js +0 -27
- package/middleware/web_before/middleware.json +0 -9
- package/middleware/web_check/index.js +0 -28
- package/middleware/web_check/middleware.json +0 -9
- package/middleware/web_main/index.js +0 -28
- package/middleware/web_main/middleware.json +0 -9
- package/middleware/web_proxy/index.js +0 -37
- package/middleware/web_proxy/middleware.json +0 -9
- package/middleware/web_render/index.js +0 -87
- package/middleware/web_render/middleware.json +0 -9
- package/middleware/web_socket/index.js +0 -34
- package/middleware/web_socket/middleware.json +0 -9
- package/middleware/web_static/index.js +0 -115
- package/middleware/web_static/middleware.json +0 -9
- /package/{core/com → com}/api/README.md +0 -0
- /package/{core/com → com}/db/README.md +0 -0
- /package/{core/com → com}/event/README.md +0 -0
- /package/{core/com → com}/mqtt/README.md +0 -0
- /package/{core/com → com}/nav/README.md +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_default.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_lang.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_nav.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_table.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_type.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_config.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_form.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_nav.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_table.vue +0 -0
- /package/{core/com → com}/nav/tpl/home_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/home_phone/page_list.vue +0 -0
- /package/{core/com → com}/param/README.md +0 -0
- /package/{core/com/cmd → com/pendant}/README.md +0 -0
- /package/{core/com → com}/socket/README.md +0 -0
- /package/{core/com → com}/sql/README.md +0 -0
- /package/{core/com → com}/static/README.md +0 -0
- /package/{core/com → com}/task/README.md +0 -0
package/core/com/plugin/drive.js
DELETED
|
@@ -1,536 +0,0 @@
|
|
|
1
|
-
const compressing = require('compressing');
|
|
2
|
-
const Item = require('mm_machine').Item;
|
|
3
|
-
const conf = require('mm_config');
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Plugin插件驱动类
|
|
7
|
-
* @extends {Item}
|
|
8
|
-
* @class
|
|
9
|
-
*/
|
|
10
|
-
class Drive extends Item {
|
|
11
|
-
/**
|
|
12
|
-
* 构造函数
|
|
13
|
-
* @param {String} dir 当前目录
|
|
14
|
-
* @constructor
|
|
15
|
-
*/
|
|
16
|
-
constructor(dir) {
|
|
17
|
-
super(dir, __dirname);
|
|
18
|
-
this.default_file = "./plugin.json";
|
|
19
|
-
// 默认启用热更新
|
|
20
|
-
this.mode = 3;
|
|
21
|
-
/**
|
|
22
|
-
* 当前语言
|
|
23
|
-
*/
|
|
24
|
-
this.lang_now = "zh_CN";
|
|
25
|
-
/**
|
|
26
|
-
* 语言包
|
|
27
|
-
*/
|
|
28
|
-
this.lang = {};
|
|
29
|
-
|
|
30
|
-
/* 通用项 */
|
|
31
|
-
// 配置参数
|
|
32
|
-
this.config = {
|
|
33
|
-
// 应用域
|
|
34
|
-
"app": "",
|
|
35
|
-
// 名称, 由中英文和下“_”组成, 用于修改或卸载 例如: demo
|
|
36
|
-
// 同时也是版本唯一标识,当商城有两个插件名称相同时,可以通过版本号查询和下载
|
|
37
|
-
"name": "",
|
|
38
|
-
// 标题, 介绍事件作用
|
|
39
|
-
"title": "",
|
|
40
|
-
// 描述, 用于描述该事件有什么用的
|
|
41
|
-
"description": "",
|
|
42
|
-
// 版本号
|
|
43
|
-
"version": "1.0.0",
|
|
44
|
-
// 作者
|
|
45
|
-
"author": "",
|
|
46
|
-
// 官网
|
|
47
|
-
"web": "",
|
|
48
|
-
// 状态 0未启用,1启用
|
|
49
|
-
"state": 1,
|
|
50
|
-
// 显示 0不显示,1显示
|
|
51
|
-
"show": 0,
|
|
52
|
-
// 文件路径, 当调用函数不存在时,会先从文件中加载
|
|
53
|
-
"func_file": "./index.js",
|
|
54
|
-
// 回调函数名 用于决定调用脚本的哪个函数
|
|
55
|
-
"func_name": "",
|
|
56
|
-
// 语言包路径
|
|
57
|
-
"lang_path": "./lang/",
|
|
58
|
-
// 插件图标
|
|
59
|
-
"icon": "/img/logo.png",
|
|
60
|
-
// 指令前缀
|
|
61
|
-
"cmd": "",
|
|
62
|
-
// 是否中断执行
|
|
63
|
-
"end": true,
|
|
64
|
-
// 排序
|
|
65
|
-
"sort": 10,
|
|
66
|
-
// 配置
|
|
67
|
-
"options": []
|
|
68
|
-
};
|
|
69
|
-
// 配置
|
|
70
|
-
this.options = {};
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* 设置配置
|
|
76
|
-
* @param {Object} config 配置
|
|
77
|
-
*/
|
|
78
|
-
Drive.prototype.set_config = function(config) {
|
|
79
|
-
var file = this.filename;
|
|
80
|
-
var cg = Object.assign({}, this.config, config || {});
|
|
81
|
-
this.config = conf(cg, file);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* 插件初始化之后
|
|
86
|
-
*/
|
|
87
|
-
Drive.prototype.set_config_after = function() {
|
|
88
|
-
var options = this.get_config_options();
|
|
89
|
-
this.options = this.merge_options(options);
|
|
90
|
-
this.backup_options();
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* 更新配置
|
|
95
|
-
*/
|
|
96
|
-
Drive.prototype.update_options = function(options = []) {
|
|
97
|
-
var op = this.config.options;
|
|
98
|
-
var list = [];
|
|
99
|
-
for (var i = options.length - 1; i >= 0; i--) {
|
|
100
|
-
var o = options[i];
|
|
101
|
-
var obj = op.get({
|
|
102
|
-
name: o.name
|
|
103
|
-
});
|
|
104
|
-
if (obj) {
|
|
105
|
-
Object.assign(obj, o);
|
|
106
|
-
} else {
|
|
107
|
-
list.push(o);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
for (var i = 0; i < options.length; i++) {
|
|
111
|
-
var o = options[i];
|
|
112
|
-
op.push(o);
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* 更新配置后
|
|
118
|
-
* @param {Object} options
|
|
119
|
-
*/
|
|
120
|
-
Drive.prototype.update_options_after = function(options) {
|
|
121
|
-
// if (this.config.state) {
|
|
122
|
-
// this.restart();
|
|
123
|
-
// }
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* 获取配置参数
|
|
128
|
-
* @return {Object} 返回配置参数
|
|
129
|
-
*/
|
|
130
|
-
Drive.prototype.get_options = function() {
|
|
131
|
-
return this.options;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* 获取配置参数
|
|
136
|
-
* @return {Object} 返回配置参数
|
|
137
|
-
*/
|
|
138
|
-
Drive.prototype.get_config_options = function() {
|
|
139
|
-
var op = this.config.options || [];
|
|
140
|
-
var dict = {};
|
|
141
|
-
for (var i = 0; i < op.length; i++) {
|
|
142
|
-
var o = op[i];
|
|
143
|
-
if (o.type === "number") {
|
|
144
|
-
var val = o.value === 'null' ? '0' : o.value;
|
|
145
|
-
dict[o.name] = Number(val || '0');
|
|
146
|
-
} else if (o.type === "boolean") {
|
|
147
|
-
var val = false;
|
|
148
|
-
if (o.value) {
|
|
149
|
-
if (typeof(o.value) == "string") {
|
|
150
|
-
if (o.value == '1' || o.value == 'true') {
|
|
151
|
-
val = true;
|
|
152
|
-
}
|
|
153
|
-
} else if (typeof(o.value) == "boolean") {
|
|
154
|
-
val = o.value;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
dict[o.name] = val;
|
|
158
|
-
} else if (o.type === "object") {
|
|
159
|
-
var val = o.value === 'null' ? '{}' : o.value;
|
|
160
|
-
dict[o.name] = o.value.toJSON();
|
|
161
|
-
} else if (o.type === "array") {
|
|
162
|
-
var val = o.value === 'null' ? '[]' : o.value;
|
|
163
|
-
dict[o.name] = o.value.toJSON();
|
|
164
|
-
} else if (o.value === "null") {
|
|
165
|
-
dict[o.name] = null;
|
|
166
|
-
} else if (o.type === "string") {
|
|
167
|
-
dict[o.name] = o.value || "";
|
|
168
|
-
} else {
|
|
169
|
-
dict[o.name] = o.value;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
return dict;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* 获取配置参数
|
|
177
|
-
* @param {Object} 设置配置
|
|
178
|
-
* @return {Object} 返回配置参数
|
|
179
|
-
*/
|
|
180
|
-
Drive.prototype.design_option = function(body) {
|
|
181
|
-
var cg = this.config;
|
|
182
|
-
if (Array.isArray(body)) {
|
|
183
|
-
cg.options = body;
|
|
184
|
-
} else {
|
|
185
|
-
var options = cg.options || [];
|
|
186
|
-
var option = options.getObj({
|
|
187
|
-
name: body.name
|
|
188
|
-
});
|
|
189
|
-
if (option) {
|
|
190
|
-
Object.assign(option, body);
|
|
191
|
-
} else {
|
|
192
|
-
options.push(body);
|
|
193
|
-
}
|
|
194
|
-
cg.options = options;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* 保存配置
|
|
200
|
-
*/
|
|
201
|
-
Drive.prototype.save_option = function(options) {
|
|
202
|
-
this.options = options;
|
|
203
|
-
this.backup_options();
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* 保存配置
|
|
208
|
-
*/
|
|
209
|
-
Drive.prototype.backup_options = function() {
|
|
210
|
-
var l = $.slash;
|
|
211
|
-
var file = "/cache/" + l + l + this.filename.right("app" + l).replaceAll(l + "plugin", "").replace(".json",
|
|
212
|
-
"/config.json");
|
|
213
|
-
file = file.fullname();
|
|
214
|
-
file.addDir();
|
|
215
|
-
file.saveJson(this.options);
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* 合并配置
|
|
220
|
-
* @param {Object} cg 配置
|
|
221
|
-
*/
|
|
222
|
-
Drive.prototype.merge_options = function(options) {
|
|
223
|
-
var l = $.slash;
|
|
224
|
-
var file = "/cache/" + l + l + this.filename.right("app" + l).replaceAll(l + "plugin", "").replace(".json",
|
|
225
|
-
"/config.json");
|
|
226
|
-
var options_cache = file.loadJson();
|
|
227
|
-
if (options_cache) {
|
|
228
|
-
$.push(options, options_cache);
|
|
229
|
-
}
|
|
230
|
-
return options;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* 新建脚本
|
|
235
|
-
* @param {String} 文件
|
|
236
|
-
*/
|
|
237
|
-
Drive.prototype.new_script = function(file) {
|
|
238
|
-
var fl = __dirname + "/script.js";
|
|
239
|
-
if (fl.hasFile()) {
|
|
240
|
-
var text = fl.loadText();
|
|
241
|
-
if (text) {
|
|
242
|
-
var name = 'sys';
|
|
243
|
-
var l = $.slash;
|
|
244
|
-
if (file.indexOf('plugin' + l) !== -1) {
|
|
245
|
-
name = file.between('plugin' + l, l);
|
|
246
|
-
if (file.indexOf('app' + l) !== -1) {
|
|
247
|
-
var app = file.between('app' + l, l);
|
|
248
|
-
text = text.replaceAll('{1}', app);
|
|
249
|
-
}
|
|
250
|
-
text = text.replaceAll('{0}', name);
|
|
251
|
-
} else if (file.indexOf('app' + l) !== -1) {
|
|
252
|
-
name = file.between('app' + l, l);
|
|
253
|
-
text = text.replaceAll('{0}', name)
|
|
254
|
-
}
|
|
255
|
-
file.saveText(text);
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* 新建配置
|
|
262
|
-
* @param {String} 文件
|
|
263
|
-
*/
|
|
264
|
-
Drive.prototype.new_config = function(file) {
|
|
265
|
-
var fl = __dirname + "/config.tpl.json";
|
|
266
|
-
if (fl.hasFile()) {
|
|
267
|
-
var text = fl.loadText();
|
|
268
|
-
if (text) {
|
|
269
|
-
var name = 'sys';
|
|
270
|
-
var l = $.slash;
|
|
271
|
-
if (file.indexOf('plugin' + l) !== -1) {
|
|
272
|
-
name = file.between('plugin' + l, l);
|
|
273
|
-
if (file.indexOf('app' + l) !== -1) {
|
|
274
|
-
var app = file.between('app' + l, l);
|
|
275
|
-
text = text.replaceAll('{1}', app).replaceAll('{2}', app + '.' + name);
|
|
276
|
-
}
|
|
277
|
-
text = text.replaceAll('{0}', name);
|
|
278
|
-
} else if (file.indexOf('app' + l) !== -1) {
|
|
279
|
-
name = file.between('app' + l, l);
|
|
280
|
-
text = text.replaceAll('{0}', name).replaceAll('\r\n "app": "{1}",', '').replaceAll('插件', '应用')
|
|
281
|
-
.replaceAll('{2}', name);
|
|
282
|
-
}
|
|
283
|
-
file.saveText(text);
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
};
|
|
287
|
-
|
|
288
|
-
/**
|
|
289
|
-
* 设置语言
|
|
290
|
-
* @param {Sting} lang
|
|
291
|
-
* @return {String} 成功返回null,否则返回错误提示
|
|
292
|
-
*/
|
|
293
|
-
Drive.prototype.set_lang = function(lang) {
|
|
294
|
-
var msg = null;
|
|
295
|
-
if (!lang) {
|
|
296
|
-
lang = "zh_CN"
|
|
297
|
-
}
|
|
298
|
-
var file = this.config.lang_path + ".json";
|
|
299
|
-
if (file.hasFile()) {
|
|
300
|
-
var obj = file.loadJson();
|
|
301
|
-
if (obj) {
|
|
302
|
-
this.lang = obj;
|
|
303
|
-
} else {
|
|
304
|
-
msg = "语言包不是正确的json格式";
|
|
305
|
-
}
|
|
306
|
-
} else {
|
|
307
|
-
msg = "语言包文件不存在";
|
|
308
|
-
}
|
|
309
|
-
return msg;
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* 安装
|
|
314
|
-
* @param {Object} option 配置参数
|
|
315
|
-
* @return {String} 成功返回null,否则返回错误提示
|
|
316
|
-
*/
|
|
317
|
-
Drive.prototype.install = function(option) {
|
|
318
|
-
var msg = null;
|
|
319
|
-
return msg;
|
|
320
|
-
};
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* 重启设备
|
|
324
|
-
* @param {Object} option 配置
|
|
325
|
-
*/
|
|
326
|
-
Drive.prototype.restart = async function(option) {
|
|
327
|
-
await this.exec('stop');
|
|
328
|
-
await this.exec('start');
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
/**
|
|
332
|
-
* 初始化
|
|
333
|
-
* @param {Object} option 配置参数
|
|
334
|
-
* @return {String} 成功返回null, 否则返回错误提示
|
|
335
|
-
*/
|
|
336
|
-
Drive.prototype.init = function(option) {
|
|
337
|
-
var msg = null;
|
|
338
|
-
return msg;
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* 更新
|
|
343
|
-
* @param {Object} option 配置参数
|
|
344
|
-
* @return {String} 成功返回null, 否则返回错误提示
|
|
345
|
-
*/
|
|
346
|
-
Drive.prototype.update = function(option) {
|
|
347
|
-
var msg = null;
|
|
348
|
-
return msg;
|
|
349
|
-
};
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* 卸载
|
|
353
|
-
* @param {Object} option 配置参数
|
|
354
|
-
* @return {String} 成功返回null,否则返回错误提示
|
|
355
|
-
*/
|
|
356
|
-
Drive.prototype.uninstall = function(option) {
|
|
357
|
-
var msg = null;
|
|
358
|
-
return msg;
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* 启动
|
|
363
|
-
* @param {Object} opiton 配置参数
|
|
364
|
-
* @return {String} 成功返回null,否则返回错误提示
|
|
365
|
-
*/
|
|
366
|
-
Drive.prototype.start = function(opiton) {
|
|
367
|
-
var msg = null;
|
|
368
|
-
return msg;
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* 暂停
|
|
373
|
-
* @param {Object} opiton 配置参数
|
|
374
|
-
* @return {String} 成功返回null,否则返回错误提示
|
|
375
|
-
*/
|
|
376
|
-
Drive.prototype.stop = function(opiton) {
|
|
377
|
-
var msg = null;
|
|
378
|
-
return msg;
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* 结束
|
|
383
|
-
* @param {Object} opiton 配置参数
|
|
384
|
-
* @return {String} 成功返回null,否则返回错误提示
|
|
385
|
-
*/
|
|
386
|
-
Drive.prototype.end = function(opiton) {
|
|
387
|
-
var msg = null;
|
|
388
|
-
return msg;
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
/**
|
|
392
|
-
* API接口(用于其他插件调用该插件时)
|
|
393
|
-
* @param {Object} ctx HTTP上下文
|
|
394
|
-
* @param {Object} db 数据库管理器
|
|
395
|
-
* @return {Object} 执行结果
|
|
396
|
-
*/
|
|
397
|
-
Drive.prototype.api = function(ctx, db) {
|
|
398
|
-
var ret = {};
|
|
399
|
-
return ret;
|
|
400
|
-
};
|
|
401
|
-
|
|
402
|
-
/**
|
|
403
|
-
* 商店(用于下载插件相关模块)
|
|
404
|
-
* @param {String} item 插件项
|
|
405
|
-
* @return {String} 成功返回null,否则返回错误提示
|
|
406
|
-
*/
|
|
407
|
-
Drive.prototype.store = function(item) {
|
|
408
|
-
var msg = null;
|
|
409
|
-
return msg;
|
|
410
|
-
};
|
|
411
|
-
|
|
412
|
-
/**
|
|
413
|
-
* 插件
|
|
414
|
-
* @param {String} item 插件项
|
|
415
|
-
* @return {Object} 旗下插件和信息
|
|
416
|
-
*/
|
|
417
|
-
Drive.prototype.plugin = function(item) {
|
|
418
|
-
|
|
419
|
-
};
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* 帮助(讲解插件使用方法)
|
|
423
|
-
* @param {String} item 帮助项
|
|
424
|
-
* @return {String} 返回使用方法明细
|
|
425
|
-
*/
|
|
426
|
-
Drive.prototype.help = function(item) {
|
|
427
|
-
var body = "";
|
|
428
|
-
return body;
|
|
429
|
-
};
|
|
430
|
-
|
|
431
|
-
/**
|
|
432
|
-
* 主程序
|
|
433
|
-
* @param {Object} param1 参数1
|
|
434
|
-
* @param {Object} param2 参数2
|
|
435
|
-
* @return {Object} 返回执行结果
|
|
436
|
-
*/
|
|
437
|
-
Drive.prototype.main = function(param1, param2) {
|
|
438
|
-
return null;
|
|
439
|
-
};
|
|
440
|
-
|
|
441
|
-
/**
|
|
442
|
-
* 指令(类似命令提示符)
|
|
443
|
-
* @param {String} content 指令内容
|
|
444
|
-
* @return {String} 执行结果
|
|
445
|
-
*/
|
|
446
|
-
Drive.prototype.cmd = function(content) {
|
|
447
|
-
var body = "";
|
|
448
|
-
return body;
|
|
449
|
-
};
|
|
450
|
-
|
|
451
|
-
/**
|
|
452
|
-
* 聊天(通过聊天的方式驱动插件, 用于机器人开发)
|
|
453
|
-
* @param {String} from_user 发送消息人
|
|
454
|
-
* @param {String} to_user 接收消息人
|
|
455
|
-
* @param {String} content 内容
|
|
456
|
-
* @param {String} group 群组 如果是个人,群组为空
|
|
457
|
-
* @param {Number} type 群类型, 1永久会话/群、2临时会话/群
|
|
458
|
-
* @param {String} msg_type 消息类型, event事件型、message消息型。默认消息型
|
|
459
|
-
* @param {Object} 数据管理器
|
|
460
|
-
* @return {String} 回复内容
|
|
461
|
-
*/
|
|
462
|
-
Drive.prototype.chat = async function(from_user, to_user, group, content, type, msg_type, db) {
|
|
463
|
-
var body = "";
|
|
464
|
-
return body;
|
|
465
|
-
};
|
|
466
|
-
|
|
467
|
-
/**
|
|
468
|
-
* 指令(类似命令提示符)
|
|
469
|
-
* @param {String} content 指令内容
|
|
470
|
-
* @return {String} 执行结果
|
|
471
|
-
*/
|
|
472
|
-
Drive.prototype.run_cmd = async function(content) {
|
|
473
|
-
if (!content) {
|
|
474
|
-
content = "";
|
|
475
|
-
}
|
|
476
|
-
var ret;
|
|
477
|
-
try {
|
|
478
|
-
ret = this.cmd(content);
|
|
479
|
-
} catch (err) {
|
|
480
|
-
$.log.error("运行插件指令失败!", this.config.name, err);
|
|
481
|
-
}
|
|
482
|
-
if (!ret) {
|
|
483
|
-
ret = "";
|
|
484
|
-
}
|
|
485
|
-
return ret;
|
|
486
|
-
};
|
|
487
|
-
|
|
488
|
-
/**
|
|
489
|
-
* 聊天(通过聊天的方式驱动插件, 用于机器人开发)
|
|
490
|
-
* @param {String} from_user 发送消息人
|
|
491
|
-
* @param {String} to_user 接收消息人
|
|
492
|
-
* @param {String} content 内容
|
|
493
|
-
* @param {String} group 群组 如果是个人,群组为空
|
|
494
|
-
* @param {Number} type 群类型, 1永久会话/群、2临时会话/群
|
|
495
|
-
* @param {String} msg_type 消息类型, event事件型、message消息型。默认消息型
|
|
496
|
-
* @return {String} 回复内容
|
|
497
|
-
*/
|
|
498
|
-
Drive.prototype.run_chat = async function(from_user, to_user, content, group, type, msg_type, db) {
|
|
499
|
-
if (!content) {
|
|
500
|
-
content = "";
|
|
501
|
-
}
|
|
502
|
-
if (!msg_type) {
|
|
503
|
-
msg_type = "message";
|
|
504
|
-
}
|
|
505
|
-
if (!group) {
|
|
506
|
-
group = "";
|
|
507
|
-
}
|
|
508
|
-
var ret;
|
|
509
|
-
try {
|
|
510
|
-
ret = this.chat(from_user, to_user, group, content, type, msg_type, db);
|
|
511
|
-
} catch (err) {
|
|
512
|
-
$.log.error("运行插件聊天失败!", this.config.name, err);
|
|
513
|
-
}
|
|
514
|
-
if (!ret) {
|
|
515
|
-
ret = "";
|
|
516
|
-
}
|
|
517
|
-
return ret;
|
|
518
|
-
};
|
|
519
|
-
|
|
520
|
-
/**
|
|
521
|
-
* 压缩插件
|
|
522
|
-
* @param {String} 要压缩的目录
|
|
523
|
-
* @returns {String} 打包成功返回压缩包文件地址
|
|
524
|
-
*/
|
|
525
|
-
Drive.prototype.zip = async function(zip_dir = "/static/file/zip/") {
|
|
526
|
-
var dir = this.filename.dirname();
|
|
527
|
-
var file = ("./" + this.config.name + '.zip').fullname(zip_dir);
|
|
528
|
-
file.addDir();
|
|
529
|
-
var done = await compressing.zip.compressDir(dir, file);
|
|
530
|
-
if (file.hasFile()) {
|
|
531
|
-
return file;
|
|
532
|
-
}
|
|
533
|
-
return null;
|
|
534
|
-
}
|
|
535
|
-
|
|
536
|
-
module.exports = Drive;
|