abler-api 0.1.26 → 0.1.27
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/cjs/pp-util.js +36 -115
- package/dist/es/pp-util.js +33 -113
- package/package.json +1 -1
package/dist/cjs/pp-util.js
CHANGED
|
@@ -1,23 +1,25 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var require$$0
|
|
3
|
+
var require$$0 = require('crypto');
|
|
4
4
|
var require$$1 = require('abler-util');
|
|
5
5
|
var require$$2 = require('abler-db');
|
|
6
6
|
var require$$3 = require('abler-net');
|
|
7
|
-
var require$$0$
|
|
7
|
+
var require$$0$1 = require('fs');
|
|
8
8
|
var require$$1$1 = require('path');
|
|
9
|
+
var require$$1$2 = require('abler-messenger');
|
|
9
10
|
|
|
10
11
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
12
|
|
|
12
|
-
var require$$0__default
|
|
13
|
+
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0);
|
|
13
14
|
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
14
15
|
var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
|
|
15
16
|
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
|
|
16
|
-
var require$$0__default$
|
|
17
|
+
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
17
18
|
var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
|
|
19
|
+
var require$$1__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$1$2);
|
|
18
20
|
|
|
19
|
-
const crypto = require$$0__default
|
|
20
|
-
const ppUtil$
|
|
21
|
+
const crypto = require$$0__default["default"];
|
|
22
|
+
const ppUtil$3 = require$$1__default["default"].ppUtil;
|
|
21
23
|
const {
|
|
22
24
|
dbUtil,
|
|
23
25
|
kvStorage
|
|
@@ -31,17 +33,17 @@ const pnToken = "access_token",
|
|
|
31
33
|
// 我们接收到的 headers 中的字段名总是全小写的
|
|
32
34
|
pnApiSecret = "apiSecret",
|
|
33
35
|
hnApiSecret = pnApiSecret.toLowerCase();
|
|
34
|
-
const MD5 = ppUtil$
|
|
35
|
-
moveProperty = ppUtil$
|
|
36
|
+
const MD5 = ppUtil$3.MD5,
|
|
37
|
+
moveProperty = ppUtil$3.moveProperty;
|
|
36
38
|
|
|
37
39
|
class apiUtil$1 {
|
|
38
|
-
static debugFlag = ppUtil$
|
|
40
|
+
static debugFlag = ppUtil$3.newGuid(); //应用必须设置,否则谁也不知道是啥
|
|
39
41
|
|
|
40
|
-
static testFlag = ppUtil$
|
|
42
|
+
static testFlag = ppUtil$3.newGuid();
|
|
41
43
|
static envId_dev = "?"; // static apiCallRecSaver;
|
|
42
44
|
|
|
43
45
|
static config(appConfig, appErrCfg, appDbSql) {
|
|
44
|
-
ppUtil$
|
|
46
|
+
ppUtil$3.config(appConfig, appErrCfg);
|
|
45
47
|
conf$2 = appConfig;
|
|
46
48
|
appSetting$1 = conf$2?.appSetting;
|
|
47
49
|
err$1 = appErrCfg, dbSql = appDbSql;
|
|
@@ -57,7 +59,7 @@ class apiUtil$1 {
|
|
|
57
59
|
|
|
58
60
|
|
|
59
61
|
static _getApiSecret(companyId) {
|
|
60
|
-
return ppUtil$
|
|
62
|
+
return ppUtil$3.newGuid();
|
|
61
63
|
}
|
|
62
64
|
/**
|
|
63
65
|
* 保存 API 调用记录,应用系统必须重写此方法
|
|
@@ -160,7 +162,7 @@ class apiUtil$1 {
|
|
|
160
162
|
|
|
161
163
|
|
|
162
164
|
static setParamsFunctions(params) {
|
|
163
|
-
ppUtil$
|
|
165
|
+
ppUtil$3.defUnenumProp(params, "asNumber", function (name, minValue, maxValue, defaultValue) {
|
|
164
166
|
// if (!this.hasOwnProperty(name)) // {} 定义的对象没有 hasOwnProperty 函数
|
|
165
167
|
if (this[name] === undefined) return defaultValue;
|
|
166
168
|
let result = +this[name];
|
|
@@ -171,7 +173,7 @@ class apiUtil$1 {
|
|
|
171
173
|
|
|
172
174
|
return result;
|
|
173
175
|
});
|
|
174
|
-
ppUtil$
|
|
176
|
+
ppUtil$3.defUnenumProp(params, "asBool", function (name, defaultValue) {
|
|
175
177
|
if (this[name] === undefined) return defaultValue;
|
|
176
178
|
let result = JSON.parse(this[name]);
|
|
177
179
|
return !!result;
|
|
@@ -236,7 +238,7 @@ class apiUtil$1 {
|
|
|
236
238
|
|
|
237
239
|
static apiFail(error, req) {
|
|
238
240
|
configNeeded();
|
|
239
|
-
let response = err$1.ERROR(error, err$1.errorLangParamFlag + ppUtil$
|
|
241
|
+
let response = err$1.ERROR(error, err$1.errorLangParamFlag + ppUtil$3.getMsgLang(req));
|
|
240
242
|
response.datetime = new Date();
|
|
241
243
|
|
|
242
244
|
if (req && req.headers) {
|
|
@@ -484,7 +486,7 @@ class apiUtil$1 {
|
|
|
484
486
|
const params = apiUtil$1.extractParams(req);
|
|
485
487
|
req.accessToken = req.accessToken || apiUtil$1.extractToken(req);
|
|
486
488
|
|
|
487
|
-
if (req.accessToken === MD5(ppUtil$
|
|
489
|
+
if (req.accessToken === MD5(ppUtil$3.idNumDisturbing)) {
|
|
488
490
|
//todo: 检查IP
|
|
489
491
|
params.__internal__ = true;
|
|
490
492
|
req.ignoreToken = true; // if (params.idNum || params.personId) {
|
|
@@ -541,7 +543,7 @@ class apiUtil$1 {
|
|
|
541
543
|
|
|
542
544
|
if (dbgToken) {
|
|
543
545
|
let envId = process.env.ECS_DEPLOY_ID;
|
|
544
|
-
req.__debug__ = dbgToken && dbgToken === MD5(req.headers.timestamp, ppUtil$
|
|
546
|
+
req.__debug__ = dbgToken && dbgToken === MD5(req.headers.timestamp, ppUtil$3.commonHashDisturbing) && (envId === "florist_longdan" || envId === "shuzi");
|
|
545
547
|
} else {
|
|
546
548
|
req.__debug__ = false;
|
|
547
549
|
} // console.log("__debug__:", req.__debug__, "dbgToken:", dbgToken);
|
|
@@ -721,7 +723,7 @@ class apiUtil$1 {
|
|
|
721
723
|
};
|
|
722
724
|
|
|
723
725
|
if (rec.secret !== "") {
|
|
724
|
-
rec.secret = ppUtil$
|
|
726
|
+
rec.secret = ppUtil$3.getEncAse192(rec.secret);
|
|
725
727
|
}
|
|
726
728
|
|
|
727
729
|
req.apiCallRec = rec;
|
|
@@ -1021,7 +1023,7 @@ class apiUtil$1 {
|
|
|
1021
1023
|
paramExists = typeof params[paramName] != 'undefined' || typeof params[paramName + paramSufix] != 'undefined';
|
|
1022
1024
|
}
|
|
1023
1025
|
|
|
1024
|
-
if (!paramExists) return ppUtil$
|
|
1026
|
+
if (!paramExists) return ppUtil$3.errorPormise(err$1.ERROR(err$1.PARAMETER_NEEDED, paramName));
|
|
1025
1027
|
}
|
|
1026
1028
|
|
|
1027
1029
|
return Promise.resolve(paramSufix);
|
|
@@ -1070,7 +1072,7 @@ class apiUtil$1 {
|
|
|
1070
1072
|
|
|
1071
1073
|
static async hostIsMySelf(host, req) {
|
|
1072
1074
|
let clientIp = apiUtil$1.getClientIp(req);
|
|
1073
|
-
return ppUtil$
|
|
1075
|
+
return ppUtil$3.getMyIp({
|
|
1074
1076
|
hosts: [host, clientIp]
|
|
1075
1077
|
});
|
|
1076
1078
|
}
|
|
@@ -1085,7 +1087,7 @@ class apiUtil$1 {
|
|
|
1085
1087
|
configNeeded();
|
|
1086
1088
|
const params = options.replacements;
|
|
1087
1089
|
const myEnvHosts = apiUtil$1.getEnvHosts(params);
|
|
1088
|
-
const myIp = ppUtil$
|
|
1090
|
+
const myIp = ppUtil$3.getMyIp();
|
|
1089
1091
|
const host = params.host || myIp;
|
|
1090
1092
|
if (!myEnvHosts.hosts.contains(host)) throw [err$1.ACCESS_REFUSED, `环境${conf$2.envId}貌似无此主机:${params.host}`];
|
|
1091
1093
|
|
|
@@ -1387,7 +1389,7 @@ class apiUtil$1 {
|
|
|
1387
1389
|
if (await apiUtil$1.checkForwardsHost(options)) return true;
|
|
1388
1390
|
let c = apiUtil$1.parseCfgPath(item);
|
|
1389
1391
|
delete c.parent;
|
|
1390
|
-
c.host = ppUtil$
|
|
1392
|
+
c.host = ppUtil$3.getMyIp();
|
|
1391
1393
|
return c;
|
|
1392
1394
|
}
|
|
1393
1395
|
/**
|
|
@@ -1415,7 +1417,7 @@ class apiUtil$1 {
|
|
|
1415
1417
|
c.newValue = params.value;
|
|
1416
1418
|
c.parent[c.key] = c.newValue;
|
|
1417
1419
|
delete c.parent;
|
|
1418
|
-
c.host = ppUtil$
|
|
1420
|
+
c.host = ppUtil$3.getMyIp();
|
|
1419
1421
|
return c; // 应用层自行处理多机同步
|
|
1420
1422
|
} //#endregion
|
|
1421
1423
|
|
|
@@ -1424,18 +1426,18 @@ class apiUtil$1 {
|
|
|
1424
1426
|
|
|
1425
1427
|
function configNeeded() {
|
|
1426
1428
|
if (!conf$2 || !err$1) {
|
|
1427
|
-
ppUtil$
|
|
1428
|
-
conf$2 = ppUtil$
|
|
1429
|
+
ppUtil$3.configNeeded();
|
|
1430
|
+
conf$2 = ppUtil$3.appConfig;
|
|
1429
1431
|
appSetting$1 = conf$2.appSetting;
|
|
1430
|
-
err$1 = ppUtil$
|
|
1432
|
+
err$1 = ppUtil$3.appErrCfg;
|
|
1431
1433
|
}
|
|
1432
1434
|
}
|
|
1433
1435
|
|
|
1434
1436
|
var ppUtilApi = apiUtil$1;
|
|
1435
1437
|
|
|
1436
|
-
const fs = require$$0__default$
|
|
1438
|
+
const fs = require$$0__default$1["default"];
|
|
1437
1439
|
const path = require$$1__default$1["default"];
|
|
1438
|
-
const ppUtil$
|
|
1440
|
+
const ppUtil$2 = require$$1__default["default"].ppUtil;
|
|
1439
1441
|
const redisUtil = require$$2__default["default"].redisUtil;
|
|
1440
1442
|
let conf$1, err; // const dbCheck = require('../dbupdate/dd-version');
|
|
1441
1443
|
|
|
@@ -1456,9 +1458,9 @@ class preconditions$1 {
|
|
|
1456
1458
|
static checkPromises = [];
|
|
1457
1459
|
|
|
1458
1460
|
static setAppName(aName) {
|
|
1459
|
-
ppUtil$
|
|
1460
|
-
conf$1 = ppUtil$
|
|
1461
|
-
err = ppUtil$
|
|
1461
|
+
ppUtil$2.configNeeded();
|
|
1462
|
+
conf$1 = ppUtil$2.appConfig;
|
|
1463
|
+
err = ppUtil$2.appErrCfg;
|
|
1462
1464
|
preconditions$1.appName = aName || conf$1.thisApp;
|
|
1463
1465
|
return preconditions$1;
|
|
1464
1466
|
}
|
|
@@ -1538,7 +1540,7 @@ class preconditions$1 {
|
|
|
1538
1540
|
|
|
1539
1541
|
async function createEnvSettingFile(fileName) {
|
|
1540
1542
|
try {
|
|
1541
|
-
const cfgText = await ppUtil$
|
|
1543
|
+
const cfgText = await ppUtil$2.doCreateEnvSettingFile(fileName);
|
|
1542
1544
|
|
|
1543
1545
|
if (cfgText.indexOf(`cfgVersion: "${conf$1._envSetting.cfgVersion}"`) > 0) {
|
|
1544
1546
|
console.log(`\n*** 已創建新的本機環境配置文件\n${fileName}\n请檢查各項內容是否正确(此项更新服务可正常运行)\n\n`);
|
|
@@ -1583,7 +1585,7 @@ async function checkRedis() {
|
|
|
1583
1585
|
if (!conf$1.redis.enabled) return "";
|
|
1584
1586
|
const redis = redisUtil.newClient("io"); // console.log(`checkRedis begin:`);
|
|
1585
1587
|
|
|
1586
|
-
await ppUtil$
|
|
1588
|
+
await ppUtil$2.wait(15 * 1000, param => {
|
|
1587
1589
|
if (redis.ready && redis.connected || redis.error) {
|
|
1588
1590
|
return true;
|
|
1589
1591
|
}
|
|
@@ -1601,94 +1603,13 @@ async function checkRedis() {
|
|
|
1601
1603
|
|
|
1602
1604
|
var ppPrecond = preconditions$1;
|
|
1603
1605
|
|
|
1604
|
-
var require$$0 = require$$2__default["default"];
|
|
1605
|
-
|
|
1606
|
-
function _interopDefaultLegacy$1(e) {
|
|
1607
|
-
return e && typeof e === 'object' && 'default' in e ? e : {
|
|
1608
|
-
'default': e
|
|
1609
|
-
};
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy$1(require$$0); // const logger = require("log4js").getLogger();
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
const redis = require$$0__default["default"].redisUtil;
|
|
1616
|
-
|
|
1617
|
-
class Messenger {
|
|
1618
|
-
constructor(appConfig, appErrCfg) {
|
|
1619
|
-
if (appConfig) {
|
|
1620
|
-
redis.config(appConfig, appErrCfg);
|
|
1621
|
-
}
|
|
1622
|
-
|
|
1623
|
-
this.channel = "ecs_messenger"; //default channel
|
|
1624
|
-
|
|
1625
|
-
this.publisher = redis.newClient("publisher");
|
|
1626
|
-
this.subscriber = redis.newClient("subscriber");
|
|
1627
|
-
this.subscriber.on("subscribe", function (channel, count) {
|
|
1628
|
-
console.log("chanel subscribed :", channel, count);
|
|
1629
|
-
});
|
|
1630
|
-
this.subscriber.on("message", this.handleMessage);
|
|
1631
|
-
}
|
|
1632
|
-
|
|
1633
|
-
setMessageHandle(handle, channel) {
|
|
1634
|
-
channel = channel || this.channel;
|
|
1635
|
-
Messenger.onmessage = Messenger.onmessage || {};
|
|
1636
|
-
Messenger.onmessage[channel] = Messenger.onmessage[channel] || [];
|
|
1637
|
-
const appMsgHandles = Messenger.onmessage[channel];
|
|
1638
|
-
|
|
1639
|
-
for (let i = 0; i < appMsgHandles.length; i++) {
|
|
1640
|
-
if (appMsgHandles[i] === handle) return this;
|
|
1641
|
-
}
|
|
1642
|
-
|
|
1643
|
-
appMsgHandles.push(handle);
|
|
1644
|
-
return this;
|
|
1645
|
-
}
|
|
1646
|
-
|
|
1647
|
-
subscribe(channel) {
|
|
1648
|
-
channel = channel || this.channel;
|
|
1649
|
-
this.subscriber.subscribe(channel);
|
|
1650
|
-
return this;
|
|
1651
|
-
}
|
|
1652
|
-
|
|
1653
|
-
async handleMessage(channel, message) {
|
|
1654
|
-
console.log(`通道[${channel}]收到订阅消息:`, message);
|
|
1655
|
-
let appMsgHandles = Messenger.onmessage[channel] || [];
|
|
1656
|
-
|
|
1657
|
-
for (let i = 0; i < appMsgHandles.length; i++) {
|
|
1658
|
-
const appMsgHandle = appMsgHandles[i];
|
|
1659
|
-
|
|
1660
|
-
try {
|
|
1661
|
-
let msgObj = JSON.parse(message); // await appMsgHandle(msgObj);
|
|
1662
|
-
|
|
1663
|
-
appMsgHandle(msgObj);
|
|
1664
|
-
} catch (e) {
|
|
1665
|
-
console.log(e);
|
|
1666
|
-
}
|
|
1667
|
-
}
|
|
1668
|
-
}
|
|
1669
|
-
|
|
1670
|
-
async publish(message, channel) {
|
|
1671
|
-
channel = channel || this.channel;
|
|
1672
|
-
let msgStr = typeof message === "object" ? JSON.stringify(message) : message.toString();
|
|
1673
|
-
console.log(`通道[${channel}]发布消息:`, message);
|
|
1674
|
-
await this.publisher.publish(channel, msgStr);
|
|
1675
|
-
return this;
|
|
1676
|
-
}
|
|
1677
|
-
|
|
1678
|
-
}
|
|
1679
|
-
|
|
1680
|
-
var ppMessenger$1 = Messenger;
|
|
1681
|
-
const ppMessenger = ppMessenger$1;
|
|
1682
|
-
var ppUtil$2 = ppMessenger;
|
|
1683
|
-
var ppUtil_1 = ppUtil$2;
|
|
1684
|
-
|
|
1685
1606
|
// 若 redis 可用,则使用基于 redis 的消息订阅发布系统
|
|
1686
1607
|
// 若 redis 不可用,则将消息转发到其它主机
|
|
1687
1608
|
|
|
1688
1609
|
const {
|
|
1689
1610
|
ppUtil: ppUtil$1
|
|
1690
1611
|
} = require$$1__default["default"];
|
|
1691
|
-
const RedisMessenger =
|
|
1612
|
+
const RedisMessenger = require$$1__default$2["default"];
|
|
1692
1613
|
const {
|
|
1693
1614
|
netUtil
|
|
1694
1615
|
} = require$$3__default["default"];
|
package/dist/es/pp-util.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import require$$0
|
|
1
|
+
import require$$0 from 'crypto';
|
|
2
2
|
import require$$1 from 'abler-util';
|
|
3
3
|
import require$$2 from 'abler-db';
|
|
4
4
|
import require$$3 from 'abler-net';
|
|
5
|
-
import require$$0$
|
|
5
|
+
import require$$0$1 from 'fs';
|
|
6
6
|
import require$$1$1 from 'path';
|
|
7
|
+
import require$$1$2 from 'abler-messenger';
|
|
7
8
|
|
|
8
|
-
const crypto = require$$0
|
|
9
|
-
const ppUtil$
|
|
9
|
+
const crypto = require$$0;
|
|
10
|
+
const ppUtil$3 = require$$1.ppUtil;
|
|
10
11
|
const {
|
|
11
12
|
dbUtil,
|
|
12
13
|
kvStorage
|
|
@@ -20,17 +21,17 @@ const pnToken = "access_token",
|
|
|
20
21
|
// 我们接收到的 headers 中的字段名总是全小写的
|
|
21
22
|
pnApiSecret = "apiSecret",
|
|
22
23
|
hnApiSecret = pnApiSecret.toLowerCase();
|
|
23
|
-
const MD5 = ppUtil$
|
|
24
|
-
moveProperty = ppUtil$
|
|
24
|
+
const MD5 = ppUtil$3.MD5,
|
|
25
|
+
moveProperty = ppUtil$3.moveProperty;
|
|
25
26
|
|
|
26
27
|
class apiUtil$1 {
|
|
27
|
-
static debugFlag = ppUtil$
|
|
28
|
+
static debugFlag = ppUtil$3.newGuid(); //应用必须设置,否则谁也不知道是啥
|
|
28
29
|
|
|
29
|
-
static testFlag = ppUtil$
|
|
30
|
+
static testFlag = ppUtil$3.newGuid();
|
|
30
31
|
static envId_dev = "?"; // static apiCallRecSaver;
|
|
31
32
|
|
|
32
33
|
static config(appConfig, appErrCfg, appDbSql) {
|
|
33
|
-
ppUtil$
|
|
34
|
+
ppUtil$3.config(appConfig, appErrCfg);
|
|
34
35
|
conf$2 = appConfig;
|
|
35
36
|
appSetting$1 = conf$2?.appSetting;
|
|
36
37
|
err$1 = appErrCfg, dbSql = appDbSql;
|
|
@@ -46,7 +47,7 @@ class apiUtil$1 {
|
|
|
46
47
|
|
|
47
48
|
|
|
48
49
|
static _getApiSecret(companyId) {
|
|
49
|
-
return ppUtil$
|
|
50
|
+
return ppUtil$3.newGuid();
|
|
50
51
|
}
|
|
51
52
|
/**
|
|
52
53
|
* 保存 API 调用记录,应用系统必须重写此方法
|
|
@@ -149,7 +150,7 @@ class apiUtil$1 {
|
|
|
149
150
|
|
|
150
151
|
|
|
151
152
|
static setParamsFunctions(params) {
|
|
152
|
-
ppUtil$
|
|
153
|
+
ppUtil$3.defUnenumProp(params, "asNumber", function (name, minValue, maxValue, defaultValue) {
|
|
153
154
|
// if (!this.hasOwnProperty(name)) // {} 定义的对象没有 hasOwnProperty 函数
|
|
154
155
|
if (this[name] === undefined) return defaultValue;
|
|
155
156
|
let result = +this[name];
|
|
@@ -160,7 +161,7 @@ class apiUtil$1 {
|
|
|
160
161
|
|
|
161
162
|
return result;
|
|
162
163
|
});
|
|
163
|
-
ppUtil$
|
|
164
|
+
ppUtil$3.defUnenumProp(params, "asBool", function (name, defaultValue) {
|
|
164
165
|
if (this[name] === undefined) return defaultValue;
|
|
165
166
|
let result = JSON.parse(this[name]);
|
|
166
167
|
return !!result;
|
|
@@ -225,7 +226,7 @@ class apiUtil$1 {
|
|
|
225
226
|
|
|
226
227
|
static apiFail(error, req) {
|
|
227
228
|
configNeeded();
|
|
228
|
-
let response = err$1.ERROR(error, err$1.errorLangParamFlag + ppUtil$
|
|
229
|
+
let response = err$1.ERROR(error, err$1.errorLangParamFlag + ppUtil$3.getMsgLang(req));
|
|
229
230
|
response.datetime = new Date();
|
|
230
231
|
|
|
231
232
|
if (req && req.headers) {
|
|
@@ -473,7 +474,7 @@ class apiUtil$1 {
|
|
|
473
474
|
const params = apiUtil$1.extractParams(req);
|
|
474
475
|
req.accessToken = req.accessToken || apiUtil$1.extractToken(req);
|
|
475
476
|
|
|
476
|
-
if (req.accessToken === MD5(ppUtil$
|
|
477
|
+
if (req.accessToken === MD5(ppUtil$3.idNumDisturbing)) {
|
|
477
478
|
//todo: 检查IP
|
|
478
479
|
params.__internal__ = true;
|
|
479
480
|
req.ignoreToken = true; // if (params.idNum || params.personId) {
|
|
@@ -530,7 +531,7 @@ class apiUtil$1 {
|
|
|
530
531
|
|
|
531
532
|
if (dbgToken) {
|
|
532
533
|
let envId = process.env.ECS_DEPLOY_ID;
|
|
533
|
-
req.__debug__ = dbgToken && dbgToken === MD5(req.headers.timestamp, ppUtil$
|
|
534
|
+
req.__debug__ = dbgToken && dbgToken === MD5(req.headers.timestamp, ppUtil$3.commonHashDisturbing) && (envId === "florist_longdan" || envId === "shuzi");
|
|
534
535
|
} else {
|
|
535
536
|
req.__debug__ = false;
|
|
536
537
|
} // console.log("__debug__:", req.__debug__, "dbgToken:", dbgToken);
|
|
@@ -710,7 +711,7 @@ class apiUtil$1 {
|
|
|
710
711
|
};
|
|
711
712
|
|
|
712
713
|
if (rec.secret !== "") {
|
|
713
|
-
rec.secret = ppUtil$
|
|
714
|
+
rec.secret = ppUtil$3.getEncAse192(rec.secret);
|
|
714
715
|
}
|
|
715
716
|
|
|
716
717
|
req.apiCallRec = rec;
|
|
@@ -1010,7 +1011,7 @@ class apiUtil$1 {
|
|
|
1010
1011
|
paramExists = typeof params[paramName] != 'undefined' || typeof params[paramName + paramSufix] != 'undefined';
|
|
1011
1012
|
}
|
|
1012
1013
|
|
|
1013
|
-
if (!paramExists) return ppUtil$
|
|
1014
|
+
if (!paramExists) return ppUtil$3.errorPormise(err$1.ERROR(err$1.PARAMETER_NEEDED, paramName));
|
|
1014
1015
|
}
|
|
1015
1016
|
|
|
1016
1017
|
return Promise.resolve(paramSufix);
|
|
@@ -1059,7 +1060,7 @@ class apiUtil$1 {
|
|
|
1059
1060
|
|
|
1060
1061
|
static async hostIsMySelf(host, req) {
|
|
1061
1062
|
let clientIp = apiUtil$1.getClientIp(req);
|
|
1062
|
-
return ppUtil$
|
|
1063
|
+
return ppUtil$3.getMyIp({
|
|
1063
1064
|
hosts: [host, clientIp]
|
|
1064
1065
|
});
|
|
1065
1066
|
}
|
|
@@ -1074,7 +1075,7 @@ class apiUtil$1 {
|
|
|
1074
1075
|
configNeeded();
|
|
1075
1076
|
const params = options.replacements;
|
|
1076
1077
|
const myEnvHosts = apiUtil$1.getEnvHosts(params);
|
|
1077
|
-
const myIp = ppUtil$
|
|
1078
|
+
const myIp = ppUtil$3.getMyIp();
|
|
1078
1079
|
const host = params.host || myIp;
|
|
1079
1080
|
if (!myEnvHosts.hosts.contains(host)) throw [err$1.ACCESS_REFUSED, `环境${conf$2.envId}貌似无此主机:${params.host}`];
|
|
1080
1081
|
|
|
@@ -1376,7 +1377,7 @@ class apiUtil$1 {
|
|
|
1376
1377
|
if (await apiUtil$1.checkForwardsHost(options)) return true;
|
|
1377
1378
|
let c = apiUtil$1.parseCfgPath(item);
|
|
1378
1379
|
delete c.parent;
|
|
1379
|
-
c.host = ppUtil$
|
|
1380
|
+
c.host = ppUtil$3.getMyIp();
|
|
1380
1381
|
return c;
|
|
1381
1382
|
}
|
|
1382
1383
|
/**
|
|
@@ -1404,7 +1405,7 @@ class apiUtil$1 {
|
|
|
1404
1405
|
c.newValue = params.value;
|
|
1405
1406
|
c.parent[c.key] = c.newValue;
|
|
1406
1407
|
delete c.parent;
|
|
1407
|
-
c.host = ppUtil$
|
|
1408
|
+
c.host = ppUtil$3.getMyIp();
|
|
1408
1409
|
return c; // 应用层自行处理多机同步
|
|
1409
1410
|
} //#endregion
|
|
1410
1411
|
|
|
@@ -1413,18 +1414,18 @@ class apiUtil$1 {
|
|
|
1413
1414
|
|
|
1414
1415
|
function configNeeded() {
|
|
1415
1416
|
if (!conf$2 || !err$1) {
|
|
1416
|
-
ppUtil$
|
|
1417
|
-
conf$2 = ppUtil$
|
|
1417
|
+
ppUtil$3.configNeeded();
|
|
1418
|
+
conf$2 = ppUtil$3.appConfig;
|
|
1418
1419
|
appSetting$1 = conf$2.appSetting;
|
|
1419
|
-
err$1 = ppUtil$
|
|
1420
|
+
err$1 = ppUtil$3.appErrCfg;
|
|
1420
1421
|
}
|
|
1421
1422
|
}
|
|
1422
1423
|
|
|
1423
1424
|
var ppUtilApi = apiUtil$1;
|
|
1424
1425
|
|
|
1425
|
-
const fs = require$$0$
|
|
1426
|
+
const fs = require$$0$1;
|
|
1426
1427
|
const path = require$$1$1;
|
|
1427
|
-
const ppUtil$
|
|
1428
|
+
const ppUtil$2 = require$$1.ppUtil;
|
|
1428
1429
|
const redisUtil = require$$2.redisUtil;
|
|
1429
1430
|
let conf$1, err; // const dbCheck = require('../dbupdate/dd-version');
|
|
1430
1431
|
|
|
@@ -1445,9 +1446,9 @@ class preconditions$1 {
|
|
|
1445
1446
|
static checkPromises = [];
|
|
1446
1447
|
|
|
1447
1448
|
static setAppName(aName) {
|
|
1448
|
-
ppUtil$
|
|
1449
|
-
conf$1 = ppUtil$
|
|
1450
|
-
err = ppUtil$
|
|
1449
|
+
ppUtil$2.configNeeded();
|
|
1450
|
+
conf$1 = ppUtil$2.appConfig;
|
|
1451
|
+
err = ppUtil$2.appErrCfg;
|
|
1451
1452
|
preconditions$1.appName = aName || conf$1.thisApp;
|
|
1452
1453
|
return preconditions$1;
|
|
1453
1454
|
}
|
|
@@ -1527,7 +1528,7 @@ class preconditions$1 {
|
|
|
1527
1528
|
|
|
1528
1529
|
async function createEnvSettingFile(fileName) {
|
|
1529
1530
|
try {
|
|
1530
|
-
const cfgText = await ppUtil$
|
|
1531
|
+
const cfgText = await ppUtil$2.doCreateEnvSettingFile(fileName);
|
|
1531
1532
|
|
|
1532
1533
|
if (cfgText.indexOf(`cfgVersion: "${conf$1._envSetting.cfgVersion}"`) > 0) {
|
|
1533
1534
|
console.log(`\n*** 已創建新的本機環境配置文件\n${fileName}\n请檢查各項內容是否正确(此项更新服务可正常运行)\n\n`);
|
|
@@ -1572,7 +1573,7 @@ async function checkRedis() {
|
|
|
1572
1573
|
if (!conf$1.redis.enabled) return "";
|
|
1573
1574
|
const redis = redisUtil.newClient("io"); // console.log(`checkRedis begin:`);
|
|
1574
1575
|
|
|
1575
|
-
await ppUtil$
|
|
1576
|
+
await ppUtil$2.wait(15 * 1000, param => {
|
|
1576
1577
|
if (redis.ready && redis.connected || redis.error) {
|
|
1577
1578
|
return true;
|
|
1578
1579
|
}
|
|
@@ -1590,94 +1591,13 @@ async function checkRedis() {
|
|
|
1590
1591
|
|
|
1591
1592
|
var ppPrecond = preconditions$1;
|
|
1592
1593
|
|
|
1593
|
-
var require$$0 = require$$2;
|
|
1594
|
-
|
|
1595
|
-
function _interopDefaultLegacy(e) {
|
|
1596
|
-
return e && typeof e === 'object' && 'default' in e ? e : {
|
|
1597
|
-
'default': e
|
|
1598
|
-
};
|
|
1599
|
-
}
|
|
1600
|
-
|
|
1601
|
-
var require$$0__default = /*#__PURE__*/_interopDefaultLegacy(require$$0); // const logger = require("log4js").getLogger();
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
const redis = require$$0__default["default"].redisUtil;
|
|
1605
|
-
|
|
1606
|
-
class Messenger {
|
|
1607
|
-
constructor(appConfig, appErrCfg) {
|
|
1608
|
-
if (appConfig) {
|
|
1609
|
-
redis.config(appConfig, appErrCfg);
|
|
1610
|
-
}
|
|
1611
|
-
|
|
1612
|
-
this.channel = "ecs_messenger"; //default channel
|
|
1613
|
-
|
|
1614
|
-
this.publisher = redis.newClient("publisher");
|
|
1615
|
-
this.subscriber = redis.newClient("subscriber");
|
|
1616
|
-
this.subscriber.on("subscribe", function (channel, count) {
|
|
1617
|
-
console.log("chanel subscribed :", channel, count);
|
|
1618
|
-
});
|
|
1619
|
-
this.subscriber.on("message", this.handleMessage);
|
|
1620
|
-
}
|
|
1621
|
-
|
|
1622
|
-
setMessageHandle(handle, channel) {
|
|
1623
|
-
channel = channel || this.channel;
|
|
1624
|
-
Messenger.onmessage = Messenger.onmessage || {};
|
|
1625
|
-
Messenger.onmessage[channel] = Messenger.onmessage[channel] || [];
|
|
1626
|
-
const appMsgHandles = Messenger.onmessage[channel];
|
|
1627
|
-
|
|
1628
|
-
for (let i = 0; i < appMsgHandles.length; i++) {
|
|
1629
|
-
if (appMsgHandles[i] === handle) return this;
|
|
1630
|
-
}
|
|
1631
|
-
|
|
1632
|
-
appMsgHandles.push(handle);
|
|
1633
|
-
return this;
|
|
1634
|
-
}
|
|
1635
|
-
|
|
1636
|
-
subscribe(channel) {
|
|
1637
|
-
channel = channel || this.channel;
|
|
1638
|
-
this.subscriber.subscribe(channel);
|
|
1639
|
-
return this;
|
|
1640
|
-
}
|
|
1641
|
-
|
|
1642
|
-
async handleMessage(channel, message) {
|
|
1643
|
-
console.log(`通道[${channel}]收到订阅消息:`, message);
|
|
1644
|
-
let appMsgHandles = Messenger.onmessage[channel] || [];
|
|
1645
|
-
|
|
1646
|
-
for (let i = 0; i < appMsgHandles.length; i++) {
|
|
1647
|
-
const appMsgHandle = appMsgHandles[i];
|
|
1648
|
-
|
|
1649
|
-
try {
|
|
1650
|
-
let msgObj = JSON.parse(message); // await appMsgHandle(msgObj);
|
|
1651
|
-
|
|
1652
|
-
appMsgHandle(msgObj);
|
|
1653
|
-
} catch (e) {
|
|
1654
|
-
console.log(e);
|
|
1655
|
-
}
|
|
1656
|
-
}
|
|
1657
|
-
}
|
|
1658
|
-
|
|
1659
|
-
async publish(message, channel) {
|
|
1660
|
-
channel = channel || this.channel;
|
|
1661
|
-
let msgStr = typeof message === "object" ? JSON.stringify(message) : message.toString();
|
|
1662
|
-
console.log(`通道[${channel}]发布消息:`, message);
|
|
1663
|
-
await this.publisher.publish(channel, msgStr);
|
|
1664
|
-
return this;
|
|
1665
|
-
}
|
|
1666
|
-
|
|
1667
|
-
}
|
|
1668
|
-
|
|
1669
|
-
var ppMessenger$1 = Messenger;
|
|
1670
|
-
const ppMessenger = ppMessenger$1;
|
|
1671
|
-
var ppUtil$2 = ppMessenger;
|
|
1672
|
-
var ppUtil_1 = ppUtil$2;
|
|
1673
|
-
|
|
1674
1594
|
// 若 redis 可用,则使用基于 redis 的消息订阅发布系统
|
|
1675
1595
|
// 若 redis 不可用,则将消息转发到其它主机
|
|
1676
1596
|
|
|
1677
1597
|
const {
|
|
1678
1598
|
ppUtil: ppUtil$1
|
|
1679
1599
|
} = require$$1;
|
|
1680
|
-
const RedisMessenger =
|
|
1600
|
+
const RedisMessenger = require$$1$2;
|
|
1681
1601
|
const {
|
|
1682
1602
|
netUtil
|
|
1683
1603
|
} = require$$3;
|