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
@@ -1,81 +0,0 @@
1
- const compressing = require('compressing');
2
- const Item = require('mm_machine').Drive;
3
-
4
- /**
5
- * 主题模板驱动类
6
- * @class
7
- */
8
- class Drive extends Item {
9
- static config = {
10
- name: '',
11
- title: '',
12
- description: '',
13
- version: '1.0.0',
14
- preview: '',
15
- preview_large: '',
16
- git: ''
17
- };
18
-
19
- /**
20
- * 主题模板驱动类
21
- * @param {object} config 主题模板配置
22
- * @param {object} parent 父项
23
- */
24
- constructor(config, parent) {
25
- super({ ...Drive.config, ...config }, parent);
26
- // this.default_file = "./template.json";
27
- // dir, "/static/template".fullname()
28
- }
29
- }
30
-
31
- /**
32
- * 压缩主题模板
33
- * @param {string} zip_dir 压缩目录
34
- * @returns {object} 压缩后的文件对象
35
- */
36
- Drive.prototype.zip = async function (zip_dir = '/static/file/zip/') {
37
- var file = ('./' + this.config.name + '.zip').fullname(zip_dir);
38
- file.addDir();
39
- await compressing.zip.compressDir(this.getDir(), file);
40
- if (file.hasFile()) {
41
- return file;
42
- }
43
- return null;
44
- };
45
-
46
- /**
47
- * 下载主题模板包
48
- */
49
- Drive.prototype.download = async function () {
50
-
51
- };
52
-
53
- /**
54
- * 更新主题模板
55
- */
56
- Drive.prototype.update = async function () {
57
-
58
- };
59
-
60
- /**
61
- * 获取模型
62
- * @param {string} type 模型类型
63
- * @returns {object} 返回获取到的模型
64
- */
65
- Drive.prototype.getModel = function (type) {
66
- let model = { ...this.config };
67
- let dir = this.getDir();
68
- let l = $.slash;
69
- let app_name = dir.between('app' + l, l);
70
- let plugin_name = dir.between('plugin' + l, l);
71
- let name = dir.basename();
72
- model.app = app_name;
73
- model.plugin = plugin_name;
74
- model.name = model.name || app_name + '_' + name;
75
- return model;
76
- };
77
-
78
- module.exports = {
79
- Drive
80
- };
81
-
@@ -1,141 +0,0 @@
1
- const compressing = require("compressing");
2
- const Manager = require("mm_machine").Manager;
3
- const Drive = require("./drive").Drive;
4
-
5
- /**
6
- * 主题模板管理类
7
- * @class
8
- */
9
- class Template 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: "template管理",
25
- /**
26
- * 描述
27
- * @type {string}
28
- */
29
- description: "这是template管理器",
30
- /**
31
- * 检索文件名
32
- * @type {string}
33
- */
34
- filename: "template.json",
35
- /**
36
- * 模板目录
37
- * @type {string}
38
- */
39
- tpl_dir: __dirname,
40
- /**
41
- * 基础目录
42
- * @type {string}
43
- */
44
- base_dir: "../common/template".fullname(__dirname),
45
- /**
46
- * 自定义目录,加载项目自定义资源
47
- * @type {string}
48
- */
49
- dir: "./static/template".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({ ...Template.config, ...config }, parent);
79
- }
80
- }
81
-
82
- Template.prototype.Drive = Drive;
83
-
84
- /**
85
- * 解压模板
86
- * @param {string} file 模板压缩文件
87
- * @returns {object} 解压后的文件对象
88
- */
89
- Template.prototype.unzip = async function (file) {
90
- var done = await compressing.zip.uncompress(
91
- file,
92
- "/static/template".fullname(),
93
- );
94
- return done;
95
- };
96
-
97
- /**
98
- * 获取模板
99
- * @param {string} key 模板键名
100
- * @returns {object} 模板对象
101
- */
102
- Template.prototype.get = function (key) {
103
- return this.mods[key];
104
- };
105
-
106
- /**
107
- * 主题模板模板池
108
- */
109
- if (!$.pool.template) {
110
- $.pool.template = {};
111
- }
112
-
113
- /**
114
- * 主题模板管理器,用于创建缓存
115
- * @param {string} scope 作用域
116
- * @param {string} title 标题
117
- * @returns {object} 返回一个缓存类
118
- */
119
- function templateAdmin(scope, title) {
120
- var sc = scope || $.val.scope + "";
121
- var obj = $.pool.template[sc];
122
- if (!obj) {
123
- $.pool.template[sc] = new Template({
124
- name: sc,
125
- title: title,
126
- });
127
- obj = $.pool.template[sc];
128
- }
129
- return obj;
130
- }
131
-
132
- /**
133
- * @module 导出模板管理器
134
- */
135
- if ($.admin) {
136
- $.admin.template = templateAdmin;
137
- }
138
-
139
- module.exports = {
140
- Template,
141
- };
package/com.js DELETED
@@ -1,237 +0,0 @@
1
- const { Word } = require('./ulits/word.js');
2
-
3
- if (!$.admin) {
4
- $.admin = {};
5
- }
6
- /**
7
- * 公共模块管理类
8
- */
9
- class Com {
10
- static config = {
11
- name: 'com',
12
- title: '公共模块'
13
- };
14
-
15
- /**
16
- * 构造函数
17
- * @param {object} config 配置参数
18
- */
19
- constructor(config) {
20
- this.config = {
21
- name: 'com',
22
- ...Com.config,
23
- ...config
24
- };
25
- /**
26
- * 公共模块配置列表
27
- */
28
- this.list = [];
29
- }
30
- }
31
-
32
- /**
33
- * 排序
34
- * @private
35
- */
36
- Com.prototype._sort = function () {
37
- this.list.sort((a, b) => {
38
- return a.sort - b.sort;
39
- });
40
- };
41
-
42
- /**
43
- * 将文件名改为类名
44
- * @param {string} name 文件名
45
- * @returns {string} 类名
46
- */
47
- Com.prototype.toClassName = function (name) {
48
- var word = new Word();
49
- return word.toPascalCase(name);
50
- };
51
-
52
- /**
53
- * 加载配置
54
- * @param {string} file 配置文件
55
- * @returns {object} 返回配置信息
56
- */
57
- Com.prototype._loadConfig = function (file) {
58
- var cg;
59
- if (file.hasFile()) {
60
- cg = file.loadJson();
61
- if (!cg) {
62
- var name = this.toClassName(file.dirname().basename());
63
- var content = `{
64
- // 名称
65
- "name": "${name}",
66
- // 标题
67
- "title": "公共模块",
68
- // 描述
69
- "description": "定义公共模块",
70
- // 状态 0:禁用 1:启用
71
- "state": 1,
72
- // 排序,越小越靠前
73
- "sort": 100,
74
- // 依赖的module
75
- "dependencies": []
76
- }`;
77
- file.saveText(content);
78
- cg = file.loadJson();
79
- }
80
- }
81
- return cg;
82
- };
83
-
84
- /**
85
- * 加载脚本
86
- * @param {object} cg 配置信息
87
- */
88
- Com.prototype._loadScript = function (cg) {
89
- var file = cg._file || (cg.main || './index.js').fullname(cg.dir);
90
- if (!file.hasFile()) {
91
- var name = this.toClassName(cg.name);
92
- var title = cg.title;
93
- var script = `/**
94
- * ${title}
95
- */
96
- class ${name} {
97
- /**
98
- * 构造函数
99
- * @param {object} config 配置参数
100
- */
101
- constructor(config) {
102
- this.config = {...config};
103
- }
104
- }
105
-
106
- exports.${name} = ${name};`;
107
- file.saveText(script);
108
- }
109
- try {
110
- return $.require(file, (mod) => {
111
- this[cg.name] = mod;
112
- });
113
- } catch (error) {
114
- $.log.error('加载脚本失败!', error);
115
- return null;
116
- }
117
- };
118
-
119
- /**
120
- * 批量加载配置
121
- * @private
122
- * @param {string} dir 目录路径
123
- * @param {string} dirname 目录名
124
- */
125
- Com.prototype._loads = function (dir, dirname) {
126
- if (!dir || !dir.hasDir()) {
127
- return;
128
- }
129
- var files = $.file.getAll(dir, this.config.name + '.json', dirname);
130
- for (let i = 0; i < files.length; i++) {
131
- var file = files[i];
132
- var cg = this._loadConfig(file);
133
- if (cg) {
134
- cg.dir = file.dirname();
135
- cg._file = (cg.main || './index.js').fullname(cg.dir);
136
- cg._loaded = false;
137
- var idx = this._findIndex(cg.name);
138
- if (idx >= 0) {
139
- var loaded = this.list[idx]._loaded;
140
- Object.assign(this.list[idx], cg);
141
- this.list[idx]._loaded = loaded;
142
- } else {
143
- this.list.push(cg);
144
- this._defineLazy(cg);
145
- }
146
- }
147
- }
148
- this._sort();
149
- // 立即加载脚本(保证副作用执行,如 $.admin.xxx 注册)
150
- for (let i = 0; i < this.list.length; i++) {
151
- var cg = this.list[i];
152
- if (cg.state && !cg._loaded) {
153
- this._loadScript(cg);
154
- cg._loaded = true;
155
- }
156
- }
157
- };
158
-
159
- /**
160
- * 查找配置索引
161
- * @param {string} name 模块名称
162
- * @returns {number} 索引位置, 未找到返回 -1
163
- */
164
- Com.prototype._findIndex = function (name) {
165
- for (var i = 0; i < this.list.length; i++) {
166
- if (this.list[i].name === name) {
167
- return i;
168
- }
169
- }
170
- return -1;
171
- };
172
-
173
- /**
174
- * 查找配置
175
- * @param {string} name 模块名称
176
- * @returns {object|null} 配置信息
177
- */
178
- Com.prototype._findConfig = function (name) {
179
- var idx = this._findIndex(name);
180
- return idx >= 0 ? this.list[idx] : null;
181
- };
182
-
183
- /**
184
- * 定义懒加载属性
185
- * @param {object} cg 配置信息
186
- */
187
- Com.prototype._defineLazy = function (cg) {
188
- var self = this;
189
- var name = cg.name;
190
- var key = '_' + name;
191
- Object.defineProperty(this, name, {
192
- get: function () {
193
- if (self[key] === undefined) {
194
- var mod = self._loadScript(cg);
195
- if (mod !== undefined && mod !== null) {
196
- self[key] = mod;
197
- }
198
- }
199
- return self[key];
200
- },
201
- set: function (val) {
202
- self[key] = val;
203
- },
204
- configurable: true,
205
- enumerable: true
206
- });
207
- };
208
-
209
- /**
210
- * 预加载核心模块
211
- * @param {Array<string>} names 模块名称列表
212
- */
213
- Com.prototype.loadCore = function (names) {
214
- if (!names || !names.length) {
215
- return;
216
- }
217
- for (var i = 0; i < names.length; i++) {
218
- var name = names[i];
219
- var cg = this._findConfig(name);
220
- if (cg && cg.state) {
221
- var val = this[name];
222
- if (val === undefined || val === null) {
223
- $.log.error('核心模块加载失败:', name);
224
- }
225
- }
226
- }
227
- };
228
-
229
- /**
230
- * 加载公共模块
231
- */
232
- Com.prototype.loads = function () {
233
- this._loads('./com'.fullname(__dirname));
234
- this._loads('/com'.fullname());
235
- };
236
-
237
- exports.Com = Com;
package/common/README.md DELETED
@@ -1,2 +0,0 @@
1
- common 为公共模块, 会被每一个APP引用
2
- 提供一些内置的处理器、模型、服务。
@@ -1,26 +0,0 @@
1
- /**
2
- * 中间件
3
- */
4
- module.exports = {
5
- async _init(adapter) {
6
- var event = $.admin.event('api');
7
- await event.do('load');
8
- await event.runAll('load');
9
- await event.runAll('init');
10
- },
11
- /**
12
- * 主要逻辑
13
- * @param {object} ctx Koa上下文
14
- * @param {Function} next 下一个中间件
15
- */
16
- async main(ctx, next) {
17
- await next();
18
- if (ctx.path !== '/favicon.ico') {
19
- var event = $.admin.event('api');
20
- var ret = await event.after(ctx.path, ctx, ctx.db);
21
- if (ret) {
22
- ctx.body = ret;
23
- }
24
- }
25
- }
26
- };
@@ -1,9 +0,0 @@
1
- {
2
- "name": "web_after",
3
- "title": "请求后中间件",
4
- "description": "用于处理请求后逻辑",
5
- "main": "index.js",
6
- "type": "web",
7
- "state": 1,
8
- "sort": 60
9
- }
@@ -1,113 +0,0 @@
1
- const compress = require('koa-compress');
2
- const send = require('koa-send');
3
- const { koaBody } = require('koa-body');
4
- const xmlParser = require('mm_xml');
5
- const { session } = require('mm_session');
6
-
7
- /**
8
- * web基础
9
- * @param {object} server 服务
10
- */
11
- module.exports = {
12
- /**
13
- * 初始化
14
- * @param {object} adapter 适配器集合
15
- */
16
- _init(adapter) {
17
- // 参数校验
18
- if (typeof adapter !== 'object') {
19
- throw new TypeError('参数类型错误');
20
- }
21
-
22
- // 获取web服务
23
- var web = adapter.web;
24
-
25
- // 获取配置
26
- let cg = { ...this.config, ...adapter.web.config };
27
- this._setupFileSend(web);
28
- this._setupSession(web, cg);
29
- this._setupCompress(web, cg);
30
- this._setupParsers(web, cg);
31
- },
32
-
33
- /**
34
- * 设置文件发送
35
- * @private
36
- * @param {object} web web服务
37
- */
38
- _setupFileSend(web) {
39
- web.use(async (ctx, next) => {
40
- // 设置文件发送方法,错误由web_error中间件统一处理
41
- ctx.send = async function (src) {
42
- await send(ctx, src);
43
- };
44
-
45
- await next();
46
- });
47
- },
48
-
49
- /**
50
- * 设置会话
51
- * @private
52
- * @param {object} web web服务
53
- * @param {object} cg 配置
54
- */
55
- _setupSession(web, cg) {
56
- // 设置session 保存时长2小时
57
- web.use(session({
58
- max_age: $.login_period || cg.max_age || 7200
59
- }));
60
- },
61
-
62
- /**
63
- * 设置压缩
64
- * @private
65
- * @param {object} web web服务
66
- * @param {object} cg 配置
67
- */
68
- _setupCompress(web, cg) {
69
- if (cg.compress) {
70
- web.use(compress({
71
- filter: (content_type) => /text|json|javascript|css|xml/.test(content_type),
72
- thresh: cg.threshold || 1024,
73
- gzip: {
74
- flush: require('zlib').constants.Z_SYNC_FLUSH
75
- },
76
- brotli: {
77
- flush: require('zlib').constants.BROTLI_OPERATION_FLUSH
78
- }
79
- }));
80
- }
81
- },
82
-
83
- /**
84
- * 设置解析器
85
- * @private
86
- * @param {object} web web服务
87
- * @param {object} cg 配置
88
- */
89
- _setupParsers(web, cg) {
90
- // 解析 text/xml
91
- web.use(xmlParser());
92
- // 解析请求体
93
- web.use(koaBody({
94
- jsonLimit: cg.json_limit || '20mb',
95
- multipart: true, // 必须开启才能解析 form-data
96
- urlencoded: true, // 可选:解析 URL 编码的表单
97
- text: true,
98
- json: true, // 可选:解析 JSON
99
- patchNode: true,
100
- patchKoa: true,
101
- formidable: {
102
- maxFileSize: cg.max_file_size || 2000 * 1024 * 1024
103
- }
104
- }));
105
-
106
- web.use(async (ctx, next) => {
107
- if (!ctx.request.body) {
108
- ctx.request.body = {};
109
- }
110
- await next();
111
- });
112
- }
113
- };
@@ -1,19 +0,0 @@
1
- {
2
- "name": "web_base",
3
- "title": "web基本功能",
4
- "description": "用于网站常规功能",
5
- "main": "index.js",
6
- "type": "web",
7
- "state": 1,
8
- "sort": 40,
9
- // 发送的JSON最大大小
10
- "json_limit": "20mb",
11
- // 缓存最大时长
12
- "max_age": 7200,
13
- // 最大文件大小
14
- "max_file_fize": 2097152000,
15
- // 是否brotli压缩
16
- "brotli": true,
17
- // 是否gzip压缩
18
- "gzip": true
19
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * 中间件
3
- */
4
- module.exports = {
5
- /**
6
- * 主要逻辑
7
- * @param {object} ctx Koa上下文
8
- * @param {Function} next 下一个中间件
9
- */
10
- async main(ctx, next) {
11
- if (!ctx.db) {
12
- ctx.db = {
13
- ret: null
14
- };
15
- }
16
- if (ctx.path !== '/favicon.ico') {
17
- var event = $.admin.event('api');
18
- var ret = await event.before(ctx.path, ctx, ctx.db);
19
- if (ret) {
20
- ctx.body = ret;
21
- return;
22
- }
23
- else {
24
- ret = await event.check(ctx.path, ctx, ctx.db);
25
- if (ret) {
26
- ctx.body = ret;
27
- return;
28
- }
29
- }
30
- }
31
- await next();
32
- }
33
- };
@@ -1,9 +0,0 @@
1
- {
2
- "name": "web_before",
3
- "title": "请求前中间件",
4
- "description": "用于处理请求前逻辑",
5
- "main": "index.js",
6
- "type": "web",
7
- "state": 1,
8
- "sort": 70
9
- }