mm_os 3.3.1 → 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.
Files changed (380) hide show
  1. package/LICENSE +21 -201
  2. package/README.md +491 -99
  3. package/README_EN.md +498 -0
  4. package/adapter/adapter.js +431 -0
  5. package/adapter/custom_persistence.js +660 -0
  6. package/adapter/mqtt.js +273 -0
  7. package/adapter/socket.js +113 -0
  8. package/adapter/web.js +67 -0
  9. package/adapter/websocket.js +146 -0
  10. package/com/api/com.json +5 -0
  11. package/{core/com → com}/api/config.tpl.json +8 -8
  12. package/com/api/drive.js +708 -0
  13. package/com/api/index.js +198 -0
  14. package/com/api/oauth.js +200 -0
  15. package/com/api/script.tpl.js +32 -0
  16. package/com/cmd/README.md +11 -0
  17. package/com/cmd/com.json +5 -0
  18. package/com/cmd/config.tpl.json +122 -0
  19. package/com/cmd/drive.js +1548 -0
  20. package/com/cmd/index.js +1066 -0
  21. package/com/cmd/msg.json +48 -0
  22. package/com/cmd/nlp.js +525 -0
  23. package/com/cmd/script.tpl.js +32 -0
  24. package/com/db/com.json +5 -0
  25. package/com/db/drive.js +1999 -0
  26. package/com/db/index.js +242 -0
  27. package/{core/com → com}/event/README.md +4 -4
  28. package/com/event/com.json +5 -0
  29. package/{core/com → com}/event/config.tpl.json +18 -18
  30. package/com/event/drive.js +59 -0
  31. package/com/event/index.js +409 -0
  32. package/com/event/script.tpl.js +23 -0
  33. package/com/mqtt/com.json +5 -0
  34. package/{core/com → com}/mqtt/config.tpl.json +3 -5
  35. package/com/mqtt/drive.js +676 -0
  36. package/com/mqtt/index.js +822 -0
  37. package/com/mqtt/mm_mqtt.js +425 -0
  38. package/com/mqtt/script.tpl.js +723 -0
  39. package/com/nav/com.json +5 -0
  40. package/com/nav/config.tpl.json +84 -0
  41. package/com/nav/drive.js +702 -0
  42. package/com/nav/index.js +231 -0
  43. package/{core/com → com}/nav/tpl/admin_pc/page_config.vue +280 -280
  44. package/{core/com → com}/nav/tpl/admin_pc/page_config_form.vue +194 -194
  45. package/com/nav/tpl/admin_pc/page_form.vue +180 -0
  46. package/com/nav/tpl/admin_pc/page_view.vue +124 -0
  47. package/com/nav/tpl/dev_pc/page_default.vue +247 -0
  48. package/com/nav/tpl/dev_pc/page_type.vue +313 -0
  49. package/com/nav/tpl/home_pc/page_default.vue +234 -0
  50. package/com/nav/tpl/home_pc/page_form.vue +137 -0
  51. package/com/nav/tpl/home_pc/page_list.vue +234 -0
  52. package/com/nav/tpl/home_pc/page_nav.vue +221 -0
  53. package/com/nav/tpl/home_pc/page_type.vue +234 -0
  54. package/com/nav/tpl/home_pc/page_view.vue +125 -0
  55. package/com/nav/tpl/home_phone/page_channel.vue +234 -0
  56. package/com/nav/tpl/home_phone/page_default.vue +234 -0
  57. package/com/nav/tpl/home_phone/page_form.vue +137 -0
  58. package/com/nav/tpl/home_phone/page_nav.vue +237 -0
  59. package/com/nav/tpl/home_phone/page_type.vue +234 -0
  60. package/com/nav/tpl/home_phone/page_view.vue +125 -0
  61. package/com/nav/viewmodel.js +446 -0
  62. package/com/param/com.json +5 -0
  63. package/{core/com → com}/param/config.tpl.json +7 -1
  64. package/com/param/drive.js +502 -0
  65. package/com/param/index.js +155 -0
  66. package/com/param/script.tpl.js +12 -0
  67. package/com/pendant/com.json +5 -0
  68. package/{core/com/component → com/pendant}/config.tpl.json +15 -13
  69. package/com/pendant/drive.js +204 -0
  70. package/com/pendant/index.js +441 -0
  71. package/com/pendant/pendant.html +16 -0
  72. package/com/pendant/script.tpl.js +18 -0
  73. package/com/socket/com.json +5 -0
  74. package/com/socket/config.tpl.json +12 -0
  75. package/com/socket/drive.js +651 -0
  76. package/com/socket/index.js +351 -0
  77. package/com/socket/script.tpl.js +41 -0
  78. package/com/sql/com.json +5 -0
  79. package/{core/com → com}/sql/config.tpl.json +13 -9
  80. package/com/sql/drive.js +1259 -0
  81. package/com/sql/index.js +150 -0
  82. package/com/sql/script.tpl.js +47 -0
  83. package/com/static/com.json +5 -0
  84. package/{core/com → com}/static/config.tpl.json +10 -6
  85. package/com/static/drive.js +194 -0
  86. package/com/static/index.js +226 -0
  87. package/com/static/script.tpl.js +28 -0
  88. package/com/task/com.json +5 -0
  89. package/{core/com → com}/task/config.tpl.json +4 -6
  90. package/com/task/drive.js +405 -0
  91. package/com/task/index.js +148 -0
  92. package/com/task/script.tpl.js +37 -0
  93. package/com/template/com.json +5 -0
  94. package/com/template/config.tpl.json +16 -0
  95. package/com/template/drive.js +80 -0
  96. package/com/template/index.js +141 -0
  97. package/com.js +156 -0
  98. package/common/README.md +2 -0
  99. package/common/handler/msg/handler.json +22 -0
  100. package/common/handler/msg/index.js +23 -0
  101. package/common/handler/player/handler.json +22 -0
  102. package/common/handler/player/index.js +287 -0
  103. package/common/handler/user/handler.json +22 -0
  104. package/common/handler/user/index.js +23 -0
  105. package/common/middleware/web_after/index.js +29 -0
  106. package/common/middleware/web_after/middleware.json +9 -0
  107. package/common/middleware/web_base/index.js +113 -0
  108. package/common/middleware/web_base/middleware.json +19 -0
  109. package/common/middleware/web_before/index.js +33 -0
  110. package/common/middleware/web_before/middleware.json +9 -0
  111. package/common/middleware/web_cors/index.js +87 -0
  112. package/common/middleware/web_cors/middleware.json +24 -0
  113. package/common/middleware/web_error/index.js +119 -0
  114. package/common/middleware/web_error/middleware.json +18 -0
  115. package/common/middleware/web_ip/index.js +15 -0
  116. package/common/middleware/web_ip/middleware.json +14 -0
  117. package/common/middleware/web_logger/index.js +156 -0
  118. package/common/middleware/web_logger/middleware.json +14 -0
  119. package/common/middleware/web_main/index.js +24 -0
  120. package/common/middleware/web_main/middleware.json +9 -0
  121. package/common/middleware/web_static/index.js +73 -0
  122. package/common/middleware/web_static/middleware.json +54 -0
  123. package/common/middleware/web_waf/index.js +385 -0
  124. package/common/middleware/web_waf/middleware.json +13 -0
  125. package/common/model/msg/index.js +88 -0
  126. package/common/model/msg/model.json +401 -0
  127. package/common/model/player/index.js +63 -0
  128. package/common/model/player/model.json +185 -0
  129. package/common/model/user/index.js +11 -0
  130. package/common/model/user/model.json +219 -0
  131. package/core/app/config.tpl.json +67 -0
  132. package/core/app/index.js +632 -0
  133. package/core/app/script.tpl.js +52 -0
  134. package/core/channel/index.js +899 -0
  135. package/core/channel/matcher.js +585 -0
  136. package/core/com/config.tpl.json +16 -0
  137. package/core/com/index.js +74 -0
  138. package/core/com/script.tpl.js +5 -0
  139. package/core/component/component.js +42 -0
  140. package/core/component/config.tpl.json +63 -0
  141. package/core/component/index.js +273 -0
  142. package/core/component/script.tpl.js +19 -0
  143. package/core/controller/config.tpl.json +14 -0
  144. package/core/controller/index.js +373 -0
  145. package/core/controller/script.tpl.js +27 -0
  146. package/core/factory/config.tpl.json +14 -0
  147. package/core/factory/entity.js +275 -0
  148. package/core/factory/index.js +241 -0
  149. package/core/factory/script.tpl.js +16 -0
  150. package/core/game/bat/index.js +137 -0
  151. package/core/game/bat/world.js +622 -0
  152. package/core/game/config.tpl.json +16 -0
  153. package/core/game/entity_admin.js +230 -0
  154. package/core/game/index.js +186 -0
  155. package/core/handler/config.tpl.json +22 -0
  156. package/core/handler/index.js +181 -0
  157. package/core/handler/script.tpl.js +23 -0
  158. package/core/logic/config.tpl.json +14 -0
  159. package/core/logic/index.js +59 -0
  160. package/core/logic/script.tpl.js +19 -0
  161. package/core/middleware/config.tpl.json +16 -0
  162. package/core/middleware/index.js +125 -0
  163. package/core/middleware/script.tpl.js +37 -0
  164. package/core/mod/config.tpl.json +22 -0
  165. package/core/mod/index.js +130 -0
  166. package/core/mod/script.tpl.js +34 -0
  167. package/core/model/config.tpl.json +219 -0
  168. package/core/model/index.js +272 -0
  169. package/core/model/model.js +27 -0
  170. package/core/model/script.tpl.js +20 -0
  171. package/core/notifier/config.tpl.json +14 -0
  172. package/core/notifier/index.js +77 -0
  173. package/core/notifier/script.tpl.js +20 -0
  174. package/core/plugin/config.tpl.json +24 -0
  175. package/core/plugin/index.js +232 -0
  176. package/core/plugin/script.tpl.js +51 -0
  177. package/core/pusher/config.tpl.json +14 -0
  178. package/core/pusher/index.js +161 -0
  179. package/core/pusher/script.tpl.js +20 -0
  180. package/core/room/bat/index.js +170 -0
  181. package/core/room/bat/room.js +524 -0
  182. package/core/room/config.tpl.json +20 -0
  183. package/core/room/index.js +249 -0
  184. package/core/room/room.js +61 -0
  185. package/core/scene/config.tpl.json +14 -0
  186. package/core/scene/index.js +466 -0
  187. package/core/scene/loop.js +1255 -0
  188. package/core/scene/map.js +28 -0
  189. package/core/scene/script.tpl.js +22 -0
  190. package/core/sender/config.tpl.json +14 -0
  191. package/core/sender/index.js +79 -0
  192. package/core/sender/script.tpl.js +20 -0
  193. package/core/service/config.tpl.json +14 -0
  194. package/core/service/index.js +100 -0
  195. package/core/service/script.tpl.js +25 -0
  196. package/core/store/config.tpl.json +26 -0
  197. package/core/store/index.js +1755 -0
  198. package/core/store/script.tpl.js +22 -0
  199. package/core/store/sql.js +1464 -0
  200. package/core/system/config.tpl.json +18 -0
  201. package/core/system/index.js +312 -0
  202. package/core/system/script.tpl.js +77 -0
  203. package/core/view/config.tpl.json +14 -0
  204. package/core/view/index.js +91 -0
  205. package/core/view/script.tpl.js +20 -0
  206. package/core/zone/bat/index.js +725 -0
  207. package/core/zone/config.tpl.json +54 -0
  208. package/core/zone/index.js +614 -0
  209. package/core/zone/script.tpl.js +10 -0
  210. package/core/zone/zone_bat.js +136 -0
  211. package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +24 -0
  212. package/index.js +17 -333
  213. package/os.js +57 -0
  214. package/package.json +58 -58
  215. package/server.js +598 -0
  216. package/README.en.md +0 -36
  217. package/conf.json +0 -3
  218. package/core/base/mqtt/index.js +0 -1110
  219. package/core/base/mqtt/lib.js +0 -40
  220. package/core/base/web/index.js +0 -245
  221. package/core/com/api/com.json +0 -4
  222. package/core/com/api/drive.js +0 -668
  223. package/core/com/api/index.js +0 -108
  224. package/core/com/api/oauth.js +0 -158
  225. package/core/com/api/script.js +0 -32
  226. package/core/com/app/README.md +0 -3
  227. package/core/com/app/com.json +0 -4
  228. package/core/com/app/config.tpl.json +0 -16
  229. package/core/com/app/drive.js +0 -309
  230. package/core/com/app/index.js +0 -211
  231. package/core/com/app/script.js +0 -155
  232. package/core/com/cmd/com.json +0 -4
  233. package/core/com/cmd/config.tpl.json +0 -66
  234. package/core/com/cmd/drive.js +0 -513
  235. package/core/com/cmd/index.js +0 -354
  236. package/core/com/cmd/old/5w2h.js +0 -54
  237. package/core/com/cmd/old/drive.js +0 -423
  238. package/core/com/cmd/script.js +0 -11
  239. package/core/com/component/README.md +0 -3
  240. package/core/com/component/com.json +0 -4
  241. package/core/com/component/component.html +0 -16
  242. package/core/com/component/drive.js +0 -197
  243. package/core/com/component/index.js +0 -312
  244. package/core/com/component/script.js +0 -18
  245. package/core/com/db/com.json +0 -4
  246. package/core/com/db/drive.js +0 -1160
  247. package/core/com/db/index.js +0 -176
  248. package/core/com/event/com.json +0 -4
  249. package/core/com/event/drive.js +0 -133
  250. package/core/com/event/index.js +0 -345
  251. package/core/com/event/script.js +0 -26
  252. package/core/com/eventer/com.js +0 -477
  253. package/core/com/eventer/com.json +0 -4
  254. package/core/com/middleware/com.js +0 -154
  255. package/core/com/middleware/com.json +0 -4
  256. package/core/com/middleware/config.tpl.json +0 -8
  257. package/core/com/middleware/script.js +0 -9
  258. package/core/com/mqtt/com.json +0 -4
  259. package/core/com/mqtt/drive.js +0 -600
  260. package/core/com/mqtt/index.js +0 -572
  261. package/core/com/mqtt/mm_mqtt.js +0 -330
  262. package/core/com/mqtt/script.js +0 -604
  263. package/core/com/msg/com.js +0 -296
  264. package/core/com/msg/com.json +0 -4
  265. package/core/com/nav/com.json +0 -4
  266. package/core/com/nav/config.tpl.json +0 -75
  267. package/core/com/nav/drive.js +0 -549
  268. package/core/com/nav/index.js +0 -182
  269. package/core/com/nav/tpl/admin_pc/page_form.vue +0 -180
  270. package/core/com/nav/tpl/admin_pc/page_view.vue +0 -124
  271. package/core/com/nav/tpl/dev_pc/page_default.vue +0 -247
  272. package/core/com/nav/tpl/dev_pc/page_type.vue +0 -313
  273. package/core/com/nav/tpl/home_pc/page_default.vue +0 -234
  274. package/core/com/nav/tpl/home_pc/page_form.vue +0 -137
  275. package/core/com/nav/tpl/home_pc/page_list.vue +0 -234
  276. package/core/com/nav/tpl/home_pc/page_nav.vue +0 -221
  277. package/core/com/nav/tpl/home_pc/page_type.vue +0 -234
  278. package/core/com/nav/tpl/home_pc/page_view.vue +0 -125
  279. package/core/com/nav/tpl/home_phone/page_channel.vue +0 -234
  280. package/core/com/nav/tpl/home_phone/page_default.vue +0 -234
  281. package/core/com/nav/tpl/home_phone/page_form.vue +0 -137
  282. package/core/com/nav/tpl/home_phone/page_nav.vue +0 -237
  283. package/core/com/nav/tpl/home_phone/page_type.vue +0 -234
  284. package/core/com/nav/tpl/home_phone/page_view.vue +0 -125
  285. package/core/com/nav/viewmodel.js +0 -296
  286. package/core/com/param/drive.js +0 -366
  287. package/core/com/param/index.js +0 -80
  288. package/core/com/param/script.js +0 -12
  289. package/core/com/param/test.js +0 -98
  290. package/core/com/plugin/README.md +0 -3
  291. package/core/com/plugin/com.json +0 -4
  292. package/core/com/plugin/config.tpl.json +0 -26
  293. package/core/com/plugin/drive.js +0 -536
  294. package/core/com/plugin/index.js +0 -259
  295. package/core/com/plugin/script.js +0 -213
  296. package/core/com/rpc/com.json +0 -4
  297. package/core/com/rpc/drive.js +0 -160
  298. package/core/com/rpc/index.js +0 -87
  299. package/core/com/rpc/rpc.js +0 -118
  300. package/core/com/socket/com.json +0 -4
  301. package/core/com/socket/config.tpl.json +0 -14
  302. package/core/com/socket/drive.js +0 -403
  303. package/core/com/socket/index.js +0 -62
  304. package/core/com/socket/script.js +0 -42
  305. package/core/com/sql/drive.js +0 -1087
  306. package/core/com/sql/index.js +0 -83
  307. package/core/com/sql/script.js +0 -48
  308. package/core/com/static/com.json +0 -4
  309. package/core/com/static/drive.js +0 -220
  310. package/core/com/static/index.js +0 -149
  311. package/core/com/static/script.js +0 -28
  312. package/core/com/task/com.json +0 -4
  313. package/core/com/task/drive.js +0 -403
  314. package/core/com/task/index.js +0 -110
  315. package/core/com/task/script.js +0 -37
  316. package/core/com/timer/com.js +0 -217
  317. package/core/com/timer/com.json +0 -4
  318. package/core/com/tpl/com.js +0 -19
  319. package/core/com/tpl/com.json +0 -4
  320. package/lib/actions.js +0 -50
  321. package/lib/base.js +0 -361
  322. package/lib/com.js +0 -29
  323. package/lib/ref.js +0 -121
  324. package/middleware/cors/index.js +0 -119
  325. package/middleware/cors/middleware.json +0 -20
  326. package/middleware/csrf/index.js +0 -202
  327. package/middleware/csrf/middleware.json +0 -24
  328. package/middleware/ip_firewall/index.js +0 -476
  329. package/middleware/ip_firewall/middleware.json +0 -109
  330. package/middleware/mqtt_base/index.js +0 -10
  331. package/middleware/mqtt_base/middleware.json +0 -11
  332. package/middleware/security_audit/index.js +0 -543
  333. package/middleware/security_audit/middleware.json +0 -48
  334. package/middleware/waf/index.js +0 -343
  335. package/middleware/waf/middleware.json +0 -10
  336. package/middleware/waf_ddos/index.js +0 -520
  337. package/middleware/waf_ddos/middleware.json +0 -38
  338. package/middleware/waf_xss/index.js +0 -269
  339. package/middleware/waf_xss/middleware.json +0 -18
  340. package/middleware/web_after/index.js +0 -33
  341. package/middleware/web_after/middleware.json +0 -10
  342. package/middleware/web_base/index.js +0 -90
  343. package/middleware/web_base/middleware.json +0 -10
  344. package/middleware/web_before/index.js +0 -27
  345. package/middleware/web_before/middleware.json +0 -10
  346. package/middleware/web_check/index.js +0 -28
  347. package/middleware/web_check/middleware.json +0 -10
  348. package/middleware/web_main/index.js +0 -28
  349. package/middleware/web_main/middleware.json +0 -10
  350. package/middleware/web_proxy/index.js +0 -37
  351. package/middleware/web_proxy/middleware.json +0 -10
  352. package/middleware/web_render/index.js +0 -87
  353. package/middleware/web_render/middleware.json +0 -10
  354. package/middleware/web_socket/index.js +0 -34
  355. package/middleware/web_socket/middleware.json +0 -10
  356. package/middleware/web_static/index.js +0 -115
  357. package/middleware/web_static/middleware.json +0 -10
  358. /package/{core/com → com}/api/README.md +0 -0
  359. /package/{core/com → com}/db/README.md +0 -0
  360. /package/{core/com → com}/mqtt/README.md +0 -0
  361. /package/{core/com → com}/nav/README.md +0 -0
  362. /package/{core/com → com}/nav/tpl/admin_pc/page_channel.vue +0 -0
  363. /package/{core/com → com}/nav/tpl/admin_pc/page_default.vue +0 -0
  364. /package/{core/com → com}/nav/tpl/admin_pc/page_lang.vue +0 -0
  365. /package/{core/com → com}/nav/tpl/admin_pc/page_nav.vue +0 -0
  366. /package/{core/com → com}/nav/tpl/admin_pc/page_table.vue +0 -0
  367. /package/{core/com → com}/nav/tpl/admin_pc/page_type.vue +0 -0
  368. /package/{core/com → com}/nav/tpl/dev_pc/page_channel.vue +0 -0
  369. /package/{core/com → com}/nav/tpl/dev_pc/page_config.vue +0 -0
  370. /package/{core/com → com}/nav/tpl/dev_pc/page_form.vue +0 -0
  371. /package/{core/com → com}/nav/tpl/dev_pc/page_nav.vue +0 -0
  372. /package/{core/com → com}/nav/tpl/dev_pc/page_table.vue +0 -0
  373. /package/{core/com → com}/nav/tpl/home_pc/page_channel.vue +0 -0
  374. /package/{core/com → com}/nav/tpl/home_phone/page_list.vue +0 -0
  375. /package/{core/com → com}/param/README.md +0 -0
  376. /package/{core/com/cmd → com/pendant}/README.md +0 -0
  377. /package/{core/com → com}/socket/README.md +0 -0
  378. /package/{core/com → com}/sql/README.md +0 -0
  379. /package/{core/com → com}/static/README.md +0 -0
  380. /package/{core/com → com}/task/README.md +0 -0
@@ -1,108 +0,0 @@
1
- const Index = require('mm_machine').Index;
2
- const Drive = require('./drive');
3
-
4
- /**
5
- * Api接口类
6
- * @extends {Index}
7
- * @class
8
- */
9
- class Api extends Index {
10
- /**
11
- * 构造函数
12
- * @param {Object} scope 作用域
13
- * @param {String} title 标题
14
- * @constructor
15
- */
16
- constructor(scope, title) {
17
- super(scope, __dirname);
18
- this.Drive = Drive;
19
- this.type = "api";
20
- this.title = title;
21
- // 默认启用热更新
22
- this.mode = 3;
23
- }
24
- }
25
-
26
- /**
27
- * 接口排序
28
- */
29
- Api.prototype.sort = function() {
30
- this.list.sort(function(o1, o2) {
31
- var p1 = o1.config.path;
32
- var p2 = o2.config.path;
33
- var n = p2.length - p1.length;
34
- if (n) {
35
- return n;
36
- } else {
37
- return o1.config.sort - o2.config.sort;
38
- }
39
- });
40
- };
41
-
42
- /**
43
- * 执行Api
44
- * @param {Object} ctx 请求上下文
45
- * @param {Object} db 数据管理器
46
- * @return {Object|String}
47
- */
48
- Api.prototype.run = async function(ctx, db) {
49
- if (!db) {
50
- db = {
51
- ret: null
52
- };
53
- }
54
- const path = ctx.request.path;
55
- var lt = this.list;
56
-
57
- for (var i = 0, o; o = lt[i++];) {
58
- if (o.config.state === 1 && path.has(o.config.path)) {
59
- var ret = await o.run(ctx, db);
60
- if (this.mode > 4) {
61
- o.exec('reload', o.filename);
62
- }
63
- if (ret) {
64
- db.ret = ret;
65
- break;
66
- }
67
- }
68
- }
69
- return db.ret;
70
- };
71
-
72
-
73
-
74
- /**
75
- * @module 导出API类
76
- */
77
- module.exports = Api;
78
-
79
-
80
- /**
81
- * 创建全局管理器
82
- */
83
- if (!$.pool.api) {
84
- $.pool.api = {};
85
- }
86
-
87
- /**
88
- * API管理器,用于创建缓存
89
- * @param {string} scope 作用域
90
- * @param {string} title 标题
91
- * @return {Object} 返回一个缓存类
92
- */
93
- function api_admin(scope, title) {
94
- if (!scope) {
95
- scope = $.val.scope + '';
96
- }
97
- var obj = $.pool.api[scope];
98
- if (!obj) {
99
- $.pool.api[scope] = new Api(scope, title);
100
- obj = $.pool.api[scope];
101
- }
102
- return obj;
103
- }
104
-
105
- /**
106
- * @module 导出API管理器
107
- */
108
- $.api_admin = api_admin;
@@ -1,158 +0,0 @@
1
- /**
2
- * Oauth身份验证驱动类
3
- * @class
4
- */
5
- class Oauth {
6
- /**
7
- * 构造函数
8
- * @param {String} dir 当前路径
9
- * @constructor
10
- */
11
- constructor(dir) {
12
- // 当前路径
13
- this.dir = dir;
14
- // 当前文件
15
- this.filename;
16
- /* 通用项 */
17
- // 配置参数
18
- this.config = {
19
- // 是否登录
20
- "signIn": false,
21
- // 要求会员级别
22
- "vip": 0,
23
- // 要求管理级别
24
- "gm": 0,
25
- // 要求商户级别
26
- "mc": 0,
27
- // 要求用户组
28
- "user_group": [],
29
- // 要求管理组
30
- "user_admin": [],
31
- // 文件路径, 当调用函数不存在时,会先从文件中加载
32
- "func_file": ""
33
- };
34
- }
35
- }
36
-
37
- /**
38
- * 加载配置对象
39
- * @param {Object} obj 配置对象
40
- */
41
- Oauth.prototype.loadObj = function(obj) {
42
- $.push(this.config, obj);
43
- var f = this.config.func_file;
44
- if (f) {
45
- var file = f.fullname(this.dir);
46
- if (file.hasFile()) {
47
- var cs = require(file);
48
- if (cs) {
49
- $.push(this, cs);
50
- }
51
- }
52
- }
53
- };
54
-
55
- /**
56
- * 身份验证主程序
57
- * @param {Object} ctx HTTP请求上下文
58
- */
59
- Oauth.prototype.main = async function(ctx) {
60
- return null;
61
- };
62
-
63
- /**
64
- * 小校验
65
- * @param {Object} ctx
66
- */
67
- Oauth.prototype.check_sub = async function(ctx) {
68
-
69
- };
70
-
71
- /**
72
- * 验证身份
73
- * @param {Object} ctx HTTP请求上下文
74
- * @return {Object} 验证失败返回错误提示,验证通过返回null
75
- */
76
- Oauth.prototype.check = async function(ctx) {
77
- // 无需登录则不验证身份和权限
78
- var cg = this.config;
79
- var user = ctx.session.user;
80
- if (!user) {
81
- var token = ctx.headers[$.dict.token];
82
- if (token) {
83
- var u = await $.cache.get($.dict.session_id + '_' + token);
84
- if (u) {
85
- var type = typeof(u);
86
- if (type === "string") {
87
- var o = u.toJson();
88
- user = o.user;
89
- } else if (type === "object") {
90
- if (Object.keys(u).length > 0) {
91
- user = u.user;
92
- }
93
- }
94
- if (user) {
95
- ctx.session.user = user;
96
- }
97
- }
98
- }
99
- }
100
- if (!cg.signIn) {
101
- return null;
102
- }
103
- var error = await this.main(ctx);
104
- if (error) {
105
- return error;
106
- }
107
-
108
- error = {
109
- code: 70000,
110
- message: "没有访问权限"
111
- };
112
-
113
- if (user) {
114
- // 判断特殊用户级别
115
- if (cg.gm !== 0 && user.gm < cg.gm) {
116
- return error;
117
- }
118
- if (cg.vip !== 0 && user.vip < cg.vip) {
119
- return error;
120
- }
121
- if (cg.mc !== 0 && user.mc < cg.mc) {
122
- return error;
123
- }
124
-
125
- // 判断用户组
126
- if (cg.user_group.length > 0) {
127
- // 利用filter获取数组交集
128
- var arr2 = user.user_group.split(',');
129
- var arr = cg.user_group.filter(function(v) {
130
- return arr2.indexOf(v) !== -1
131
- });
132
- if (arr.length === 0) {
133
- return error;
134
- }
135
- }
136
-
137
- // 判断管理组
138
- if (cg.user_admin.length > 0) {
139
- // 利用filter获取数组交集
140
- var arr2 = user.user_admin.split(',');
141
- var arr = cg.user_admin.filter(function(v) {
142
- return arr2.indexOf(v) !== -1
143
- });
144
- if (arr.length === 0) {
145
- return error;
146
- }
147
- }
148
- } else {
149
- return {
150
- code: 60000,
151
- message: "账户未登录!"
152
- };
153
- }
154
-
155
- return null;
156
- };
157
-
158
- module.exports = Oauth;
@@ -1,32 +0,0 @@
1
-
2
- /**
3
- * 接口主函数
4
- * @param {Object} ctx HTTP上下文
5
- * @param {Object} db 数据管理器,如: { next: async function{}, ret: {} }
6
- * @return {Object} 执行结果
7
- */
8
- async function main(ctx, db) {
9
- // 获取请求参数
10
- var req = ctx.request;
11
- var {
12
- query,
13
- body
14
- } = req;
15
- // return "hello world" + JSON.stringify(body);
16
-
17
- // 操作sql模板
18
- var m = query.method;
19
- if (m === "add") {
20
-
21
- } else if (m === "del") {
22
-
23
- } else if (m === "set") {
24
-
25
- } else {
26
-
27
- }
28
- var ret = await this.sql.run(query, body, db);
29
- return ret;
30
- };
31
-
32
- exports.main = main;
@@ -1,3 +0,0 @@
1
- ## 插件框架
2
- 用于实现应用结构和应用插件结构,实现了一个mm系统多个应用、一个应用多个插件的系统结构。
3
- 确保应用和插件是可以动态安装、卸载、重置,便捷功能拓展。
@@ -1,4 +0,0 @@
1
- {
2
- "name": "应用管理器",
3
- "script": "./index.js"
4
- }
@@ -1,16 +0,0 @@
1
- {
2
- // 应用名称,应用的唯一标识
3
- "name": "{0}",
4
- // 应用标题,用于检索和识别
5
- "title": "示例应用",
6
- // 应用描述,介绍改应用是做什么用的
7
- "description": "描述该应用是做什么用的",
8
- // 应用版本号,用于升级迭代
9
- "version": "1.0.0",
10
- // 应用语言包文件路径
11
- "lang_path": "./lang/",
12
- // 是否中断执行
13
- "end": true,
14
- // 排序,表示多个应用时在应用下执行的先后顺序
15
- "sort": 10
16
- }
@@ -1,309 +0,0 @@
1
- const compressing = require('compressing');
2
- const Item = require('mm_machine').Item;
3
- const conf = require('mm_config');
4
-
5
- /**
6
- * APP应用驱动类
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 = "./app.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
- // 名称, 由中英文和下“_”组成, 用于修改或卸载 例如: demo
34
- // 同时也是版本唯一标识,当商城有两个应用名称相同时,可以通过版本号查询和下载
35
- "name": "",
36
- // 标题, 介绍事件作用
37
- "title": "",
38
- // 描述, 用于描述该事件有什么用的
39
- "description": "",
40
- // 版本号
41
- "version": "1.0.0",
42
- // 状态 0未启用,1启用
43
- "state": 1,
44
- // 文件路径, 当调用函数不存在时,会先从文件中加载
45
- "func_file": "./app.js",
46
- // 回调函数名 用于决定调用脚本的哪个函数
47
- "func_name": "",
48
- // 语言包路径
49
- "lang_path": "./lang/",
50
- // 指令前缀
51
- "cmd": "",
52
- // 是否中断执行
53
- "end": true,
54
- // 排序
55
- "sort": 10,
56
- // 配置
57
- "options": []
58
- };
59
- // 配置
60
- this.options = {};
61
- }
62
- }
63
-
64
- /**
65
- * 设置配置
66
- * @param {Object} config 配置
67
- */
68
- Drive.prototype.set_config = function(config) {
69
- var file = this.filename;
70
- var cg = Object.assign({}, this.config, config || {});
71
- this.config = conf(cg, file);
72
- }
73
-
74
- /**
75
- * 新建脚本
76
- * @param {String} 文件
77
- */
78
- Drive.prototype.new_script = function(file) {
79
- var fl = __dirname + "/script.js";
80
- if (fl.hasFile()) {
81
- var text = fl.loadText();
82
- if (text) {
83
- var l = $.slash;
84
- var name = file.between('app' + l, l) || 'sys';
85
- text = text.replaceAll('{0}', name)
86
- file.saveText(text);
87
- }
88
- }
89
- };
90
-
91
- /**
92
- * 新建配置
93
- * @param {String} file 文件
94
- */
95
- Drive.prototype.new_config = function(file) {
96
- var fl = __dirname + "/config.tpl.json";
97
- if (fl.hasFile()) {
98
- var text = fl.loadText();
99
- if (text) {
100
- var l = $.slash;
101
- var name = file.between('app' + l, l) || 'sys';
102
- text = text.replaceAll('{0}', name);
103
- file.saveText(text);
104
- }
105
- }
106
- };
107
-
108
- /**
109
- * 设置语言
110
- * @param {Sting} lang
111
- * @return {String} 成功返回null,否则返回错误提示
112
- */
113
- Drive.prototype.set_lang = function(lang) {
114
- var msg = null;
115
- if (!lang) {
116
- lang = "zh_CN"
117
- }
118
- var file = this.config.lang_path + ".json";
119
- if (file.hasFile()) {
120
- var obj = file.loadJson();
121
- if (obj) {
122
- this.lang = obj;
123
- } else {
124
- msg = "语言包不是正确的json格式";
125
- }
126
- } else {
127
- msg = "语言包文件不存在";
128
- }
129
- return msg;
130
- };
131
-
132
- /**
133
- * 安装
134
- * @param {Object} option 配置参数
135
- * @return {String} 成功返回null,否则返回错误提示
136
- */
137
- Drive.prototype.install = function(option) {
138
- var msg = null;
139
- return msg;
140
- };
141
-
142
- /**
143
- * 重启设备
144
- * @param {Object} option 配置
145
- */
146
- Drive.prototype.restart = async function(option) {
147
- await this.exec('stop');
148
- await this.exec('start');
149
- }
150
-
151
- /**
152
- * 初始化之前
153
- * @param {Object} option
154
- */
155
- Drive.prototype.init_before = async function(option) {
156
- this.plugin = $.plugin_admin(this.config.name, this.config.title);
157
- await this.plugin.update();
158
- this.plugin.exec(null, 'init');
159
- }
160
-
161
- /**
162
- * 初始化
163
- * @param {Object} option 配置参数
164
- * @return {String} 成功返回null, 否则返回错误提示
165
- */
166
- Drive.prototype.init = function(option) {
167
- var msg = null;
168
- return msg;
169
- };
170
-
171
- /**
172
- * 更新
173
- * @param {Object} option 配置参数
174
- * @return {String} 成功返回null, 否则返回错误提示
175
- */
176
- Drive.prototype.update = function(option) {
177
- var msg = null;
178
- return msg;
179
- };
180
-
181
- /**
182
- * 卸载
183
- * @param {Object} option 配置参数
184
- * @return {String} 成功返回null,否则返回错误提示
185
- */
186
- Drive.prototype.uninstall = function(option) {
187
- var msg = null;
188
- return msg;
189
- };
190
-
191
- /**
192
- * 启动
193
- * @param {Object} opiton 配置参数
194
- * @return {String} 成功返回null,否则返回错误提示
195
- */
196
- Drive.prototype.start = function(opiton) {
197
- var msg = null;
198
- return msg;
199
- };
200
-
201
- /**
202
- * 启动之后,启动插件
203
- * @param {Object} opiton 配置参数
204
- * @return {String} 成功返回null,否则返回错误提示
205
- */
206
- Drive.prototype.start_after = async function(opiton) {
207
- var msg = null;
208
- this.plugin.run(null, 'start');
209
- return msg;
210
- };
211
-
212
- /**
213
- * 暂停
214
- * @param {Object} opiton 配置参数
215
- * @return {String} 成功返回null,否则返回错误提示
216
- */
217
- Drive.prototype.stop = function(opiton) {
218
- var msg = null;
219
- return msg;
220
- };
221
-
222
- /**
223
- * 结束
224
- * @param {Object} opiton 配置参数
225
- * @return {String} 成功返回null,否则返回错误提示
226
- */
227
- Drive.prototype.end = function(opiton) {
228
- var msg = null;
229
- return msg;
230
- };
231
-
232
- /**
233
- * 商店(用于下载应用相关模块)
234
- * @param {String} item 应用项
235
- * @return {String} 成功返回null,否则返回错误提示
236
- */
237
- Drive.prototype.store = function(item) {
238
- var msg = null;
239
- return msg;
240
- };
241
-
242
- /**
243
- * 帮助(讲解应用使用方法)
244
- * @param {String} item 帮助项
245
- * @return {String} 返回使用方法明细
246
- */
247
- Drive.prototype.help = function(item) {
248
- var body = "";
249
- return body;
250
- };
251
-
252
- /**
253
- * 主程序
254
- * @param {Object} param1 参数1
255
- * @param {Object} param2 参数2
256
- * @return {Object} 返回执行结果
257
- */
258
- Drive.prototype.main = function(param1, param2) {
259
- return null;
260
- };
261
-
262
- /**
263
- * 指令(类似命令提示符)
264
- * @param {String} content 指令内容
265
- * @return {String} 执行结果
266
- */
267
- Drive.prototype.cmd = function(content) {
268
- var body = "";
269
- return body;
270
- };
271
-
272
- /**
273
- * 指令(类似命令提示符)
274
- * @param {String} content 指令内容
275
- * @return {String} 执行结果
276
- */
277
- Drive.prototype.run_cmd = async function(content) {
278
- if (!content) {
279
- content = "";
280
- }
281
- var ret;
282
- try {
283
- ret = this.cmd(content);
284
- } catch (err) {
285
- $.log.error("运行应用指令失败!", this.config.name, err);
286
- }
287
- if (!ret) {
288
- ret = "";
289
- }
290
- return ret;
291
- };
292
-
293
- /**
294
- * 压缩应用
295
- * @param {String} 要压缩的目录
296
- * @returns {String} 打包成功返回压缩包文件地址
297
- */
298
- Drive.prototype.zip = async function(zip_dir = "/static/file/zip/") {
299
- var dir = this.filename.dirname();
300
- var file = ("./" + this.config.name + '.zip').fullname(zip_dir);
301
- file.addDir();
302
- var done = await compressing.zip.compressDir(dir, file);
303
- if (file.hasFile()) {
304
- return file;
305
- }
306
- return null;
307
- }
308
-
309
- module.exports = Drive;