cgserver 6.1.10 → 6.2.4

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.
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.core = void 0;
4
- let Md5 = require("md5");
5
4
  let os = require('os');
6
5
  let request = require('request');
7
6
  const _ = require("underscore");
7
+ const crypto = require("crypto");
8
8
  /**
9
9
  * 常用的工具函数类
10
10
  */
@@ -321,13 +321,14 @@ class core {
321
321
  newStr += last;
322
322
  return newStr;
323
323
  }
324
- static md5 = function (data) {
325
- let str = data;
326
- if (!core.isString(data)) {
327
- str = JSON.stringify(data);
328
- }
329
- return Md5(str);
330
- };
324
+ static md5(str) {
325
+ let md5_str = crypto.createHash('md5').update(str).digest('hex');
326
+ return md5_str;
327
+ }
328
+ static sha1(str) {
329
+ let sha1_str = crypto.createHash('sha1').update(str).digest('hex');
330
+ return sha1_str;
331
+ }
331
332
  static getLocalIP = function () {
332
333
  let iptable = {};
333
334
  let ifaces = os.networkInterfaces();
@@ -72,7 +72,7 @@ class BaseService {
72
72
  return rs;
73
73
  }
74
74
  aggregate(pipeline, options) {
75
- let ret = MongoManager_1.GMongoMgr.aggregate(this._table);
75
+ let ret = MongoManager_1.GMongoMgr.aggregate(this._table, pipeline, options);
76
76
  return ret;
77
77
  }
78
78
  }
@@ -133,12 +133,7 @@ class MongoManager {
133
133
  let one = null;
134
134
  try {
135
135
  let col = this._mongo.collection(collection);
136
- if (!sort) {
137
- one = await col.findOne(where, property);
138
- }
139
- else {
140
- one = await (col.find(where, property).sort(sort).limit(1).next());
141
- }
136
+ one = await col.findOne(where, { projection: property });
142
137
  }
143
138
  catch (e) {
144
139
  Log_1.GLog.error(e.stack);
@@ -99,7 +99,7 @@ class IWebSocket {
99
99
  }
100
100
  }
101
101
  catch (e) {
102
- Log_1.GLog.error('Received Message Handle Error: ' + e);
102
+ Log_1.GLog.error(this.tipKey + ' Received Message Handle Error: ' + e);
103
103
  }
104
104
  }
105
105
  _onDecode(message, ...params) {
@@ -135,11 +135,11 @@ class IWebSocket {
135
135
  && jsonData
136
136
  && jsonData.cmd != "heartbeat") {
137
137
  Log_1.GLog.info(this.tipKey + " receive:--------", true);
138
- Log_1.GLog.info(jsonData, true);
138
+ Log_1.GLog.info({ tipKey: this.tipKey, jsonData }, true);
139
139
  }
140
140
  if (!jsonData.cmd || jsonData.cmd == "") {
141
- Log_1.GLog.error('Received Message warning: no cmd param,data=');
142
- Log_1.GLog.error(jsonData);
141
+ Log_1.GLog.error(this.tipKey + ' Received Message warning: no cmd param,data=');
142
+ Log_1.GLog.error({ tipKey: this.tipKey, jsonData });
143
143
  return false;
144
144
  }
145
145
  return true;
@@ -156,16 +156,11 @@ class IWebSocket {
156
156
  await this["receive_other_all"](jsonData); //默认支持其他所有处理消息
157
157
  }
158
158
  catch (e) {
159
- if (e && e.stack) {
160
- Log_1.GLog.error(e.stack);
161
- }
162
- else {
163
- Log_1.GLog.error(e + " msg:data=" + JSON.stringify(jsonData));
164
- }
159
+ Log_1.GLog.error(this.tipKey + e.stack);
165
160
  }
166
161
  }
167
162
  else {
168
- Log_1.GLog.error('Received Message warning: no cmd handle,cmd=' + jsonData.cmd);
163
+ Log_1.GLog.error(this.tipKey + ' Received Message warning: no cmd handle,cmd=' + jsonData.cmd);
169
164
  }
170
165
  }
171
166
  else {
@@ -173,35 +168,30 @@ class IWebSocket {
173
168
  await this["receive_" + jsonData.cmd](jsonData);
174
169
  }
175
170
  catch (e) {
176
- if (e && e.stack) {
177
- Log_1.GLog.error("error msg:data=" + JSON.stringify(jsonData) + "\n" + e.stack);
178
- }
179
- else {
180
- Log_1.GLog.error(e + " msg:data=" + JSON.stringify(jsonData));
181
- }
171
+ Log_1.GLog.error(this.tipKey + " error msg:data=" + JSON.stringify(jsonData) + "\n" + e.stack);
182
172
  }
183
173
  }
184
174
  }
185
175
  onOpen(e) {
186
176
  }
187
177
  onError(e) {
188
- Log_1.GLog.info("onError:" + e.message);
178
+ Log_1.GLog.info(this.tipKey + " onError:" + e.message);
189
179
  }
190
180
  onClose(reasonCode, description) {
191
- Log_1.GLog.info("onClose resonCode=" + reasonCode + " des=" + description);
181
+ Log_1.GLog.info(this.tipKey + " onClose resonCode=" + reasonCode + " des=" + description);
192
182
  }
193
183
  send(data) {
194
184
  if (!this.connected) {
195
185
  return;
196
186
  }
197
187
  if (!data) {
198
- Log_1.GLog.error("Send Message warning:null data!");
188
+ Log_1.GLog.error(this.tipKey + " Send Message warning:null data!");
199
189
  return;
200
190
  }
201
191
  if (this._debug_msg
202
192
  && data.cmd != "heartbeat") {
203
193
  Log_1.GLog.info(this.tipKey + " send:-----------------------------------", true);
204
- Log_1.GLog.info(data, true);
194
+ Log_1.GLog.info({ tipKey: this.tipKey, data }, true);
205
195
  }
206
196
  let msg = this._onEncode(data);
207
197
  this._ws.send(msg);
@@ -38,7 +38,8 @@ export declare class core {
38
38
  * @param str
39
39
  */
40
40
  static fuzzy(str: string): string;
41
- static md5: (data: any) => any;
41
+ static md5(str: string): string;
42
+ static sha1(str: string): string;
42
43
  static getLocalIP: () => any;
43
44
  static getIP: () => Promise<string>;
44
45
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cgserver",
3
- "version": "6.1.10",
3
+ "version": "6.2.4",
4
4
  "author": "trojan",
5
5
  "type": "commonjs",
6
6
  "description": "free for all.Websocket or Http",
@@ -35,7 +35,6 @@
35
35
  "@types/cors": "^2.8.12",
36
36
  "@types/express": "^4.17.13",
37
37
  "@types/formidable": "^2.0.0",
38
- "@types/md5": "^2.3.1",
39
38
  "@types/mime": "^2.0.3",
40
39
  "@types/mssql": "^7.1.5",
41
40
  "@types/mysql": "^2.15.19",
@@ -61,7 +60,6 @@
61
60
  "https": "^1.0.0",
62
61
  "jsonc": "^2.0.0",
63
62
  "log4js": "^6.3.0",
64
- "md5": "^2.3.0",
65
63
  "mime": "^3.0.0",
66
64
  "mongodb": "^4.2.1",
67
65
  "mssql": "^8.0.2",
@@ -80,7 +78,5 @@
80
78
  "webpack": "^5.73.0",
81
79
  "webpack-node-externals": "^3.0.0",
82
80
  "websocket": "^1.0.34"
83
- },
84
- "devDependencies": {
85
81
  }
86
82
  }