mm_os 4.3.6 → 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.
Files changed (234) hide show
  1. package/README.md +101 -504
  2. package/index.js +26 -19
  3. package/lib/loader.js +787 -0
  4. package/lib/os.js +369 -0
  5. package/package.json +55 -80
  6. package/LICENSE +0 -21
  7. package/README_EN.md +0 -505
  8. package/adapter/adapter.js +0 -484
  9. package/adapter/custom_persistence.js +0 -661
  10. package/adapter/mqtt.js +0 -254
  11. package/adapter/socket.js +0 -244
  12. package/adapter/web.js +0 -92
  13. package/adapter/websocket.js +0 -43
  14. package/ai.js +0 -130
  15. package/com/api/README.md +0 -3
  16. package/com/api/com.json +0 -5
  17. package/com/api/config.tpl.json +0 -41
  18. package/com/api/drive.js +0 -732
  19. package/com/api/index.js +0 -201
  20. package/com/api/oauth.js +0 -200
  21. package/com/api/script.tpl.js +0 -32
  22. package/com/cmd/README.md +0 -11
  23. package/com/cmd/com.json +0 -5
  24. package/com/cmd/config.tpl.json +0 -48
  25. package/com/cmd/drive.js +0 -176
  26. package/com/cmd/index.js +0 -287
  27. package/com/cmd/job/config.json +0 -66
  28. package/com/cmd/job/index.js +0 -241
  29. package/com/cmd/job/test.js +0 -188
  30. package/com/cmd/msg.json +0 -48
  31. package/com/cmd/script.tpl.js +0 -12
  32. package/com/db/README.md +0 -3
  33. package/com/db/com.json +0 -5
  34. package/com/db/drive.js +0 -2206
  35. package/com/db/index.js +0 -241
  36. package/com/event/README.md +0 -4
  37. package/com/event/com.json +0 -5
  38. package/com/event/config.tpl.json +0 -20
  39. package/com/event/drive.js +0 -61
  40. package/com/event/index.js +0 -438
  41. package/com/event/script.tpl.js +0 -23
  42. package/com/mqtt/README.md +0 -47
  43. package/com/mqtt/com.json +0 -5
  44. package/com/mqtt/config.tpl.json +0 -42
  45. package/com/mqtt/drive.js +0 -696
  46. package/com/mqtt/index.js +0 -1017
  47. package/com/mqtt/index.test.js +0 -503
  48. package/com/mqtt/mm_mqtt.js +0 -446
  49. package/com/mqtt/script.tpl.js +0 -719
  50. package/com/nav/README.md +0 -2
  51. package/com/nav/com.json +0 -5
  52. package/com/nav/config.tpl.json +0 -84
  53. package/com/nav/drive.js +0 -702
  54. package/com/nav/index.js +0 -228
  55. package/com/nav/tpl/admin_pc/page_channel.vue +0 -305
  56. package/com/nav/tpl/admin_pc/page_config.vue +0 -280
  57. package/com/nav/tpl/admin_pc/page_config_form.vue +0 -194
  58. package/com/nav/tpl/admin_pc/page_default.vue +0 -247
  59. package/com/nav/tpl/admin_pc/page_form.vue +0 -180
  60. package/com/nav/tpl/admin_pc/page_lang.vue +0 -264
  61. package/com/nav/tpl/admin_pc/page_nav.vue +0 -321
  62. package/com/nav/tpl/admin_pc/page_table.vue +0 -296
  63. package/com/nav/tpl/admin_pc/page_type.vue +0 -321
  64. package/com/nav/tpl/admin_pc/page_view.vue +0 -124
  65. package/com/nav/tpl/dev_pc/page_channel.vue +0 -253
  66. package/com/nav/tpl/dev_pc/page_config.vue +0 -253
  67. package/com/nav/tpl/dev_pc/page_default.vue +0 -247
  68. package/com/nav/tpl/dev_pc/page_form.vue +0 -162
  69. package/com/nav/tpl/dev_pc/page_nav.vue +0 -253
  70. package/com/nav/tpl/dev_pc/page_table.vue +0 -247
  71. package/com/nav/tpl/dev_pc/page_type.vue +0 -313
  72. package/com/nav/tpl/home_pc/page_channel.vue +0 -234
  73. package/com/nav/tpl/home_pc/page_default.vue +0 -234
  74. package/com/nav/tpl/home_pc/page_form.vue +0 -137
  75. package/com/nav/tpl/home_pc/page_list.vue +0 -234
  76. package/com/nav/tpl/home_pc/page_nav.vue +0 -221
  77. package/com/nav/tpl/home_pc/page_type.vue +0 -234
  78. package/com/nav/tpl/home_pc/page_view.vue +0 -125
  79. package/com/nav/tpl/home_phone/page_channel.vue +0 -234
  80. package/com/nav/tpl/home_phone/page_default.vue +0 -234
  81. package/com/nav/tpl/home_phone/page_form.vue +0 -137
  82. package/com/nav/tpl/home_phone/page_list.vue +0 -234
  83. package/com/nav/tpl/home_phone/page_nav.vue +0 -237
  84. package/com/nav/tpl/home_phone/page_type.vue +0 -234
  85. package/com/nav/tpl/home_phone/page_view.vue +0 -125
  86. package/com/nav/viewmodel.js +0 -446
  87. package/com/param/README.md +0 -2
  88. package/com/param/com.json +0 -5
  89. package/com/param/config.tpl.json +0 -136
  90. package/com/param/drive.js +0 -502
  91. package/com/param/index.js +0 -158
  92. package/com/param/script.tpl.js +0 -12
  93. package/com/pendant/README.md +0 -3
  94. package/com/pendant/com.json +0 -5
  95. package/com/pendant/config.tpl.json +0 -32
  96. package/com/pendant/drive.js +0 -204
  97. package/com/pendant/index.js +0 -467
  98. package/com/pendant/pendant.html +0 -16
  99. package/com/pendant/script.tpl.js +0 -18
  100. package/com/socket/README.md +0 -47
  101. package/com/socket/com.json +0 -5
  102. package/com/socket/config.tpl.json +0 -12
  103. package/com/socket/drive.js +0 -679
  104. package/com/socket/index.js +0 -402
  105. package/com/socket/script.tpl.js +0 -41
  106. package/com/sql/README.md +0 -3
  107. package/com/sql/com.json +0 -5
  108. package/com/sql/config.tpl.json +0 -74
  109. package/com/sql/drive.js +0 -1283
  110. package/com/sql/index.js +0 -152
  111. package/com/sql/script.tpl.js +0 -47
  112. package/com/static/README.md +0 -2
  113. package/com/static/com.json +0 -5
  114. package/com/static/config.tpl.json +0 -24
  115. package/com/static/drive.js +0 -194
  116. package/com/static/index.js +0 -237
  117. package/com/static/script.tpl.js +0 -28
  118. package/com/task/README.md +0 -3
  119. package/com/task/com.json +0 -5
  120. package/com/task/config.tpl.json +0 -24
  121. package/com/task/drive.js +0 -428
  122. package/com/task/index.js +0 -159
  123. package/com/task/script.tpl.js +0 -40
  124. package/com/template/com.json +0 -5
  125. package/com/template/config.tpl.json +0 -16
  126. package/com/template/drive.js +0 -81
  127. package/com/template/index.js +0 -141
  128. package/com.js +0 -237
  129. package/common/README.md +0 -2
  130. package/common/middleware/web_after/index.js +0 -26
  131. package/common/middleware/web_after/middleware.json +0 -9
  132. package/common/middleware/web_base/index.js +0 -113
  133. package/common/middleware/web_base/middleware.json +0 -19
  134. package/common/middleware/web_before/index.js +0 -33
  135. package/common/middleware/web_before/middleware.json +0 -9
  136. package/common/middleware/web_cors/index.js +0 -87
  137. package/common/middleware/web_cors/middleware.json +0 -24
  138. package/common/middleware/web_error/index.js +0 -131
  139. package/common/middleware/web_error/middleware.json +0 -19
  140. package/common/middleware/web_ip/index.js +0 -15
  141. package/common/middleware/web_ip/middleware.json +0 -14
  142. package/common/middleware/web_logger/index.js +0 -156
  143. package/common/middleware/web_logger/middleware.json +0 -14
  144. package/common/middleware/web_main/index.js +0 -26
  145. package/common/middleware/web_main/middleware.json +0 -9
  146. package/common/middleware/web_static/index.js +0 -73
  147. package/common/middleware/web_static/middleware.json +0 -54
  148. package/common/middleware/web_waf/index.js +0 -385
  149. package/common/middleware/web_waf/middleware.json +0 -13
  150. package/core/app/config.tpl.json +0 -67
  151. package/core/app/index.js +0 -710
  152. package/core/app/script.tpl.js +0 -52
  153. package/core/channel/index.js +0 -899
  154. package/core/channel/matcher.js +0 -585
  155. package/core/com/config.tpl.json +0 -16
  156. package/core/com/index.js +0 -77
  157. package/core/com/script.tpl.js +0 -5
  158. package/core/component/component.js +0 -42
  159. package/core/component/config.tpl.json +0 -63
  160. package/core/component/index.js +0 -273
  161. package/core/component/script.tpl.js +0 -19
  162. package/core/controller/config.tpl.json +0 -14
  163. package/core/controller/index.js +0 -371
  164. package/core/controller/script.tpl.js +0 -27
  165. package/core/factory/config.tpl.json +0 -14
  166. package/core/factory/entity.js +0 -275
  167. package/core/factory/index.js +0 -241
  168. package/core/factory/script.tpl.js +0 -16
  169. package/core/game/bat/index.js +0 -137
  170. package/core/game/bat/world.js +0 -622
  171. package/core/game/config.tpl.json +0 -16
  172. package/core/game/entity_admin.js +0 -230
  173. package/core/game/index.js +0 -186
  174. package/core/handler/config.tpl.json +0 -22
  175. package/core/handler/index.js +0 -181
  176. package/core/handler/script.tpl.js +0 -23
  177. package/core/logic/config.tpl.json +0 -14
  178. package/core/logic/index.js +0 -59
  179. package/core/logic/script.tpl.js +0 -19
  180. package/core/middleware/config.tpl.json +0 -16
  181. package/core/middleware/index.js +0 -117
  182. package/core/middleware/script.tpl.js +0 -37
  183. package/core/mod/config.tpl.json +0 -22
  184. package/core/mod/index.js +0 -136
  185. package/core/mod/script.tpl.js +0 -34
  186. package/core/model/config.tpl.json +0 -219
  187. package/core/model/index.js +0 -272
  188. package/core/model/model.js +0 -27
  189. package/core/model/script.tpl.js +0 -20
  190. package/core/notifier/config.tpl.json +0 -14
  191. package/core/notifier/index.js +0 -77
  192. package/core/notifier/script.tpl.js +0 -20
  193. package/core/plugin/config.tpl.json +0 -36
  194. package/core/plugin/index.js +0 -297
  195. package/core/plugin/script.tpl.js +0 -51
  196. package/core/pusher/config.tpl.json +0 -14
  197. package/core/pusher/index.js +0 -158
  198. package/core/pusher/script.tpl.js +0 -20
  199. package/core/room/bat/index.js +0 -170
  200. package/core/room/bat/room.js +0 -524
  201. package/core/room/config.tpl.json +0 -20
  202. package/core/room/index.js +0 -249
  203. package/core/room/room.js +0 -61
  204. package/core/scene/config.tpl.json +0 -14
  205. package/core/scene/index.js +0 -467
  206. package/core/scene/loop.js +0 -1306
  207. package/core/scene/map.js +0 -28
  208. package/core/scene/script.tpl.js +0 -22
  209. package/core/sender/config.tpl.json +0 -14
  210. package/core/sender/index.js +0 -79
  211. package/core/sender/script.tpl.js +0 -20
  212. package/core/service/config.tpl.json +0 -14
  213. package/core/service/index.js +0 -100
  214. package/core/service/script.tpl.js +0 -25
  215. package/core/store/config.tpl.json +0 -26
  216. package/core/store/index.js +0 -1794
  217. package/core/store/script.tpl.js +0 -22
  218. package/core/store/sql.js +0 -1488
  219. package/core/system/config.tpl.json +0 -18
  220. package/core/system/index.js +0 -312
  221. package/core/system/script.tpl.js +0 -77
  222. package/core/view/config.tpl.json +0 -14
  223. package/core/view/index.js +0 -91
  224. package/core/view/script.tpl.js +0 -20
  225. package/core/zone/bat/index.js +0 -744
  226. package/core/zone/config.tpl.json +0 -54
  227. package/core/zone/index.js +0 -655
  228. package/core/zone/script.tpl.js +0 -10
  229. package/core/zone/zone_bat.js +0 -136
  230. package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +0 -24
  231. package/os.js +0 -53
  232. package/server.js +0 -595
  233. package/ulits/id_gen.js +0 -134
  234. 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
- }
@@ -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
- };
@@ -1,2 +0,0 @@
1
- ## 静态文件框架
2
- 实现了多静态文件目录结合使用,让每个应用或每个插件都可以有自己独立的静态文件目录,以便热拔插和提供给前端访问。
@@ -1,5 +0,0 @@
1
- {
2
- "name": "Static",
3
- "title": "静态文件管理器",
4
- "state": 1
5
- }
@@ -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
- }
@@ -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;
@@ -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
- }
@@ -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
- };
@@ -1,3 +0,0 @@
1
- ## 定时任务框架
2
- 实现了指定时间启动到指定时间结束,什么时候执行、每隔多久执行一次,最多执行多少次等,让写定时程序更加容易。
3
- 同时调用唯一的定时程序,减少了内存开销。
package/com/task/com.json DELETED
@@ -1,5 +0,0 @@
1
- {
2
- "name": "Task",
3
- "title": "定时任务管理器",
4
- "state": 1
5
- }