cgserver 7.2.686 → 7.3.1434
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.
package/dist/lib/Core/Core.js
CHANGED
|
@@ -6,6 +6,7 @@ let request = require('request');
|
|
|
6
6
|
const _ = require("underscore");
|
|
7
7
|
const crypto = require("crypto");
|
|
8
8
|
const Log_1 = require("../Logic/Log");
|
|
9
|
+
const CryptoJS = require("crypto-js");
|
|
9
10
|
/**
|
|
10
11
|
* 常用的工具函数类
|
|
11
12
|
*/
|
|
@@ -600,5 +601,39 @@ class core {
|
|
|
600
601
|
return { errcode: { id: 1008613, des: "failed" } };
|
|
601
602
|
}
|
|
602
603
|
}
|
|
604
|
+
//判断当前日期为当年第几周
|
|
605
|
+
static getYearWeek(time) {
|
|
606
|
+
//date1是当前日期
|
|
607
|
+
//date2是当年第一天
|
|
608
|
+
//d是当前日期是今年第多少天
|
|
609
|
+
//用d + 当前年的第一天的周差距的和在除以7就是本年第几周
|
|
610
|
+
let tar = new Date(time);
|
|
611
|
+
let start = new Date(tar.getFullYear(), 0, 1);
|
|
612
|
+
let days = Math.round((tar.valueOf() - start.valueOf()) / 86400000);
|
|
613
|
+
return Math.ceil((days + ((start.getDay() + 1) - 1)) / 7);
|
|
614
|
+
}
|
|
615
|
+
static toBase64(content) {
|
|
616
|
+
var wordArray = CryptoJS.enc.Hex.parse(content);
|
|
617
|
+
var base64Str = CryptoJS.enc.Base64.stringify(wordArray);
|
|
618
|
+
return base64Str;
|
|
619
|
+
}
|
|
620
|
+
static aesEncode(content, key, iv) {
|
|
621
|
+
let _iv = CryptoJS.enc.Utf8.parse(iv);
|
|
622
|
+
let etext = CryptoJS.AES.encrypt(content, key, {
|
|
623
|
+
iv: _iv,
|
|
624
|
+
mode: CryptoJS.mode.CBC,
|
|
625
|
+
padding: CryptoJS.pad.Pkcs7
|
|
626
|
+
}).toString();
|
|
627
|
+
return etext;
|
|
628
|
+
}
|
|
629
|
+
static aesDecode(base64_str, key, iv) {
|
|
630
|
+
let _iv = CryptoJS.enc.Utf8.parse(iv);
|
|
631
|
+
let dtext = CryptoJS.AES.decrypt(base64_str, key, {
|
|
632
|
+
iv: _iv,
|
|
633
|
+
mode: CryptoJS.mode.CBC,
|
|
634
|
+
padding: CryptoJS.pad.Pkcs7
|
|
635
|
+
}).toString(CryptoJS.enc.Utf8);
|
|
636
|
+
return dtext;
|
|
637
|
+
}
|
|
603
638
|
}
|
|
604
639
|
exports.core = core;
|
|
@@ -75,5 +75,40 @@ class MongoBaseService {
|
|
|
75
75
|
let ret = MongoManager_1.GMongoMgr.aggregate(this._table, pipeline, options);
|
|
76
76
|
return ret;
|
|
77
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* 仅仅支持一级
|
|
80
|
+
* @param array 数据名称 比如 items
|
|
81
|
+
* @param where 数组内赛选条件 比如 "items.id":1
|
|
82
|
+
* @param pre_match 数组上一级赛选条件 比如 "user_id":1
|
|
83
|
+
*/
|
|
84
|
+
async getsInArray(array, where, pre_match) {
|
|
85
|
+
let agg = this.aggregate();
|
|
86
|
+
if (pre_match) {
|
|
87
|
+
agg = agg.match(pre_match);
|
|
88
|
+
}
|
|
89
|
+
agg = agg.unwind("$" + array);
|
|
90
|
+
if (where) {
|
|
91
|
+
agg = agg.match(where);
|
|
92
|
+
}
|
|
93
|
+
let all = await agg.toArray();
|
|
94
|
+
let items = [];
|
|
95
|
+
for (let i = 0; i < all.length; ++i) {
|
|
96
|
+
items.push(all[i][array]);
|
|
97
|
+
}
|
|
98
|
+
return items;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 仅仅支持一级
|
|
102
|
+
* @param array 数据名称 比如 items
|
|
103
|
+
* @param where 数组内赛选条件 比如 "items.id":1
|
|
104
|
+
* @param pre_match 数组上一级赛选条件 比如 "user_id":1
|
|
105
|
+
*/
|
|
106
|
+
async getInArray(array, where, pre_match) {
|
|
107
|
+
let items = await this.getsInArray(array, where, pre_match);
|
|
108
|
+
if (items.length <= 0) {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
return items[0];
|
|
112
|
+
}
|
|
78
113
|
}
|
|
79
114
|
exports.MongoBaseService = MongoBaseService;
|
|
@@ -4,12 +4,12 @@ exports.GHttpTool = void 0;
|
|
|
4
4
|
const request = require("request");
|
|
5
5
|
const qs = require("querystring");
|
|
6
6
|
const Log_1 = require("./Log");
|
|
7
|
-
const
|
|
7
|
+
const Core_1 = require("../Core/Core");
|
|
8
8
|
exports.GHttpTool = null;
|
|
9
9
|
class HttpTool {
|
|
10
10
|
get(options_url) {
|
|
11
11
|
let options = null;
|
|
12
|
-
if (
|
|
12
|
+
if (Core_1.core.isString(options_url)) {
|
|
13
13
|
options = { url: options_url };
|
|
14
14
|
}
|
|
15
15
|
else {
|
|
@@ -23,7 +23,7 @@ class HttpTool {
|
|
|
23
23
|
Log_1.GLog.error(error);
|
|
24
24
|
}
|
|
25
25
|
try {
|
|
26
|
-
if (
|
|
26
|
+
if (Core_1.core.isString(body)) {
|
|
27
27
|
body = JSON.parse(body);
|
|
28
28
|
}
|
|
29
29
|
}
|
|
@@ -41,7 +41,7 @@ class HttpTool {
|
|
|
41
41
|
}
|
|
42
42
|
post(options_url) {
|
|
43
43
|
let options = null;
|
|
44
|
-
if (
|
|
44
|
+
if (Core_1.core.isString(options_url)) {
|
|
45
45
|
options = { url: options_url };
|
|
46
46
|
}
|
|
47
47
|
else {
|
|
@@ -55,7 +55,7 @@ class HttpTool {
|
|
|
55
55
|
Log_1.GLog.error(error);
|
|
56
56
|
}
|
|
57
57
|
try {
|
|
58
|
-
if (
|
|
58
|
+
if (Core_1.core.isString(body)) {
|
|
59
59
|
body = JSON.parse(body);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -101,4 +101,8 @@ export declare class core {
|
|
|
101
101
|
static convertToGlobalStr(num: number): string;
|
|
102
102
|
static sleep(milliseconds: number): Promise<unknown>;
|
|
103
103
|
static safeCall(func: Function, thisArg?: any, ...params: any[]): Promise<any>;
|
|
104
|
+
static getYearWeek(time: number): number;
|
|
105
|
+
static toBase64(content: string): string;
|
|
106
|
+
static aesEncode(content: string, key: string, iv: string): string;
|
|
107
|
+
static aesDecode(base64_str: string, key: string, iv: string): string;
|
|
104
108
|
}
|
|
@@ -64,4 +64,18 @@ export declare class MongoBaseService<T> {
|
|
|
64
64
|
rs: string;
|
|
65
65
|
}>;
|
|
66
66
|
aggregate(pipeline?: Document[], options?: mongo.AggregateOptions): mongo.AggregationCursor<mongo.Document>;
|
|
67
|
+
/**
|
|
68
|
+
* 仅仅支持一级
|
|
69
|
+
* @param array 数据名称 比如 items
|
|
70
|
+
* @param where 数组内赛选条件 比如 "items.id":1
|
|
71
|
+
* @param pre_match 数组上一级赛选条件 比如 "user_id":1
|
|
72
|
+
*/
|
|
73
|
+
getsInArray<T>(array: string, where?: any, pre_match?: any): Promise<T[]>;
|
|
74
|
+
/**
|
|
75
|
+
* 仅仅支持一级
|
|
76
|
+
* @param array 数据名称 比如 items
|
|
77
|
+
* @param where 数组内赛选条件 比如 "items.id":1
|
|
78
|
+
* @param pre_match 数组上一级赛选条件 比如 "user_id":1
|
|
79
|
+
*/
|
|
80
|
+
getInArray<T>(array: string, where?: any, pre_match?: any): Promise<T>;
|
|
67
81
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cgserver",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.1434",
|
|
4
4
|
"author": "trojan",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"description": "free for all.Websocket or Http",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"@alicloud/sms-sdk": "^1.1.6",
|
|
34
34
|
"@types/cookie-parser": "^1.4.2",
|
|
35
35
|
"@types/cors": "^2.8.12",
|
|
36
|
+
"@types/crypto-js": "^4.1.1",
|
|
36
37
|
"@types/express": "^4.17.13",
|
|
37
38
|
"@types/formidable": "^2.0.0",
|
|
38
39
|
"@types/mime": "^2.0.3",
|
|
@@ -48,10 +49,10 @@
|
|
|
48
49
|
"@types/websocket": "^1.0.4",
|
|
49
50
|
"alipay_sdk2": "^1.1.6",
|
|
50
51
|
"alipay-sdk": "^3.1.7",
|
|
51
|
-
"cgserver": "^6.9.468",
|
|
52
52
|
"colors": "^1.4.0",
|
|
53
53
|
"cookie-parser": "^1.4.5",
|
|
54
54
|
"cors": "^2.8.5",
|
|
55
|
+
"crypto-js": "^4.1.1",
|
|
55
56
|
"ec-key": "0.0.4",
|
|
56
57
|
"express": "^4.17.1",
|
|
57
58
|
"fast-xml-parser": "^3.21.1",
|