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,259 +0,0 @@
1
- const compressing = require('compressing');
2
- const Index = require('mm_machine').Index;
3
- const Drive = require('./drive');
4
-
5
- /**
6
- * Plugin插件类
7
- * @extends {Index}
8
- * @class
9
- */
10
- class Plugin extends Index {
11
- /**
12
- * 构造函数
13
- * @param {Object} scope 作用域
14
- * @param {String} title 标题
15
- * @constructor
16
- */
17
- constructor(scope, title) {
18
- super(scope, __dirname);
19
- this.Drive = Drive;
20
- this.type = "plugin";
21
- this.title = title;
22
- // 默认启用热更新
23
- this.mode = 3;
24
- }
25
- }
26
-
27
- /**
28
- * 聊天(通过聊天的方式驱动插件, 用于机器人开发)
29
- * @param {String} from_user 发送消息人
30
- * @param {String} to_user 接收消息人
31
- * @param {String} content 内容
32
- * @param {String} group 群组 如果是个人,群组为空
33
- * @param {Number} type 群类型, 1永久会话/群、2临时会话/群
34
- * @param {String} msg_type 消息类型, event事件型、message消息型。默认消息型
35
- * @param {Object} 数据管理器
36
- * @return {String} 回复内容
37
- */
38
- Plugin.prototype.chat = async function(from_user, to_user, group, content, type, msg_type, db) {
39
- var ret = "";
40
- var lt = this.list;
41
- for (var i = 0, o; o = lt[i++];) {
42
- if (o.config.state === 1) {
43
- ret = await o.chat(from_user, to_user, group, content, type, msg_type, db);
44
- if (ret) {
45
- break;
46
- }
47
- }
48
- }
49
- return ret;
50
- };
51
-
52
- /**
53
- * 初始化插件
54
- * @param {Object} option 配置参数
55
- * @return {String} 执行结果
56
- */
57
- Plugin.prototype.init = function(option) {
58
- var ret = "";
59
- var lt = this.list;
60
- for (var i = 0, o; o = lt[i++];) {
61
- ret = o.exec('init', option);
62
- }
63
- return ret;
64
- };
65
-
66
- /**
67
- * 加载插件
68
- * @param {String} path 检索路径
69
- * @param {Boolean} accurate 是否精确路径
70
- */
71
- Plugin.prototype.update_config_all = async function(path, accurate) {
72
- var dir_plugin;
73
- if (accurate) {
74
- dir_plugin = path;
75
- } else {
76
- if (!path) {
77
- path = '/app/' + this.scope;
78
- }
79
- dir_plugin = path + "/plugin/";
80
- }
81
- if (dir_plugin.hasDir()) {
82
- var list_scope = $.dir.get(dir_plugin);
83
- // 遍历目录路径
84
- for (var i = 0, o; o = list_scope[i++];) {
85
- var file = './plugin.json'.fullname(o);
86
- if (file.hasFile()) {
87
- await this.load_file(file, true);
88
- }
89
- }
90
- }
91
- };
92
-
93
- /**
94
- * 压缩插件
95
- * @param {Object} name 插件名称
96
- * @returns {Boolean} 返回压缩路径
97
- */
98
- Plugin.prototype.zip = async function(name) {
99
- var plus = this.get(name);
100
- if (plus) {
101
- return await plus.zip();
102
- }
103
- return null;
104
- }
105
-
106
- /**
107
- * 解压插件
108
- * @param {Object} file 插件压缩文件
109
- * @returns {Boolean} 返回解压结果
110
- */
111
- Plugin.prototype.unzip = async function(file) {
112
- var name = file.basename().left(".");
113
- var dir = `/cache/plugin/${name}`.fullname();
114
- dir.addDir();
115
- var ret;
116
- try {
117
- await compressing.zip.uncompress(file, dir);
118
- ret = {
119
- file,
120
- dir
121
- };
122
- } catch (err) {
123
- $.log.error("插件解压失败!", err);
124
- }
125
- return ret;
126
- }
127
-
128
- /**
129
- * 卸载插件
130
- * @param {String} name 插件名称
131
- * @returns {String} 返回卸载路径
132
- */
133
- Plugin.prototype.uninstall = async function(name) {
134
- var plus = this.get(name);
135
- if (plus) {
136
- await plus.exec('uninstall');
137
- var obj = this.del(name, true);
138
- if (obj) {
139
- var file = obj.filename;
140
- // 删除目录
141
- file.dirname().delDir();
142
- return file
143
- }
144
- }
145
- return null;
146
- }
147
-
148
- /**
149
- * 复制目录
150
- * @param {String} dir_src 原路径
151
- * @param {String} dir 新路径
152
- * @returns {Object} 返回复制结果
153
- */
154
- Plugin.prototype.copy_dir = function(dir_src, dir) {
155
- return new Promise((resolve, reject) => {
156
- $.dir.copy(dir_src, dir, () => {
157
- resolve({
158
- dir_src,
159
- dir
160
- });
161
- });
162
- });
163
- }
164
-
165
- /**
166
- * 安装插件
167
- * @param {String} file 插件压缩文件
168
- * @returns {Object} 返回解压结果
169
- */
170
- Plugin.prototype.install = async function(file) {
171
- var ret = await this.unzip(file);
172
- if (ret) {
173
- var dirs = $.dir.get(ret.dir);
174
- if (dirs.length) {
175
- var dir_src = dirs[0];
176
- var file = "./plugin.json".fullname(dir_src);
177
- var config = file.loadJson();
178
- if (config) {
179
- var app = config.app || 'sys';
180
- var name = config.name;
181
- if (name) {
182
- var dir = `/app/${app}/plugin/${name}`;
183
- await this.copy_dir(dir_src, dir);
184
- var cs = $.pool.plugin[app];
185
- if (cs) {
186
- await cs.update(`/app/${app}/`.fullname());
187
- await cs.exec(name, 'install');
188
- setTimeout(() => {
189
- ret.dir.delDir();
190
- }, 3000)
191
- }
192
- return {
193
- app,
194
- name,
195
- dir_src,
196
- dir
197
- }
198
- }
199
- }
200
- }
201
- }
202
- }
203
-
204
- // /**
205
- // * 更新插件
206
- // * @param {String} name 插件名称
207
- // * @returns {Object} 返回更新结果
208
- // */
209
- // Plugin.prototype.update = async function(name) {
210
- // var plus = this.get(name);
211
- // if (plus) {
212
- // var cg = plus.config;
213
- // // 先将配置缓存
214
- // var file = `/cache/config/${cg.app}_${cg.name}.json`;
215
- // file.saveJson(cg);
216
-
217
- // var dir = plus.filename.dirname();
218
-
219
- // // 判断是否存在git仓库
220
- // if (cg.git) {
221
- // if (dir.hasDir('.git')) {
222
- // // "git fetch";
223
- // // "git reset --hard origin/master"
224
- // }
225
- // }
226
- // } else {
227
- // ret = $.ret.error("更新失败!原因:插件不存在");
228
- // }
229
- // }
230
-
231
- module.exports = Plugin;
232
-
233
-
234
- /**
235
- * 创建全局管理器
236
- */
237
- if (!$.pool.plugin) {
238
- $.pool.plugin = {};
239
- }
240
-
241
- function plugin_admin(scope, title) {
242
- if (!scope) {
243
- scope = $.val.scope + '';
244
- }
245
- var obj = $.pool.plugin[scope];
246
- if (!obj) {
247
- $.pool.plugin[scope] = new Plugin(scope, title);
248
- obj = $.pool.plugin[scope];
249
- }
250
- return obj;
251
- }
252
-
253
- /**
254
- * plugin管理器, 用于管理插件
255
- * @param {string} scope 作用域
256
- * @param {string} title 标题
257
- * @return {Object} 返回一个缓存类
258
- */
259
- $.plugin_admin = plugin_admin;
@@ -1,213 +0,0 @@
1
- /**
2
- * @fileOverview {0}
3
- * @author <a href="作者主页地址">插件作者</a>
4
- * @version 1.0
5
- */
6
-
7
- /**
8
- * 插件对象
9
- */
10
- module.exports = {
11
- /**
12
- * 安装,把插件安装到系统中,在安装时执行
13
- * @param {Object} option 配置参数
14
- * @param {String} option.path 插件安装路径
15
- * @param {Object} option.config 插件配置信息
16
- * @param {String} option.version 插件版本号
17
- * @return {String} 成功返回null,否则返回错误提示。常见错误:路径不存在、版本不兼容、依赖缺失等
18
- */
19
- install(option) {
20
- var msg = null;
21
- // 此处常用于更新文件和导入数据库等操作。通常为一次操作
22
- return msg;
23
- },
24
- /**
25
- * 加载插件,当脚本被引入时会执行
26
- * @param {Object} option 配置参数
27
- * @return {String} 成功返回null, 否则返回错误提示。常见错误:依赖模块加载失败、模块冲突等
28
- */
29
- load(option) {
30
- var msg = null;
31
- // 此处通常用于require加载其他相关模块(不在脚本文件中直接require模块,可提高启动速度,可根据插件优先级优先加载模块)
32
- return msg;
33
- },
34
- /**
35
- * 初始化插件,设置全局变量、路由规则和定时任务等
36
- * @param {Object} option 配置参数
37
- * @return {String} 成功返回null, 否则返回错误提示。常见错误:配置格式错误、路由冲突等
38
- */
39
- init(option) {
40
- var msg = null;
41
- // 此处主要用于重置全局变量和配置,更新路由和更新定时任务等操作
42
- return msg;
43
- },
44
-
45
- /**
46
- * 启动插件,开启路由监听和定时任务
47
- * @param {Object} option 配置参数
48
- * @return {String} 成功返回null,否则返回错误提示。常见错误:端口被占用、服务启动超时等
49
- */
50
- start(option) {
51
- var msg = null;
52
- // 此处主要用于开启路由和定时任务
53
- return msg;
54
- },
55
- /**
56
- * 重启插件,在配置更改或插件更新时执行
57
- * @param {Object} option 配置参数
58
- * @return {String} 成功返回null,否则返回错误提示。常见错误:重启超时、服务未完全停止等
59
- */
60
- restart(option) {
61
- var msg = null;
62
- this.stop();
63
- this.start();
64
- return msg;
65
- },
66
- /**
67
- * 暂停插件,临时停止路由和定时任务的执行
68
- * @param {Object} option 配置参数
69
- * @return {String} 成功返回null,否则返回错误提示。常见错误:有未完成的任务、停止超时等
70
- */
71
- stop(option) {
72
- var msg = null;
73
- // 此处主要用于关闭路由和定时任务
74
- return msg;
75
- },
76
- /**
77
- * 结束插件,清理路由、定时任务和连接
78
- * @param {Object} option 配置参数
79
- * @return {String} 成功返回null,否则返回错误提示。常见错误:资源释放失败、清理超时等
80
- */
81
- end(option) {
82
- var msg = null;
83
- // 主要用于移除注册的路由、 定时任务连接
84
- return msg;
85
- },
86
- /**
87
- * 卸载已加载的模块,释放内存资源
88
- * @param {Object} option 配置参数
89
- * @return {String} 成功返回null,否则返回错误提示。常见错误:模块正在使用、依赖关系阻止卸载等
90
- */
91
- unload(option) {
92
- var msg = null;
93
- // 主要用于移除加载的模块,释放内存(卸载require的模块,降低系统运行内存)
94
- return msg;
95
- },
96
- /**
97
- * 插件版本更新,包括下载、安装和重启
98
- * @param {Object} option 配置参数
99
- * @return {String} 成功返回null, 否则返回错误提示。常见错误:网络问题、版本冲突、空间不足等
100
- */
101
- update(option) {
102
- var msg = null;
103
- // 下载最新版本,重新安装、重新加载并初始化,如果本身程序属于启动状态,将重新启动
104
- this.install(option);
105
- if (this.config.state == 1) {
106
- this.load(option);
107
- this.init(option);
108
- this.start(option);
109
- }
110
- return msg;
111
- },
112
- /**
113
- * 卸载插件,完全移除插件及其相关资源
114
- * @param {Object} option 配置参数
115
- * @return {String} 成功返回null,否则返回错误提示。常见错误:文件删除失败、数据库清理失败等
116
- */
117
- uninstall(option) {
118
- var msg = null;
119
- // 此处从系统中完全删除程序及其所有相关文件和配置。卸载后,该插件不会在系统中留下任何痕迹‌
120
- return msg;
121
- },
122
- /**
123
- * 配置更新后的处理函数
124
- * @param {Object} options 更新后的配置对象
125
- */
126
- update_options_after(options) {
127
- if (this.config.state) {
128
- this.restart();
129
- }
130
- },
131
- /**
132
- * 获取插件使用帮助信息
133
- * @param {String} item 查询的功能项,如"install"、"api"等
134
- * @return {Object} 返回帮助信息对象
135
- * @example
136
- * // 获取安装相关帮助
137
- * help("install")
138
- * // 返回: {title: "安装说明", steps: ["步骤1...", "步骤2..."], examples: [...]}
139
- */
140
- help(item) {
141
- var tip = "";
142
- switch (item) {
143
- case "run":
144
- break;
145
- default:
146
- break;
147
- }
148
- return tip;
149
- },
150
-
151
- /**
152
- * 插件主程序,处理核心业务逻辑
153
- * @param {Object} param1 业务参数对象
154
- * @param {Object} param2 配置参数对象
155
- * @return {Object} 返回执行结果对象 {code: 0, msg: "success", data: {}}
156
- * @example
157
- * main({action: "process", data: {id: 1}}, {options: {async: true}})
158
- * // 返回: {code: 0, msg: "处理成功", data: {result: "..."}}
159
- */
160
- main(param1, param2) {
161
- var ret = null;
162
- return ret;
163
- },
164
-
165
- /**
166
- * 执行命令行指令
167
- * @param {String} content 指令内容,格式为"命令 参数1 参数2..."
168
- * @return {String} 执行结果文本
169
- * @example
170
- * cmd("status --detail")
171
- * // 返回: "运行状态: 正常\n内存使用: 80MB\n已运行时间: 2h"
172
- */
173
- cmd(content) {
174
- var ret = "";
175
- return ret;
176
- },
177
-
178
- /**
179
- * 插件API接口,供其他插件调用
180
- * @param {Object} ctx HTTP上下文对象
181
- * @param {String} ctx.method 请求方法
182
- * @param {Object} ctx.query 查询参数
183
- * @param {Object} ctx.body 请求体数据
184
- * @param {Object} db 数据库管理器实例
185
- * @return {Object} 返回API执行结果 {code: 200, data: {}, msg: ""}
186
- * @example
187
- * api({method: "GET", query: {id: 1}}, db)
188
- * // 返回: {code: 200, data: {name: "test"}, msg: "success"}
189
- */
190
- api(ctx, db) {
191
- var ret = "";
192
- return ret;
193
- },
194
-
195
- /**
196
- * 聊天消息处理函数,用于机器人开发
197
- * @param {String} from_user 发送消息用户的唯一标识
198
- * @param {String} to_user 接收消息用户的唯一标识
199
- * @param {String} content 消息内容
200
- * @param {String} group 群组ID,个人聊天时为空
201
- * @param {Number} type 会话类型: 1-永久会话/群、2-临时会话/群
202
- * @param {String} msg_type 消息类型: event-事件消息、message-普通消息(默认)
203
- * @param {Object} db 数据管理器实例
204
- * @return {String} 回复消息内容
205
- * @example
206
- * chat("user1", "user2", "你好", "", 1, "message", db)
207
- * // 返回: "你好,我是智能助手,有什么可以帮你的吗?"
208
- */
209
- async chat(from_user, to_user, group, content, type, msg_type, db) {
210
- var ret = "";
211
- return ret;
212
- }
213
- };
@@ -1,4 +0,0 @@
1
- {
2
- "name": "rpc通讯管理器",
3
- "script": "./index.js"
4
- }
@@ -1,160 +0,0 @@
1
- const Item = require('mm_machine').Item;
2
-
3
- /**
4
- * Api接口驱动类
5
- * @extends {Item}
6
- * @class
7
- */
8
- class Drive extends Item {
9
- /**
10
- * 构造函数
11
- * @param {String} dir 当前目录
12
- * @constructor
13
- */
14
- constructor(dir) {
15
- /**
16
- * 定义当前RPC文件路径
17
- */
18
- this.rpc_file_now = "";
19
-
20
- /**
21
- * 定义rpc 方法
22
- */
23
- this.methods = {};
24
- }
25
- }
26
-
27
- /**
28
- * 获取现有参数
29
- * @param {String} file 文件名
30
- * @return {Object} 获取的对象
31
- */
32
- Drive.prototype.getParam = function(file) {
33
- if ($.param) {
34
- var obj = $.param.list.getObj({
35
- filename: file
36
- });
37
- if (obj) {
38
- return obj;
39
- }
40
- }
41
- return null;
42
- };
43
-
44
- /**
45
- * 设置参数对象
46
- * @param {Object} param 参数对象
47
- */
48
- Drive.prototype.setParam = function(param) {
49
- if ($.param) {
50
- var lt = $.param.list;
51
- if (lt) {
52
- var has = false;
53
- var len = lt.length;
54
- for (var i = 0; i < len; i++) {
55
- var o = lt[i];
56
- if (param.filename === o.filename) {
57
- $.param.list[i] = param;
58
- has = true;
59
- break;
60
- }
61
- }
62
- if (!has) {
63
- $.param.list.push(param);
64
- }
65
- }
66
- }
67
- };
68
-
69
- /**
70
- * 加载参数
71
- * @param {String} file_path 文件路径
72
- */
73
- Drive.prototype.loadParam = async function(file_path) {
74
- if (file_path) {
75
- var p = file_path.fullname(this.dir);
76
- var param = this.getParam(p);
77
- if (param) {
78
- this.param = param;
79
- } else {
80
- this.param = new Param(this.dir);
81
- await this.param.exec('load_config', p);
82
- this.setParam(this.param);
83
- this.param.load('load');
84
- }
85
- }
86
- };
87
-
88
- /**
89
- * 加载完成后执行
90
- */
91
- Drive.prototype.load_after = function() {
92
- var cg = this.config;
93
- this.loadParam(cg.param_path);
94
- };
95
-
96
-
97
- /**
98
- * 验证参数
99
- * @param {Object} query url参数
100
- * @param {Object} body 内容参数
101
- * @param {String} method 方法
102
- * @return {Object} 验证结果
103
- */
104
- Drive.prototype.checkParam = function(query, body, method) {
105
- if (this.param) {
106
- var msg = this.param.check(query, body, method);
107
- if (msg) {
108
- var code;
109
- if (msg.indexOf("必须") !== -1 || msg.indexOf("为空") !== -1) {
110
- code = 30001;
111
- } else {
112
- code = 30002;
113
- }
114
- return $.ret.error(code, msg);
115
- }
116
- }
117
- return null;
118
- };
119
-
120
-
121
- /**
122
- * 运行GRPC方法
123
- * @param {Object} db 数据库管理器
124
- * @param {String} method 方法名称
125
- * @param {Object} query 查询条件
126
- * @param {Object} body 增改项
127
- * @return {Object} 返回执行结果
128
- */
129
- Drive.prototype.run = async function(db, method, query, body) {
130
- var func = this.methods[method];
131
- var ret = {};
132
- try {
133
- if (func) {
134
- ret = this.checkParam(query, body, method);
135
- if (!ret) {
136
- ret = await func(db, query, body);
137
- }
138
- } else {
139
- ret = {
140
- error: {
141
- code: 60000,
142
- message: "方法名称不存在",
143
- data: Object.keys(this.methods)
144
- }
145
- }
146
- }
147
- } catch (err) {
148
- $.log.error("运行RPC方法错误!", method, err);
149
- ret = {
150
- error: {
151
- code: 500,
152
- message: "服务端业务逻辑错误"
153
- }
154
- }
155
- }
156
- return ret;
157
- };
158
-
159
- /* 导出驱动 */
160
- module.exports = Drive;
@@ -1,87 +0,0 @@
1
- const Index = require('mm_machine').Index;
2
- const Drive = require('./drive');
3
-
4
- /**
5
- * RPC导航类
6
- * @extends {Index}
7
- * @class
8
- */
9
- class RPC 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 = "rpc";
20
- this.title = title;
21
- this.list = [];
22
- // 默认启用热更新
23
- this.mode = 3;
24
- }
25
- }
26
-
27
- /**
28
- * 运行GRPC方法
29
- * @param {Object} db 数据库管理器
30
- * @param {String} class_name 类名
31
- * @param {String} method 方法名称
32
- * @param {Object} query 查询条件
33
- * @param {Object} body 增改项
34
- * @return {Object} 返回执行结果
35
- */
36
- RPC.prototype.run = async function(db, class_name, method, query, body) {
37
- if (!db) {
38
- db = {
39
- ret: null
40
- };
41
- }
42
-
43
- var lt = this.list;
44
- for (var i = 0, o; o = lt[i++];) {
45
- if (o.config.state === 1 && class_name == o.config.name) {
46
- var ret = await o.run(db, method, query, body);
47
- if (ret) {
48
- db.ret = ret;
49
- break;
50
- }
51
- }
52
- }
53
- return db.ret;
54
- };
55
-
56
- /* 导出指令 */
57
- exports.RPC = RPC;
58
-
59
- /**
60
- * RPC事件池
61
- */
62
- if (!$.pool.rpc) {
63
- $.pool.rpc = {};
64
- }
65
-
66
- /**
67
- * RPC管理器,用于创建缓存
68
- * @param {String} scope 作用域
69
- * @param {string} title 标题
70
- * @return {Object} 返回一个缓存类
71
- */
72
- function rpc_admin(scope, title) {
73
- if (!scope) {
74
- scope = $.val.scope + '';
75
- }
76
- var obj = $.pool.rpc[scope];
77
- if (!obj) {
78
- $.pool.rpc[scope] = new RPC(scope, title);
79
- obj = $.pool.rpc[scope];
80
- }
81
- return obj;
82
- }
83
-
84
- /**
85
- * @module 导出RPC管理器
86
- */
87
- $.rpc_admin = rpc_admin;