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/sql/index.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
const Manager = require("mm_machine").Manager;
|
|
2
|
-
const Drive = require("./drive");
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Sql语句拓展类
|
|
6
|
-
* @augments {Manager}
|
|
7
|
-
* @class
|
|
8
|
-
*/
|
|
9
|
-
class Sql 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: "sql管理",
|
|
25
|
-
/**
|
|
26
|
-
* 描述
|
|
27
|
-
* @type {string}
|
|
28
|
-
*/
|
|
29
|
-
description: "这是sql管理器",
|
|
30
|
-
/**
|
|
31
|
-
* 检索文件名
|
|
32
|
-
* @type {string}
|
|
33
|
-
*/
|
|
34
|
-
filename: "sql.json",
|
|
35
|
-
/**
|
|
36
|
-
* 模板目录
|
|
37
|
-
* @type {string}
|
|
38
|
-
*/
|
|
39
|
-
tpl_dir: __dirname,
|
|
40
|
-
/**
|
|
41
|
-
* 基础目录
|
|
42
|
-
* @type {string}
|
|
43
|
-
*/
|
|
44
|
-
base_dir: "../common/sql".fullname(__dirname),
|
|
45
|
-
/**
|
|
46
|
-
* 自定义目录,加载项目自定义资源
|
|
47
|
-
* @type {string}
|
|
48
|
-
*/
|
|
49
|
-
dir: "./app".fullname(),
|
|
50
|
-
/**
|
|
51
|
-
* 搜索模式 dir按目录搜索 | file按文件名搜索
|
|
52
|
-
* @type {string}
|
|
53
|
-
*/
|
|
54
|
-
search_way: "file",
|
|
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
|
-
/**
|
|
73
|
-
* 构造函数
|
|
74
|
-
* @param {object} config 配置参数
|
|
75
|
-
* @param {object} parent 父级模块
|
|
76
|
-
*/
|
|
77
|
-
constructor(config, parent) {
|
|
78
|
-
super({ ...Sql.config, ...config }, parent);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* sql驱动类
|
|
84
|
-
* @type {Drive}
|
|
85
|
-
*/
|
|
86
|
-
Sql.prototype.Drive = Drive;
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* 排序
|
|
90
|
-
*/
|
|
91
|
-
Sql.prototype.sort = function () {
|
|
92
|
-
let infos = this.getInfos();
|
|
93
|
-
infos.sortBy("asc", "name");
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* 执行sql
|
|
98
|
-
* @param {string} name 名称
|
|
99
|
-
* @param {object} query 查询参数
|
|
100
|
-
* @param {object} body 修改参数
|
|
101
|
-
* @param {object} db 数据库管理器 (object) 只支持可用sql语句的数据库
|
|
102
|
-
* @returns {object} 执行结果
|
|
103
|
-
*/
|
|
104
|
-
Sql.prototype.run = async function (name, query, body, db) {
|
|
105
|
-
var obj = this.getMod(name);
|
|
106
|
-
if (obj) {
|
|
107
|
-
if (!obj.isLoaded()) {
|
|
108
|
-
await obj.do("load");
|
|
109
|
-
}
|
|
110
|
-
var ret = await obj.run(query, body, db);
|
|
111
|
-
if (this.mode > 4) {
|
|
112
|
-
obj.do("reload");
|
|
113
|
-
}
|
|
114
|
-
return ret;
|
|
115
|
-
}
|
|
116
|
-
return null;
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
exports.Sql = Sql;
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Sql模板池
|
|
123
|
-
*/
|
|
124
|
-
if (!$.pool.sql) {
|
|
125
|
-
$.pool.sql = {};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Sql管理器,用于创建缓存
|
|
130
|
-
* @param {string} scope 作用域
|
|
131
|
-
* @param {string} title 标题
|
|
132
|
-
* @returns {object} 返回一个缓存类
|
|
133
|
-
*/
|
|
134
|
-
function sqlAdmin(scope, title) {
|
|
135
|
-
var sc = scope || $.val.scope + "";
|
|
136
|
-
var obj = $.pool.sql[sc];
|
|
137
|
-
if (!obj) {
|
|
138
|
-
$.pool.sql[sc] = new Sql({
|
|
139
|
-
name: sc,
|
|
140
|
-
title: title,
|
|
141
|
-
});
|
|
142
|
-
obj = $.pool.sql[sc];
|
|
143
|
-
}
|
|
144
|
-
return obj;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* @module 导出Sql管理器
|
|
149
|
-
*/
|
|
150
|
-
if ($.admin) {
|
|
151
|
-
$.admin.sql = sqlAdmin;
|
|
152
|
-
}
|
package/com/sql/script.tpl.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
/**
|
|
5
|
-
* 执行前, 用于过滤参数
|
|
6
|
-
* @param {object} params 参数对象,包含query和body 如:{ query: {} body: {} }
|
|
7
|
-
* @returns {object} 过滤后的参数
|
|
8
|
-
*/
|
|
9
|
-
before(params) {
|
|
10
|
-
return params;
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* 验证, 用于判断是否执行
|
|
15
|
-
* @param {object} params 参数对象,包含query和body 如:{ query: {} body: {} }
|
|
16
|
-
* @returns {boolean} 验证通过返回true, 失败返回false
|
|
17
|
-
*/
|
|
18
|
-
check(params) {
|
|
19
|
-
return true;
|
|
20
|
-
},
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 执行后 可用于附加执行
|
|
24
|
-
* @param {object} params 参数对象,包含query和body 如:{ query: {} body: {} }
|
|
25
|
-
* @param {object} sql SQL模板对象
|
|
26
|
-
* @param {object} ret 最终执行结果
|
|
27
|
-
* @returns {object} 返回执行结果
|
|
28
|
-
*/
|
|
29
|
-
after(params, sql, ret) {
|
|
30
|
-
return ret;
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 执行主函数
|
|
35
|
-
* @param {object} params 参数对象,包含query和body 如:{ query: {} body: {} }
|
|
36
|
-
* @returns {object} 返回执行结果
|
|
37
|
-
*/
|
|
38
|
-
main(params) {
|
|
39
|
-
var sql = '';
|
|
40
|
-
var ret = null;
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
sql,
|
|
44
|
-
ret
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
};
|
package/com/static/README.md
DELETED
package/com/static/com.json
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// 路由路径,注意:这里是泛路径,相当于/*
|
|
3
|
-
"path": "${path || '/${name}'}",
|
|
4
|
-
// 名称, 由中英文和下“_”组成, 用于修改或卸载 例如: demo
|
|
5
|
-
"name": "${name || 'static'}",
|
|
6
|
-
// 标题, 用于查询时
|
|
7
|
-
"title": "${title || 'static资源'}",
|
|
8
|
-
// 状态 0未启用,1启用
|
|
9
|
-
"state": 1,
|
|
10
|
-
// 资源缓存寿命,单位:秒
|
|
11
|
-
"max_age": 0,
|
|
12
|
-
// 是否恒久不变,一般资源文件可能变化,所以这里一般是false
|
|
13
|
-
"immutable": false,
|
|
14
|
-
// 是否使用brotli压缩方式
|
|
15
|
-
"brotli": true,
|
|
16
|
-
// 是否启用gzip压缩方式
|
|
17
|
-
"gzip": true,
|
|
18
|
-
// 是否限制访问指定拓展名的文件,多个
|
|
19
|
-
"extensions": null,
|
|
20
|
-
// 是否转换JS、vue代码为amd标准,true的情况下会把es6和commonJS都转成amd格式
|
|
21
|
-
"convert_amd": false,
|
|
22
|
-
// 调用脚本文件,如果请求改路由情况会调用改脚本文件 ./static.js
|
|
23
|
-
"main": ""
|
|
24
|
-
}
|
package/com/static/drive.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
const send = require('koa-send');
|
|
2
|
-
const Item = require('mm_machine').Drive;
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 静态文件驱动类
|
|
6
|
-
* @augments {Item}
|
|
7
|
-
* @class
|
|
8
|
-
*/
|
|
9
|
-
class Drive extends Item {
|
|
10
|
-
static config = {
|
|
11
|
-
// 应用名
|
|
12
|
-
'app': 'server',
|
|
13
|
-
// 插件名
|
|
14
|
-
'plugin': 'sys',
|
|
15
|
-
// 物理根目录
|
|
16
|
-
'root': '',
|
|
17
|
-
// 路由根路径
|
|
18
|
-
'path': '',
|
|
19
|
-
// 名称
|
|
20
|
-
'name': '',
|
|
21
|
-
// 首页
|
|
22
|
-
'index': 'index.html',
|
|
23
|
-
// 重定向
|
|
24
|
-
'redirect': true,
|
|
25
|
-
// 缓存保留10分钟
|
|
26
|
-
'max_age': 60 * 10,
|
|
27
|
-
// 是否保持不变
|
|
28
|
-
'immutable': true,
|
|
29
|
-
// 是否启用brotli压缩
|
|
30
|
-
'brotli': true,
|
|
31
|
-
// 是否启用gizp压缩
|
|
32
|
-
'gzip': true,
|
|
33
|
-
// 允许访问的拓展名
|
|
34
|
-
'extensions': null,
|
|
35
|
-
// 是否将ES6转换AMD
|
|
36
|
-
'convert_amd': true,
|
|
37
|
-
// 主程序文件 - 默认为空
|
|
38
|
-
'main': ''
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* 构造函数
|
|
42
|
-
* @param {object} config 配置参数
|
|
43
|
-
* @param {object} parent 父对象
|
|
44
|
-
* @class
|
|
45
|
-
*/
|
|
46
|
-
constructor(config, parent) {
|
|
47
|
-
super({ ...Drive.config, ...config }, parent);
|
|
48
|
-
// 更新并重载
|
|
49
|
-
this.mode = 3;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* 发送文件函数
|
|
55
|
-
*/
|
|
56
|
-
Drive.prototype.send = send;
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 更新配置对象前
|
|
60
|
-
*/
|
|
61
|
-
Drive.prototype._preset = function () {
|
|
62
|
-
var cg = this.config;
|
|
63
|
-
if (cg.maxAge) {
|
|
64
|
-
cg.max_age = cg.maxAge * 1000;
|
|
65
|
-
delete cg.maxAge;
|
|
66
|
-
}
|
|
67
|
-
if (!cg.app) {
|
|
68
|
-
cg.app = this.getAppName(this.config_file);
|
|
69
|
-
}
|
|
70
|
-
if (!cg.plugin) {
|
|
71
|
-
cg.plugin = this.getPluginName(this.config_file);
|
|
72
|
-
}
|
|
73
|
-
if (!cg.path) {
|
|
74
|
-
let app = cg.app || this.getAppName(this.config_file);
|
|
75
|
-
let plugin = cg.plugin || this.getPluginName(this.config_file);
|
|
76
|
-
if (plugin) {
|
|
77
|
-
cg.path = `/${app}/${plugin}/`;
|
|
78
|
-
}
|
|
79
|
-
else {
|
|
80
|
-
cg.path = `/${app}/`;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
else if (!cg.path.endsWith('/')) {
|
|
84
|
-
cg.path += '/';
|
|
85
|
-
}
|
|
86
|
-
if (!cg.root) {
|
|
87
|
-
cg.root = this._getRoot(this.config_file);
|
|
88
|
-
}
|
|
89
|
-
const Static = require('mm_statics').Static;
|
|
90
|
-
this.static = new Static(cg);
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* 获取应用名
|
|
95
|
-
* @param {string} file 文件路径
|
|
96
|
-
* @returns {string} 应用名
|
|
97
|
-
*/
|
|
98
|
-
Drive.prototype.getAppName = function (file) {
|
|
99
|
-
if (!file || typeof file !== 'string') {
|
|
100
|
-
return '';
|
|
101
|
-
}
|
|
102
|
-
return file.between('app/', '/') || '';
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* 获取插件名
|
|
107
|
-
* @param {string} file 文件路径
|
|
108
|
-
* @returns {string} 插件名
|
|
109
|
-
*/
|
|
110
|
-
Drive.prototype.getPluginName = function (file) {
|
|
111
|
-
if (!file || typeof file !== 'string') {
|
|
112
|
-
return '';
|
|
113
|
-
}
|
|
114
|
-
return file.between('plugin/', '/') || '';
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* 获取物理根目录
|
|
119
|
-
* @param {string} file 文件路径
|
|
120
|
-
* @returns {string} 物理根目录
|
|
121
|
-
*/
|
|
122
|
-
Drive.prototype._getRoot = function (file) {
|
|
123
|
-
if (!file || typeof file !== 'string') {
|
|
124
|
-
return '';
|
|
125
|
-
}
|
|
126
|
-
let f = file.replace(/\\/g, '/');
|
|
127
|
-
let dir = f.dirname().replace(/\\/g, '/').toLowerCase();
|
|
128
|
-
let ph = $.run_path.replace(/\\/g, '/').toLowerCase();
|
|
129
|
-
return dir.replace(ph, '.');
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* 执行前
|
|
134
|
-
* @param {object} ctx http请求上下文
|
|
135
|
-
* @param {object} path 文件路径
|
|
136
|
-
*/
|
|
137
|
-
Drive.prototype.before = async function (ctx, path) { };
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* 执行
|
|
141
|
-
* @param {object} ctx http请求上下文
|
|
142
|
-
* @param {object} path 文件路径
|
|
143
|
-
* @returns {boolean} 成功发送返回true,失败返回false
|
|
144
|
-
*/
|
|
145
|
-
Drive.prototype.main = async function (ctx, path) {
|
|
146
|
-
return send(ctx, path, this.config);
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* 执行后
|
|
151
|
-
* @param {object} ctx http请求上下文
|
|
152
|
-
* @param {object} path 文件路径
|
|
153
|
-
*/
|
|
154
|
-
Drive.prototype.after = async function (ctx, path) { };
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* 执行静态文件
|
|
158
|
-
* @param {object} ctx Http请求上下文
|
|
159
|
-
* @param {object} next 跳过当前函数
|
|
160
|
-
* @returns {string} 执行成功返回文件路径
|
|
161
|
-
*/
|
|
162
|
-
Drive.prototype.run = async function (ctx, next) {
|
|
163
|
-
return await this.static.main(ctx, next);
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* 获取名称
|
|
168
|
-
* @param {string} file 文件路径
|
|
169
|
-
* @returns {string} 名称
|
|
170
|
-
*/
|
|
171
|
-
Drive.prototype._getName = function (file) {
|
|
172
|
-
return file.dirname().dirname().basename();
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* 获取模型
|
|
177
|
-
* @param {string} type 模型类型
|
|
178
|
-
* @returns {object} 返回获取到的模型
|
|
179
|
-
*/
|
|
180
|
-
Drive.prototype.getModel = function (type) {
|
|
181
|
-
let model = { ...this.config };
|
|
182
|
-
let dir = this.getDir();
|
|
183
|
-
let l = $.slash;
|
|
184
|
-
let app_name = dir.between('app' + l, l);
|
|
185
|
-
let plugin_name = dir.between('plugin' + l, l);
|
|
186
|
-
let name = dir.basename();
|
|
187
|
-
model.app = app_name;
|
|
188
|
-
model.plugin = plugin_name;
|
|
189
|
-
model.name = model.name || plugin_name ? plugin_name + '_' + name : app_name + '_' + name;
|
|
190
|
-
model.path = model.path || plugin_name ? `/${app_name}/${plugin_name}/` : `/${app_name}/`;
|
|
191
|
-
return model;
|
|
192
|
-
};
|
|
193
|
-
|
|
194
|
-
module.exports = Drive;
|
package/com/static/index.js
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
const Manager = require("mm_machine").Manager;
|
|
2
|
-
const Drive = require("./drive");
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 静态文件管理类
|
|
6
|
-
* @augments {Manager}
|
|
7
|
-
* @class
|
|
8
|
-
*/
|
|
9
|
-
class Static 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: "静态文件管理",
|
|
25
|
-
/**
|
|
26
|
-
* 描述
|
|
27
|
-
* @type {string}
|
|
28
|
-
*/
|
|
29
|
-
description: "这是静态文件管理器",
|
|
30
|
-
/**
|
|
31
|
-
* 检索文件名
|
|
32
|
-
* @type {string}
|
|
33
|
-
*/
|
|
34
|
-
filename: "static.json",
|
|
35
|
-
/**
|
|
36
|
-
* 模板目录
|
|
37
|
-
* @type {string}
|
|
38
|
-
*/
|
|
39
|
-
tpl_dir: __dirname,
|
|
40
|
-
/**
|
|
41
|
-
* 基础目录
|
|
42
|
-
* @type {string}
|
|
43
|
-
*/
|
|
44
|
-
base_dir: "../common/static".fullname(__dirname),
|
|
45
|
-
/**
|
|
46
|
-
* 自定义目录,加载项目自定义资源
|
|
47
|
-
* @type {string}
|
|
48
|
-
*/
|
|
49
|
-
dir: "./app".fullname(),
|
|
50
|
-
/**
|
|
51
|
-
* 搜索模式 dir按目录搜索 | file按文件名搜索
|
|
52
|
-
* @type {string}
|
|
53
|
-
*/
|
|
54
|
-
search_way: "file",
|
|
55
|
-
/**
|
|
56
|
-
* 是否懒加载
|
|
57
|
-
* @type {boolean}
|
|
58
|
-
*/
|
|
59
|
-
lazy_load: false,
|
|
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({ ...Static.config, ...config }, parent);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* 处理请求
|
|
88
|
-
* @param {object} ctx Http请求上下文
|
|
89
|
-
* @param {object} next 跳过函数
|
|
90
|
-
*/
|
|
91
|
-
async _handleRequest(ctx, next) {
|
|
92
|
-
var md = ctx.method;
|
|
93
|
-
var path = ctx.path;
|
|
94
|
-
if (md === "GET" || md === "HEAD") {
|
|
95
|
-
await this._handleGetRequest(ctx, next, path);
|
|
96
|
-
} else {
|
|
97
|
-
await next();
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* 处理GET请求
|
|
103
|
-
* @param {object} ctx Http请求上下文
|
|
104
|
-
* @param {object} next 跳过函数
|
|
105
|
-
*/
|
|
106
|
-
async run(ctx, next) {
|
|
107
|
-
var done;
|
|
108
|
-
var infos = this.getInfos();
|
|
109
|
-
var len = infos.length;
|
|
110
|
-
let path = ctx.path;
|
|
111
|
-
if (path.indexOf(".") !== -1) {
|
|
112
|
-
done = await this._tryServeFile(ctx, infos, len, async () => {});
|
|
113
|
-
if (!done) {
|
|
114
|
-
await next();
|
|
115
|
-
}
|
|
116
|
-
} else {
|
|
117
|
-
await next();
|
|
118
|
-
await this._handleDirReq(ctx, infos, len, path);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* 尝试提供文件服务
|
|
124
|
-
* @param {object} ctx Http请求上下文
|
|
125
|
-
* @param {Array} infos 驱动信息列表
|
|
126
|
-
* @param {number} len 列表长度
|
|
127
|
-
* @param {object} next 跳过函数
|
|
128
|
-
* @returns {boolean} 是否成功
|
|
129
|
-
*/
|
|
130
|
-
async _tryServeFile(ctx, infos, len, next) {
|
|
131
|
-
for (var i = 0; i < len; i++) {
|
|
132
|
-
var info = infos[i];
|
|
133
|
-
if (info.state === 1) {
|
|
134
|
-
let mod = this.getMod(info.name);
|
|
135
|
-
if (mod) {
|
|
136
|
-
if (!mod.isLoaded()) {
|
|
137
|
-
await mod.do("load");
|
|
138
|
-
}
|
|
139
|
-
var done = await mod.run(ctx, next);
|
|
140
|
-
if (done) {
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return false;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* 处理目录请求
|
|
151
|
-
* @param {object} ctx Http请求上下文
|
|
152
|
-
* @param {Array} infos 驱动信息列表
|
|
153
|
-
* @param {number} len 列表长度
|
|
154
|
-
* @param {string} path 请求路径
|
|
155
|
-
*/
|
|
156
|
-
async _handleDirReq(ctx, infos, len, path) {
|
|
157
|
-
var q = ctx.request.querystring;
|
|
158
|
-
for (var i = 0; i < len; i++) {
|
|
159
|
-
var info = infos[i];
|
|
160
|
-
if (info.state === 1) {
|
|
161
|
-
let mod = this.getMod(info.name);
|
|
162
|
-
if (mod) {
|
|
163
|
-
var p = mod.config.path;
|
|
164
|
-
if (path === p) {
|
|
165
|
-
this._handleExactMatch(ctx, q, p);
|
|
166
|
-
break;
|
|
167
|
-
} else {
|
|
168
|
-
if (!mod.isLoaded()) {
|
|
169
|
-
await mod.do("load");
|
|
170
|
-
}
|
|
171
|
-
var done = await mod.run(ctx, () => {});
|
|
172
|
-
if (done) {
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* 处理精确匹配
|
|
183
|
-
* @param {object} ctx Http请求上下文
|
|
184
|
-
* @param {string} q 查询字符串
|
|
185
|
-
* @param {string} p 路径
|
|
186
|
-
*/
|
|
187
|
-
_handleExactMatch(ctx, q, p) {
|
|
188
|
-
if (ctx.status === 404) {
|
|
189
|
-
if (q) {
|
|
190
|
-
ctx.redirect(p + "/?" + q);
|
|
191
|
-
} else {
|
|
192
|
-
ctx.redirect(p + "/");
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
/**
|
|
199
|
-
* 静态文件驱动类
|
|
200
|
-
* @type {Drive}
|
|
201
|
-
*/
|
|
202
|
-
Static.prototype.Drive = Drive;
|
|
203
|
-
|
|
204
|
-
exports.Static = Static;
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* 创建全局管理器
|
|
208
|
-
*/
|
|
209
|
-
if (!$.pool.static) {
|
|
210
|
-
$.pool.static = {};
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* 静态文件管理器
|
|
215
|
-
* @param {string} scope 作用域
|
|
216
|
-
* @param {string} title 标题
|
|
217
|
-
* @returns {object} 返回一个缓存类
|
|
218
|
-
*/
|
|
219
|
-
function staticAdmin(scope, title) {
|
|
220
|
-
var sc = scope || $.val.scope + "";
|
|
221
|
-
var obj = $.pool.static[sc];
|
|
222
|
-
if (!obj) {
|
|
223
|
-
$.pool.static[sc] = new Static({
|
|
224
|
-
name: sc,
|
|
225
|
-
title: title,
|
|
226
|
-
});
|
|
227
|
-
obj = $.pool.static[sc];
|
|
228
|
-
}
|
|
229
|
-
return obj;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
/**
|
|
233
|
-
* @module 导出Static管理器
|
|
234
|
-
*/
|
|
235
|
-
if ($.admin) {
|
|
236
|
-
$.admin.static = staticAdmin;
|
|
237
|
-
}
|
package/com/static/script.tpl.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
module.exports = {
|
|
3
|
-
/**
|
|
4
|
-
* 执行前
|
|
5
|
-
* @param {object} ctx http请求上下文
|
|
6
|
-
* @param {object} path 文件路径
|
|
7
|
-
*/
|
|
8
|
-
async before(ctx, path) { },
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 执行
|
|
12
|
-
* @param {object} ctx http请求上下文
|
|
13
|
-
* @param {object} path 文件路径
|
|
14
|
-
* @returns {boolean} 成功发送返回true,失败返回false
|
|
15
|
-
*/
|
|
16
|
-
async main(ctx, path) {
|
|
17
|
-
return this.send(ctx, path, this.config);
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* 执行后
|
|
22
|
-
* @param {object} ctx http请求上下文
|
|
23
|
-
* @param {object} path 文件路径
|
|
24
|
-
*/
|
|
25
|
-
async after(ctx, path) {
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
};
|
package/com/task/README.md
DELETED