cgserver 12.0.8 → 12.2.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 (176) hide show
  1. package/README.md +9 -0
  2. package/dist/lib/Framework/AI/AiObject.js +10 -10
  3. package/dist/lib/Framework/AI/Astar.js +133 -133
  4. package/dist/lib/Framework/AI/BehaviorAI.js +340 -307
  5. package/dist/lib/Framework/AI/Entity.js +33 -33
  6. package/dist/lib/Framework/AI/Point.js +68 -68
  7. package/dist/lib/Framework/AI/TriggerMgr.js +201 -201
  8. package/dist/lib/Framework/Config/Config.js +74 -41
  9. package/dist/lib/Framework/Config/DbConfig.js +14 -14
  10. package/dist/lib/Framework/Config/FrameworkConfig.js +139 -173
  11. package/dist/lib/Framework/Config/IServerConfig.js +31 -31
  12. package/dist/lib/Framework/Config/_error_.js +35 -35
  13. package/dist/lib/Framework/Core/ByteTool.js +85 -85
  14. package/dist/lib/Framework/Core/Core.js +724 -688
  15. package/dist/lib/Framework/Core/Timer.js +116 -116
  16. package/dist/lib/Framework/Database/Decorator/AutoIncrement.js +10 -11
  17. package/dist/lib/Framework/Database/Decorator/DBCache.js +98 -65
  18. package/dist/lib/Framework/Database/Decorator/NotNull.js +10 -11
  19. package/dist/lib/Framework/Database/Decorator/PrimaryKey.js +10 -11
  20. package/dist/lib/Framework/Database/Decorator/Property.js +61 -61
  21. package/dist/lib/Framework/Database/Decorator/Table.js +14 -15
  22. package/dist/lib/Framework/Database/Decorator/Type.js +19 -20
  23. package/dist/lib/Framework/Database/MSSql/MSSqlManager.js +86 -53
  24. package/dist/lib/Framework/Database/Mongo/MongoBaseService.js +141 -141
  25. package/dist/lib/Framework/Database/Mongo/MongoManager.js +595 -547
  26. package/dist/lib/Framework/Database/Mongo/MongoServiceManager.js +52 -52
  27. package/dist/lib/Framework/Database/Mysql/MysqlBaseService.js +280 -280
  28. package/dist/lib/Framework/Database/Mysql/MysqlManager.js +138 -105
  29. package/dist/lib/Framework/Database/Redis/RedisManager.js +94 -61
  30. package/dist/lib/Framework/Decorator/AdminValidate.js +18 -19
  31. package/dist/lib/Framework/Decorator/AuthorityValidate.js +22 -22
  32. package/dist/lib/Framework/Decorator/CreatorValidate.js +18 -19
  33. package/dist/lib/Framework/Decorator/JsonAdminValidate.js +14 -15
  34. package/dist/lib/Framework/Decorator/JsonAuthorityValidate.js +20 -20
  35. package/dist/lib/Framework/Decorator/JsonCreatorValidate.js +18 -19
  36. package/dist/lib/Framework/Decorator/SyncCall.js +41 -42
  37. package/dist/lib/Framework/Decorator/SyncCallServer.js +77 -77
  38. package/dist/lib/Framework/Logic/CacheTool.js +106 -73
  39. package/dist/lib/Framework/Logic/EventTool.js +31 -28
  40. package/dist/lib/Framework/Logic/HttpTool.js +138 -105
  41. package/dist/lib/Framework/Logic/Log.js +121 -88
  42. package/dist/lib/Framework/Logic/SyncQueueTool.js +44 -44
  43. package/dist/lib/Framework/Server/ProtoFilter/GoogleProtoFilter.js +90 -57
  44. package/dist/lib/Framework/Server/ProtoFilter/IProtoFilter.js +9 -9
  45. package/dist/lib/Framework/Server/ProtoFilter/JsonProtoFilter.js +29 -29
  46. package/dist/lib/Framework/Server/ProtoFilter/ProtoFactory.js +35 -35
  47. package/dist/lib/Framework/Server/RpcWebSocketServer/CgMq.js +180 -180
  48. package/dist/lib/Framework/Server/RpcWebSocketServer/IRpc.js +38 -38
  49. package/dist/lib/Framework/Server/RpcWebSocketServer/IRpcClientWebSocket.js +253 -253
  50. package/dist/lib/Framework/Server/RpcWebSocketServer/IRpcServerWebSocket.js +94 -94
  51. package/dist/lib/Framework/Server/SocketServer/IClientSocket.js +44 -44
  52. package/dist/lib/Framework/Server/SocketServer/IServerSocket.js +114 -81
  53. package/dist/lib/Framework/Server/SocketServer/ISocket.js +255 -222
  54. package/dist/lib/Framework/Server/SocketServer/ISocketServer.js +177 -144
  55. package/dist/lib/Framework/Server/SocketServer/PacketParser.js +40 -40
  56. package/dist/lib/Framework/Server/WebServer/Controller/BaseController.js +119 -119
  57. package/dist/lib/Framework/Server/WebServer/Controller/MongoBaseUserController.js +171 -171
  58. package/dist/lib/Framework/Server/WebServer/Controller/MysqlBaseUserController.js +169 -169
  59. package/dist/lib/Framework/Server/WebServer/Engine/ControllerManager.js +115 -115
  60. package/dist/lib/Framework/Server/WebServer/Engine/Engine.js +254 -218
  61. package/dist/lib/Framework/Server/WebServer/Engine/RazorJs.js +543 -543
  62. package/dist/lib/Framework/Server/WebServer/Engine/Request.js +226 -226
  63. package/dist/lib/Framework/Server/WebServer/Engine/Response.js +120 -87
  64. package/dist/lib/Framework/Server/WebServer/IWebServer.js +55 -55
  65. package/dist/lib/Framework/Server/WebSocketServer/IClientWebSocket.js +44 -44
  66. package/dist/lib/Framework/Server/WebSocketServer/IServerWebSocket.js +128 -95
  67. package/dist/lib/Framework/Server/WebSocketServer/IWebSocket.js +248 -215
  68. package/dist/lib/Framework/Server/WebSocketServer/IWebSocketServer.js +250 -217
  69. package/dist/lib/Framework/Service/MongoAccountService.js +339 -339
  70. package/dist/lib/Framework/Service/MongoCacheService.js +50 -50
  71. package/dist/lib/Framework/Service/MongoUserService.js +129 -96
  72. package/dist/lib/Framework/Service/MysqlAccountService.js +411 -411
  73. package/dist/lib/Framework/Service/MysqlUserService.js +204 -171
  74. package/dist/lib/Framework/Service/ini.js +36 -36
  75. package/dist/lib/Framework/ThirdParty/AlipayTool.js +117 -205
  76. package/dist/lib/Framework/ThirdParty/Alisms.js +61 -50
  77. package/dist/lib/Framework/ThirdParty/AppleTool.js +271 -235
  78. package/dist/lib/Framework/ThirdParty/CgRankTool.js +215 -215
  79. package/dist/lib/Framework/ThirdParty/EmailTool.js +71 -38
  80. package/dist/lib/Framework/ThirdParty/QQTool.js +162 -129
  81. package/dist/lib/Framework/ThirdParty/QiniuTool.js +62 -29
  82. package/dist/lib/Framework/ThirdParty/Rpc.js +79 -79
  83. package/dist/lib/Framework/ThirdParty/WechatTool.js +167 -134
  84. package/dist/lib/Framework/cgserver.js +215 -212
  85. package/dist/lib/Framework/global.js +74 -74
  86. package/dist/lib/Framework/index.js +38 -5
  87. package/dist/lib/Framework/index_export_.js +180 -177
  88. package/dist/lib/test/test.js +21 -21
  89. package/dist/types/Framework/AI/AiObject.d.ts +5 -5
  90. package/dist/types/Framework/AI/Astar.d.ts +38 -38
  91. package/dist/types/Framework/AI/BehaviorAI.d.ts +24 -24
  92. package/dist/types/Framework/AI/Entity.d.ts +12 -12
  93. package/dist/types/Framework/AI/Point.d.ts +17 -17
  94. package/dist/types/Framework/AI/TriggerMgr.d.ts +51 -51
  95. package/dist/types/Framework/Config/Config.d.ts +9 -9
  96. package/dist/types/Framework/Config/DbConfig.d.ts +11 -11
  97. package/dist/types/Framework/Config/FrameworkConfig.d.ts +146 -178
  98. package/dist/types/Framework/Config/IServerConfig.d.ts +9 -9
  99. package/dist/types/Framework/Config/_error_.d.ts +99 -99
  100. package/dist/types/Framework/Core/ByteTool.d.ts +21 -21
  101. package/dist/types/Framework/Core/Core.d.ts +119 -120
  102. package/dist/types/Framework/Core/Timer.d.ts +16 -16
  103. package/dist/types/Framework/Database/Decorator/AutoIncrement.d.ts +1 -1
  104. package/dist/types/Framework/Database/Decorator/DBCache.d.ts +22 -22
  105. package/dist/types/Framework/Database/Decorator/NotNull.d.ts +1 -1
  106. package/dist/types/Framework/Database/Decorator/PrimaryKey.d.ts +1 -1
  107. package/dist/types/Framework/Database/Decorator/Property.d.ts +57 -57
  108. package/dist/types/Framework/Database/Decorator/Table.d.ts +1 -1
  109. package/dist/types/Framework/Database/Decorator/Type.d.ts +1 -1
  110. package/dist/types/Framework/Database/MSSql/MSSqlManager.d.ts +26 -26
  111. package/dist/types/Framework/Database/Mongo/MongoBaseService.d.ts +116 -116
  112. package/dist/types/Framework/Database/Mongo/MongoManager.d.ts +207 -204
  113. package/dist/types/Framework/Database/Mongo/MongoServiceManager.d.ts +13 -13
  114. package/dist/types/Framework/Database/Mysql/MysqlBaseService.d.ts +34 -34
  115. package/dist/types/Framework/Database/Mysql/MysqlManager.d.ts +30 -30
  116. package/dist/types/Framework/Database/Redis/RedisManager.d.ts +24 -24
  117. package/dist/types/Framework/Decorator/AdminValidate.d.ts +1 -1
  118. package/dist/types/Framework/Decorator/AuthorityValidate.d.ts +2 -2
  119. package/dist/types/Framework/Decorator/CreatorValidate.d.ts +1 -1
  120. package/dist/types/Framework/Decorator/JsonAdminValidate.d.ts +1 -1
  121. package/dist/types/Framework/Decorator/JsonAuthorityValidate.d.ts +2 -2
  122. package/dist/types/Framework/Decorator/JsonCreatorValidate.d.ts +1 -1
  123. package/dist/types/Framework/Decorator/SyncCall.d.ts +12 -12
  124. package/dist/types/Framework/Decorator/SyncCallServer.d.ts +14 -14
  125. package/dist/types/Framework/Logic/CacheTool.d.ts +27 -27
  126. package/dist/types/Framework/Logic/EventTool.d.ts +11 -12
  127. package/dist/types/Framework/Logic/HttpTool.d.ts +19 -19
  128. package/dist/types/Framework/Logic/Log.d.ts +18 -18
  129. package/dist/types/Framework/Logic/SyncQueueTool.d.ts +21 -21
  130. package/dist/types/Framework/Server/ProtoFilter/GoogleProtoFilter.d.ts +9 -9
  131. package/dist/types/Framework/Server/ProtoFilter/IProtoFilter.d.ts +10 -10
  132. package/dist/types/Framework/Server/ProtoFilter/JsonProtoFilter.d.ts +6 -6
  133. package/dist/types/Framework/Server/ProtoFilter/ProtoFactory.d.ts +12 -12
  134. package/dist/types/Framework/Server/RpcWebSocketServer/CgMq.d.ts +59 -59
  135. package/dist/types/Framework/Server/RpcWebSocketServer/IRpc.d.ts +33 -33
  136. package/dist/types/Framework/Server/RpcWebSocketServer/IRpcClientWebSocket.d.ts +34 -34
  137. package/dist/types/Framework/Server/RpcWebSocketServer/IRpcServerWebSocket.d.ts +23 -23
  138. package/dist/types/Framework/Server/SocketServer/IClientSocket.d.ts +16 -18
  139. package/dist/types/Framework/Server/SocketServer/IServerSocket.d.ts +27 -29
  140. package/dist/types/Framework/Server/SocketServer/ISocket.d.ts +78 -81
  141. package/dist/types/Framework/Server/SocketServer/ISocketServer.d.ts +44 -45
  142. package/dist/types/Framework/Server/SocketServer/PacketParser.d.ts +8 -10
  143. package/dist/types/Framework/Server/WebServer/Controller/BaseController.d.ts +34 -34
  144. package/dist/types/Framework/Server/WebServer/Controller/MongoBaseUserController.d.ts +28 -28
  145. package/dist/types/Framework/Server/WebServer/Controller/MysqlBaseUserController.d.ts +27 -27
  146. package/dist/types/Framework/Server/WebServer/Engine/ControllerManager.d.ts +37 -37
  147. package/dist/types/Framework/Server/WebServer/Engine/Engine.d.ts +42 -44
  148. package/dist/types/Framework/Server/WebServer/Engine/RazorJs.d.ts +21 -21
  149. package/dist/types/Framework/Server/WebServer/Engine/Request.d.ts +47 -50
  150. package/dist/types/Framework/Server/WebServer/Engine/Response.d.ts +26 -26
  151. package/dist/types/Framework/Server/WebServer/IWebServer.d.ts +22 -22
  152. package/dist/types/Framework/Server/WebSocketServer/IClientWebSocket.d.ts +17 -17
  153. package/dist/types/Framework/Server/WebSocketServer/IServerWebSocket.d.ts +37 -38
  154. package/dist/types/Framework/Server/WebSocketServer/IWebSocket.d.ts +76 -76
  155. package/dist/types/Framework/Server/WebSocketServer/IWebSocketServer.d.ts +49 -49
  156. package/dist/types/Framework/Service/MongoAccountService.d.ts +62 -62
  157. package/dist/types/Framework/Service/MongoCacheService.d.ts +19 -19
  158. package/dist/types/Framework/Service/MongoUserService.d.ts +31 -31
  159. package/dist/types/Framework/Service/MysqlAccountService.d.ts +67 -67
  160. package/dist/types/Framework/Service/MysqlUserService.d.ts +33 -33
  161. package/dist/types/Framework/Service/ini.d.ts +29 -29
  162. package/dist/types/Framework/ThirdParty/AlipayTool.d.ts +76 -108
  163. package/dist/types/Framework/ThirdParty/Alisms.d.ts +23 -13
  164. package/dist/types/Framework/ThirdParty/AppleTool.d.ts +131 -131
  165. package/dist/types/Framework/ThirdParty/CgRankTool.d.ts +107 -107
  166. package/dist/types/Framework/ThirdParty/EmailTool.d.ts +4 -4
  167. package/dist/types/Framework/ThirdParty/QQTool.d.ts +41 -41
  168. package/dist/types/Framework/ThirdParty/QiniuTool.d.ts +5 -5
  169. package/dist/types/Framework/ThirdParty/Rpc.d.ts +28 -28
  170. package/dist/types/Framework/ThirdParty/WechatTool.d.ts +30 -30
  171. package/dist/types/Framework/cgserver.d.ts +63 -63
  172. package/dist/types/Framework/global.d.ts +45 -45
  173. package/dist/types/Framework/index.d.ts +2 -2
  174. package/dist/types/Framework/index_export_.d.ts +81 -79
  175. package/dist/types/test/test.d.ts +1 -1
  176. package/package.json +8 -4
@@ -1,226 +1,226 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Request = void 0;
4
- const url_1 = require("url");
5
- const Core_1 = require("../../../Core/Core");
6
- const Log_1 = require("../../../Logic/Log");
7
- class Request {
8
- _req = null;
9
- get baseReq() {
10
- return this._req;
11
- }
12
- _cfg = null;
13
- _post_cb = null;
14
- set onPost(value) {
15
- this._post_cb = value;
16
- }
17
- _module = "";
18
- get module() {
19
- return this._module;
20
- }
21
- _controller = "";
22
- get controller() {
23
- return this._controller;
24
- }
25
- _action = "";
26
- get action() {
27
- return this._action;
28
- }
29
- _suffix = "";
30
- get suffix() {
31
- return this._suffix;
32
- }
33
- _file_url = null;
34
- get fileUrl() {
35
- return this._file_url;
36
- }
37
- _params = {};
38
- get params() {
39
- var body = (this._req.query || {});
40
- for (let k in body) {
41
- var v = body[k];
42
- if (!Core_1.core.isString(v)) {
43
- continue;
44
- }
45
- if (parseInt(v) == v) {
46
- body[k] = parseInt(v);
47
- }
48
- else if (parseFloat(v) == v) {
49
- body[k] == parseFloat(v);
50
- }
51
- }
52
- return body;
53
- }
54
- /**
55
- * 原始body字符串
56
- */
57
- get rawBody() {
58
- if (!this._req) {
59
- return "";
60
- }
61
- return this._req["rawBody"] || "";
62
- }
63
- get postData() {
64
- var body = this._req.body || {};
65
- if (this._req.headers["content-type"] == "application/x-www-form-urlencoded") {
66
- for (let k in body) {
67
- body = k;
68
- break;
69
- }
70
- }
71
- if (Core_1.core.isString(body)) {
72
- try {
73
- body = JSON.parse(body);
74
- }
75
- catch (e) {
76
- Log_1.gLog.error("post data--" + body + "--parse error");
77
- body = {};
78
- }
79
- }
80
- return body;
81
- }
82
- get url() {
83
- return this._req.url;
84
- }
85
- get root() {
86
- let root = this._req.headers.host;
87
- if (root != "") {
88
- root = this._req.protocol + "://" + root;
89
- }
90
- return root;
91
- }
92
- get method() {
93
- return this._req.method;
94
- }
95
- get headers() {
96
- return this._req.headers;
97
- }
98
- get remoteHost() {
99
- let ips = this._req.headers['x-forwarded-for'];
100
- let ip = "";
101
- if (Core_1.core.isArray(ips)) {
102
- ip = ips[0];
103
- }
104
- else {
105
- ip = ips;
106
- }
107
- ip = ip ||
108
- this._req.socket.remoteAddress ||
109
- this._req.ip || "";
110
- ip = ip.replace("::ffff:", "");
111
- return ip;
112
- }
113
- constructor(req, cfg) {
114
- this._cfg = cfg;
115
- this._req = req;
116
- this._init();
117
- }
118
- getCookie(key) {
119
- let cookie_key = this._cfg.cookie.prefix + key;
120
- if (!this._req.cookies) {
121
- return null;
122
- }
123
- return this._req.cookies[cookie_key];
124
- }
125
- _init() {
126
- let path = this._req.url;
127
- //服务器根目录路径写法,链接转换
128
- let _i = path.lastIndexOf("~");
129
- if (_i >= 0) {
130
- path = path.substr(_i + 1);
131
- }
132
- //处理参数
133
- this._parseParams(path);
134
- }
135
- _addListener(event, listener) {
136
- this._req.addListener(event, listener);
137
- }
138
- _parseParams(path) {
139
- this._module = this._cfg.routs.onlyModule || this._cfg.routs.defaults.module;
140
- this._controller = this._cfg.routs.defaults.controller;
141
- this._action = this._cfg.routs.defaults.action;
142
- this._suffix = null;
143
- this._file_url = null;
144
- this._params = {};
145
- if (path == "/") {
146
- return;
147
- }
148
- let firstQuoteIndex = path.indexOf("?");
149
- let preQuoteStr = path;
150
- if (firstQuoteIndex > 0) {
151
- preQuoteStr = path.substring(0, firstQuoteIndex);
152
- }
153
- let lastDotIndex = preQuoteStr.lastIndexOf(".");
154
- if (lastDotIndex > 0) {
155
- let dotStr = preQuoteStr.substring(lastDotIndex + 1);
156
- this._suffix = dotStr;
157
- this._file_url = preQuoteStr;
158
- return;
159
- }
160
- let quote_index = path.indexOf("?");
161
- if (quote_index >= 0) {
162
- let url = new url_1.URL(path);
163
- url.searchParams.forEach((value, name, searchParams) => {
164
- this._params[name] = value;
165
- });
166
- path = path.substring(0, quote_index);
167
- }
168
- let params = path.split("/");
169
- let default_module = false;
170
- if (this._cfg.routs.onlyModule) {
171
- default_module = true;
172
- }
173
- if (params.length > 1 && params[1].length > 0) {
174
- /**
175
- * 如果是only模式,那么就不支持controller和module相同,
176
- * 如果相同则认为是模块名,这样就可以同时支持,带模块的路径模式和非带模块的路径模式了
177
- */
178
- if (default_module
179
- && params[1].toLowerCase() == this._cfg.routs.onlyModule.toLowerCase()) {
180
- default_module = false;
181
- }
182
- if (default_module) {
183
- this._controller = params[1];
184
- }
185
- else {
186
- this._module = params[1];
187
- }
188
- }
189
- if (params.length > 2 && params[2].length > 0) {
190
- if (default_module) {
191
- this._action = params[2];
192
- }
193
- else {
194
- this._controller = params[2];
195
- }
196
- }
197
- if (params.length > 3
198
- && params[3].length > 0
199
- && !default_module) {
200
- this._action = params[3];
201
- }
202
- this._params = this._params || {};
203
- return;
204
- }
205
- getDebugInfo() {
206
- let debuginfo = {
207
- module: this._module,
208
- controller: this._controller,
209
- action: this._action,
210
- suffix: this._suffix,
211
- file_url: this._file_url,
212
- params: this._params,
213
- post: this.postData,
214
- method: this._req.method.toLowerCase()
215
- };
216
- return debuginfo;
217
- }
218
- debugInfo(force = false) {
219
- if (!this._cfg.debug && !force) {
220
- return;
221
- }
222
- let debuginfo = this.getDebugInfo();
223
- Log_1.gLog.info(debuginfo);
224
- }
225
- }
226
- exports.Request = Request;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Request = void 0;
4
+ const url_1 = require("url");
5
+ const Core_1 = require("../../../Core/Core");
6
+ const Log_1 = require("../../../Logic/Log");
7
+ class Request {
8
+ _req = null;
9
+ get baseReq() {
10
+ return this._req;
11
+ }
12
+ _cfg = null;
13
+ _post_cb = null;
14
+ set onPost(value) {
15
+ this._post_cb = value;
16
+ }
17
+ _module = "";
18
+ get module() {
19
+ return this._module;
20
+ }
21
+ _controller = "";
22
+ get controller() {
23
+ return this._controller;
24
+ }
25
+ _action = "";
26
+ get action() {
27
+ return this._action;
28
+ }
29
+ _suffix = "";
30
+ get suffix() {
31
+ return this._suffix;
32
+ }
33
+ _file_url = null;
34
+ get fileUrl() {
35
+ return this._file_url;
36
+ }
37
+ _params = {};
38
+ get params() {
39
+ var body = (this._req.query || {});
40
+ for (let k in body) {
41
+ var v = body[k];
42
+ if (!Core_1.core.isString(v)) {
43
+ continue;
44
+ }
45
+ if (parseInt(v) == v) {
46
+ body[k] = parseInt(v);
47
+ }
48
+ else if (parseFloat(v) == v) {
49
+ body[k] == parseFloat(v);
50
+ }
51
+ }
52
+ return body;
53
+ }
54
+ /**
55
+ * 原始body字符串
56
+ */
57
+ get rawBody() {
58
+ if (!this._req) {
59
+ return "";
60
+ }
61
+ return this._req["rawBody"] || "";
62
+ }
63
+ get postData() {
64
+ var body = this._req.body || {};
65
+ if (this._req.headers["content-type"] == "application/x-www-form-urlencoded") {
66
+ for (let k in body) {
67
+ body = k;
68
+ break;
69
+ }
70
+ }
71
+ if (Core_1.core.isString(body)) {
72
+ try {
73
+ body = JSON.parse(body);
74
+ }
75
+ catch (e) {
76
+ Log_1.gLog.error("post data--" + body + "--parse error");
77
+ body = {};
78
+ }
79
+ }
80
+ return body;
81
+ }
82
+ get url() {
83
+ return this._req.url;
84
+ }
85
+ get root() {
86
+ let root = this._req.headers.host;
87
+ if (root != "") {
88
+ root = this._req.protocol + "://" + root;
89
+ }
90
+ return root;
91
+ }
92
+ get method() {
93
+ return this._req.method;
94
+ }
95
+ get headers() {
96
+ return this._req.headers;
97
+ }
98
+ get remoteHost() {
99
+ let ips = this._req.headers['x-forwarded-for'];
100
+ let ip = "";
101
+ if (Core_1.core.isArray(ips)) {
102
+ ip = ips[0];
103
+ }
104
+ else {
105
+ ip = ips;
106
+ }
107
+ ip = ip ||
108
+ this._req.socket.remoteAddress ||
109
+ this._req.ip || "";
110
+ ip = ip.replace("::ffff:", "");
111
+ return ip;
112
+ }
113
+ constructor(req, cfg) {
114
+ this._cfg = cfg;
115
+ this._req = req;
116
+ this._init();
117
+ }
118
+ getCookie(key) {
119
+ let cookie_key = this._cfg.cookie.prefix + key;
120
+ if (!this._req.cookies) {
121
+ return null;
122
+ }
123
+ return this._req.cookies[cookie_key];
124
+ }
125
+ _init() {
126
+ let path = this._req.url;
127
+ //服务器根目录路径写法,链接转换
128
+ let _i = path.lastIndexOf("~");
129
+ if (_i >= 0) {
130
+ path = path.substr(_i + 1);
131
+ }
132
+ //处理参数
133
+ this._parseParams(path);
134
+ }
135
+ _addListener(event, listener) {
136
+ this._req.addListener(event, listener);
137
+ }
138
+ _parseParams(path) {
139
+ this._module = this._cfg.routs.onlyModule || this._cfg.routs.defaults.module;
140
+ this._controller = this._cfg.routs.defaults.controller;
141
+ this._action = this._cfg.routs.defaults.action;
142
+ this._suffix = null;
143
+ this._file_url = null;
144
+ this._params = {};
145
+ if (path == "/") {
146
+ return;
147
+ }
148
+ let firstQuoteIndex = path.indexOf("?");
149
+ let preQuoteStr = path;
150
+ if (firstQuoteIndex > 0) {
151
+ preQuoteStr = path.substring(0, firstQuoteIndex);
152
+ }
153
+ let lastDotIndex = preQuoteStr.lastIndexOf(".");
154
+ if (lastDotIndex > 0) {
155
+ let dotStr = preQuoteStr.substring(lastDotIndex + 1);
156
+ this._suffix = dotStr;
157
+ this._file_url = preQuoteStr;
158
+ return;
159
+ }
160
+ let quote_index = path.indexOf("?");
161
+ if (quote_index >= 0) {
162
+ let url = new url_1.URL(path);
163
+ url.searchParams.forEach((value, name, searchParams) => {
164
+ this._params[name] = value;
165
+ });
166
+ path = path.substring(0, quote_index);
167
+ }
168
+ let params = path.split("/");
169
+ let default_module = false;
170
+ if (this._cfg.routs.onlyModule) {
171
+ default_module = true;
172
+ }
173
+ if (params.length > 1 && params[1].length > 0) {
174
+ /**
175
+ * 如果是only模式,那么就不支持controller和module相同,
176
+ * 如果相同则认为是模块名,这样就可以同时支持,带模块的路径模式和非带模块的路径模式了
177
+ */
178
+ if (default_module
179
+ && params[1].toLowerCase() == this._cfg.routs.onlyModule.toLowerCase()) {
180
+ default_module = false;
181
+ }
182
+ if (default_module) {
183
+ this._controller = params[1];
184
+ }
185
+ else {
186
+ this._module = params[1];
187
+ }
188
+ }
189
+ if (params.length > 2 && params[2].length > 0) {
190
+ if (default_module) {
191
+ this._action = params[2];
192
+ }
193
+ else {
194
+ this._controller = params[2];
195
+ }
196
+ }
197
+ if (params.length > 3
198
+ && params[3].length > 0
199
+ && !default_module) {
200
+ this._action = params[3];
201
+ }
202
+ this._params = this._params || {};
203
+ return;
204
+ }
205
+ getDebugInfo() {
206
+ let debuginfo = {
207
+ module: this._module,
208
+ controller: this._controller,
209
+ action: this._action,
210
+ suffix: this._suffix,
211
+ file_url: this._file_url,
212
+ params: this._params,
213
+ post: this.postData,
214
+ method: this._req.method.toLowerCase()
215
+ };
216
+ return debuginfo;
217
+ }
218
+ debugInfo(force = false) {
219
+ if (!this._cfg.debug && !force) {
220
+ return;
221
+ }
222
+ let debuginfo = this.getDebugInfo();
223
+ Log_1.gLog.info(debuginfo);
224
+ }
225
+ }
226
+ exports.Request = Request;
@@ -1,87 +1,120 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Response = void 0;
4
- const fs = require("fs");
5
- const mime = require("mime");
6
- const Log_1 = require("../../../Logic/Log");
7
- class Response {
8
- _res = null;
9
- _cookie_prefix = "";
10
- _cfg = null;
11
- debug = false;
12
- get baseRes() {
13
- return this._res;
14
- }
15
- constructor(res, cfg) {
16
- this._cfg = cfg;
17
- this.debug = this._cfg.debug || false;
18
- this._res = res;
19
- this._cookie_prefix = this._cfg.cookie.prefix;
20
- }
21
- /**
22
- *
23
- * @param key
24
- * @param value
25
- * @param time 秒
26
- */
27
- setCookie(key, value, time) {
28
- key = this._cookie_prefix + key;
29
- if (time) {
30
- this._res.cookie(key, value, { maxAge: time * 1000, httpOnly: true });
31
- }
32
- else {
33
- this._res.cookie(key, value, { httpOnly: true });
34
- }
35
- }
36
- clearCookie(key) {
37
- this.setCookie(key, "", -1000);
38
- }
39
- redirect(path) {
40
- this._res.writeHead(302, { 'Location': path });
41
- this._res.end();
42
- }
43
- render(data) {
44
- return this._res.send(data);
45
- }
46
- renderJson(data) {
47
- this.debugInfo(data);
48
- return this._res.json(data);
49
- }
50
- sendStatus(status) {
51
- this.debugInfo(status);
52
- this._res.sendStatus(status);
53
- }
54
- renderHtml(html) {
55
- return this._res.send(html || "");
56
- }
57
- renderFile(fullPath) {
58
- this._res.sendFile(fullPath);
59
- }
60
- downloadFile(fullPath) {
61
- let fileName = "";
62
- let quote_index = fullPath.indexOf("/");
63
- if (quote_index > 0) {
64
- fileName = fullPath.substring(quote_index + 1);
65
- }
66
- fs.stat(fullPath, (err, stats) => {
67
- if (!stats || stats.isDirectory()) {
68
- return this.sendStatus(404);
69
- }
70
- let size = stats.size;
71
- var f = fs.createReadStream(fullPath);
72
- this._res.writeHead(200, {
73
- 'Content-Type': mime.getType(fullPath) || 'application/octet-stream',
74
- 'Content-Disposition': 'attachment; filename=' + fileName,
75
- 'Content-Length': size
76
- });
77
- f.pipe(this._res);
78
- });
79
- }
80
- debugInfo(data) {
81
- if (!this.debug) {
82
- return;
83
- }
84
- Log_1.gLog.info(data);
85
- }
86
- }
87
- exports.Response = Response;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.Response = void 0;
37
+ const fs = __importStar(require("fs"));
38
+ const mime = __importStar(require("mime"));
39
+ const Log_1 = require("../../../Logic/Log");
40
+ class Response {
41
+ _res = null;
42
+ _cookie_prefix = "";
43
+ _cfg = null;
44
+ debug = false;
45
+ get baseRes() {
46
+ return this._res;
47
+ }
48
+ constructor(res, cfg) {
49
+ this._cfg = cfg;
50
+ this.debug = this._cfg.debug || false;
51
+ this._res = res;
52
+ this._cookie_prefix = this._cfg.cookie.prefix;
53
+ }
54
+ /**
55
+ *
56
+ * @param key
57
+ * @param value
58
+ * @param time 秒
59
+ */
60
+ setCookie(key, value, time) {
61
+ key = this._cookie_prefix + key;
62
+ if (time) {
63
+ this._res.cookie(key, value, { maxAge: time * 1000, httpOnly: true });
64
+ }
65
+ else {
66
+ this._res.cookie(key, value, { httpOnly: true });
67
+ }
68
+ }
69
+ clearCookie(key) {
70
+ this.setCookie(key, "", -1000);
71
+ }
72
+ redirect(path) {
73
+ this._res.writeHead(302, { 'Location': path });
74
+ this._res.end();
75
+ }
76
+ render(data) {
77
+ return this._res.send(data);
78
+ }
79
+ renderJson(data) {
80
+ this.debugInfo(data);
81
+ return this._res.json(data);
82
+ }
83
+ sendStatus(status) {
84
+ this.debugInfo(status);
85
+ this._res.sendStatus(status);
86
+ }
87
+ renderHtml(html) {
88
+ return this._res.send(html || "");
89
+ }
90
+ renderFile(fullPath) {
91
+ this._res.sendFile(fullPath);
92
+ }
93
+ downloadFile(fullPath) {
94
+ let fileName = "";
95
+ let quote_index = fullPath.indexOf("/");
96
+ if (quote_index > 0) {
97
+ fileName = fullPath.substring(quote_index + 1);
98
+ }
99
+ fs.stat(fullPath, (err, stats) => {
100
+ if (!stats || stats.isDirectory()) {
101
+ return this.sendStatus(404);
102
+ }
103
+ let size = stats.size;
104
+ var f = fs.createReadStream(fullPath);
105
+ this._res.writeHead(200, {
106
+ 'Content-Type': mime.getType(fullPath) || 'application/octet-stream',
107
+ 'Content-Disposition': 'attachment; filename=' + fileName,
108
+ 'Content-Length': size
109
+ });
110
+ f.pipe(this._res);
111
+ });
112
+ }
113
+ debugInfo(data) {
114
+ if (!this.debug) {
115
+ return;
116
+ }
117
+ Log_1.gLog.info(data);
118
+ }
119
+ }
120
+ exports.Response = Response;