abler-api 0.1.73 → 0.1.75
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 +81 -58
- package/package.json +6 -2
package/dist/cjs/pp-util.js
CHANGED
|
@@ -3,11 +3,12 @@
|
|
|
3
3
|
var require$$0 = require('fs');
|
|
4
4
|
var require$$1$1 = require('crypto');
|
|
5
5
|
var require$$2$1 = require('basic-auth');
|
|
6
|
-
var require$$2 = require('abler-
|
|
7
|
-
var require$$3 = require('abler-
|
|
8
|
-
var require$$
|
|
6
|
+
var require$$2 = require('abler-lang');
|
|
7
|
+
var require$$3 = require('abler-util');
|
|
8
|
+
var require$$4 = require('abler-db');
|
|
9
|
+
var require$$6 = require('abler-net');
|
|
9
10
|
var require$$1 = require('path');
|
|
10
|
-
var require$$
|
|
11
|
+
var require$$2$2 = require('abler-messenger');
|
|
11
12
|
var require$$0$1 = require('node-cron');
|
|
12
13
|
|
|
13
14
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
@@ -17,20 +18,25 @@ var require$$1__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$1$1);
|
|
|
17
18
|
var require$$2__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$2$1);
|
|
18
19
|
var require$$2__default = /*#__PURE__*/_interopDefaultLegacy(require$$2);
|
|
19
20
|
var require$$3__default = /*#__PURE__*/_interopDefaultLegacy(require$$3);
|
|
20
|
-
var require$$
|
|
21
|
+
var require$$4__default = /*#__PURE__*/_interopDefaultLegacy(require$$4);
|
|
22
|
+
var require$$6__default = /*#__PURE__*/_interopDefaultLegacy(require$$6);
|
|
21
23
|
var require$$1__default = /*#__PURE__*/_interopDefaultLegacy(require$$1);
|
|
22
|
-
var require$$
|
|
24
|
+
var require$$2__default$2 = /*#__PURE__*/_interopDefaultLegacy(require$$2$2);
|
|
23
25
|
var require$$0__default$1 = /*#__PURE__*/_interopDefaultLegacy(require$$0$1);
|
|
24
26
|
|
|
25
27
|
const fs$1 = require$$0__default["default"];
|
|
26
28
|
const path = require$$1__default["default"];
|
|
27
|
-
const
|
|
29
|
+
const {
|
|
30
|
+
t_f: t_f$3,
|
|
31
|
+
t: t$1
|
|
32
|
+
} = require$$2__default["default"];
|
|
33
|
+
const ppUtil$4 = require$$3__default["default"].ppUtil;
|
|
28
34
|
const {
|
|
29
35
|
dbUtil: dbUtil$1,
|
|
30
36
|
ppRedis,
|
|
31
37
|
kvStorage: kvStorage$1,
|
|
32
38
|
redisSimulator
|
|
33
|
-
} = require$$
|
|
39
|
+
} = require$$4__default["default"];
|
|
34
40
|
let conf$3, err$2;
|
|
35
41
|
// const dbCheck = require('../dbupdate/dd-version');
|
|
36
42
|
|
|
@@ -102,7 +108,7 @@ class preconditions$2 {
|
|
|
102
108
|
}
|
|
103
109
|
let text = "";
|
|
104
110
|
if (preconditions$2.messages) {
|
|
105
|
-
text =
|
|
111
|
+
text = t_f$3("*** 由于以下原因,%s 尚不能正常提供服务:\n\n", preconditions$2.appName) + preconditions$2.messages.join("\n\n") + t$1("\n\n*** 请检查以上各项条件,修复后重新启动服务");
|
|
106
112
|
console.log("\n" + text);
|
|
107
113
|
// for (let i = 0; i < preconditions.messages.length; i++) {
|
|
108
114
|
// console.log(preconditions.messages[i]);
|
|
@@ -156,12 +162,12 @@ async function createEnvSettingFile(fileName, lastEnvSettingEx) {
|
|
|
156
162
|
try {
|
|
157
163
|
const cfgText = await ppUtil$4.doCreateEnvSettingFile(fileName, lastEnvSettingEx);
|
|
158
164
|
if (cfgText.indexOf(`cfgVersion: "${conf$3._envSetting.cfgVersion}"`) > 0) {
|
|
159
|
-
console.log(
|
|
165
|
+
console.log(t_f$3("\n*** 已創建新的本機環境配置文件\n%s\n请檢查各項內容是否正确(此项更新服务可正常运行)\n\n", fileName));
|
|
160
166
|
return "";
|
|
161
167
|
}
|
|
162
|
-
return
|
|
168
|
+
return t_f$3("已創建新的本機環境配置文件\n%s\n请檢查並正確設置各項內容,然後將配置版本號修改為%s", fileName, conf$3._envSettings.default.cfgVersion);
|
|
163
169
|
} catch (e) {
|
|
164
|
-
return
|
|
170
|
+
return t_f$3("創建本機環境配置文件失敗\n《%s》\n%s", fileName, err$2.ERROR(e).message);
|
|
165
171
|
}
|
|
166
172
|
}
|
|
167
173
|
async function checkExEnvSetting(loadjs) {
|
|
@@ -188,7 +194,7 @@ async function checkExEnvSetting(loadjs) {
|
|
|
188
194
|
}
|
|
189
195
|
ppUtil$4.importExEnvSetting(conf$3._envSetting, fileName, loadjs);
|
|
190
196
|
} catch (e) {
|
|
191
|
-
return
|
|
197
|
+
return t_f$3("导入本机环境配置失败\n%s", e.stack);
|
|
192
198
|
}
|
|
193
199
|
}
|
|
194
200
|
|
|
@@ -208,8 +214,8 @@ async function checkRedis() {
|
|
|
208
214
|
redis.error = e;
|
|
209
215
|
});
|
|
210
216
|
if (redis.error) {
|
|
211
|
-
console.log(
|
|
212
|
-
return
|
|
217
|
+
console.log(t_f$3("未能成功連接 redis: %s,請檢查相關設置", redis.error));
|
|
218
|
+
return t_f$3("未能成功連接 redis: %s,請檢查相關設置", redis.error);
|
|
213
219
|
}
|
|
214
220
|
// console.log(`checkRedis done:`);
|
|
215
221
|
// console.log(redis);
|
|
@@ -219,12 +225,12 @@ async function initDb() {
|
|
|
219
225
|
dbUtil$1.config(conf$3, err$2);
|
|
220
226
|
} catch (e) {
|
|
221
227
|
if (e.reason === 'bad decrypt') {
|
|
222
|
-
e = new Error(
|
|
228
|
+
e = new Error(t_f$3("解密数据库密码(%s)失败", conf$3.dbconn.dbpwd));
|
|
223
229
|
}
|
|
224
230
|
// if (e.reason === 'bad decrypt') {
|
|
225
231
|
// e = new Error(`解密Redis密码(${conf.redis.password})失败`);
|
|
226
232
|
// }
|
|
227
|
-
return
|
|
233
|
+
return t_f$3("初始化数据库连接失败(%s)", e.message);
|
|
228
234
|
}
|
|
229
235
|
}
|
|
230
236
|
async function initKvStorage(dbSql) {
|
|
@@ -239,7 +245,7 @@ async function initKvStorage(dbSql) {
|
|
|
239
245
|
// if (e.reason === 'bad decrypt') {
|
|
240
246
|
// e = new Error(`解密Redis密码(${conf.redis.password})失败`);
|
|
241
247
|
// }
|
|
242
|
-
return
|
|
248
|
+
return t_f$3("初始化键值对存储器失败(%s)", e.message);
|
|
243
249
|
}
|
|
244
250
|
}
|
|
245
251
|
var ppPrecond = preconditions$2;
|
|
@@ -247,14 +253,20 @@ var ppPrecond = preconditions$2;
|
|
|
247
253
|
const fs = require$$0__default["default"];
|
|
248
254
|
const crypto = require$$1__default$1["default"];
|
|
249
255
|
const getBasicAuthorization = require$$2__default$1["default"];
|
|
250
|
-
const
|
|
256
|
+
const {
|
|
257
|
+
t_f: t_f$2,
|
|
258
|
+
t
|
|
259
|
+
} = require$$2__default["default"];
|
|
260
|
+
const {
|
|
261
|
+
ppUtil: ppUtil$3
|
|
262
|
+
} = require$$3__default["default"];
|
|
251
263
|
const {
|
|
252
264
|
dbUtil,
|
|
253
265
|
kvStorage
|
|
254
|
-
} = require$$
|
|
266
|
+
} = require$$4__default["default"];
|
|
255
267
|
const {
|
|
256
268
|
netUtil: netUtil$1
|
|
257
|
-
} = require$$
|
|
269
|
+
} = require$$6__default["default"];
|
|
258
270
|
const preconditions$1 = ppPrecond;
|
|
259
271
|
let conf$2, appSetting, err$1, dbSql;
|
|
260
272
|
const pnToken = "access_token",
|
|
@@ -394,7 +406,7 @@ class apiUtil$2 {
|
|
|
394
406
|
if (this[name] === undefined) return defaultValue;
|
|
395
407
|
let result = +this[name];
|
|
396
408
|
if (typeof result !== "number" || result < minValue || result > maxValue) {
|
|
397
|
-
throw [err$1.INVALID_PARAM,
|
|
409
|
+
throw [err$1.INVALID_PARAM, t_f$2("参数 %s 必须是 %s ~ %s 之间的数字", name, minValue, maxValue)];
|
|
398
410
|
}
|
|
399
411
|
return result;
|
|
400
412
|
});
|
|
@@ -506,7 +518,7 @@ class apiUtil$2 {
|
|
|
506
518
|
try {
|
|
507
519
|
response.send(data);
|
|
508
520
|
} catch (e) {
|
|
509
|
-
console.log(
|
|
521
|
+
console.log(t_f$2("response.send 出错了,req.url: %s, response:", response.req.url), response);
|
|
510
522
|
console.log("异常信息", e);
|
|
511
523
|
}
|
|
512
524
|
}
|
|
@@ -553,7 +565,7 @@ class apiUtil$2 {
|
|
|
553
565
|
|
|
554
566
|
/**
|
|
555
567
|
* 从请求参数中获取查询参数
|
|
556
|
-
|
|
568
|
+
* @param req
|
|
557
569
|
* @param res
|
|
558
570
|
* @returns {*}
|
|
559
571
|
*/
|
|
@@ -983,7 +995,7 @@ class apiUtil$2 {
|
|
|
983
995
|
return certInfo;
|
|
984
996
|
}).catch(e => {
|
|
985
997
|
console.log('获取企业证书失败:\n', e);
|
|
986
|
-
throw [err$1.ACCESS_REFUSED,
|
|
998
|
+
throw [err$1.ACCESS_REFUSED, t_f$2("获取企业证书失败:%s", err$1.ERROR(e).message)];
|
|
987
999
|
});
|
|
988
1000
|
}
|
|
989
1001
|
|
|
@@ -996,17 +1008,17 @@ class apiUtil$2 {
|
|
|
996
1008
|
static async verifyApiSignature(tokenData, req) {
|
|
997
1009
|
try {
|
|
998
1010
|
if (!req.headers.timestamp) {
|
|
999
|
-
throw [err$1.ACCESS_REFUSED,
|
|
1011
|
+
throw [err$1.ACCESS_REFUSED, t_f$2("必须在请求头中设置时戳")];
|
|
1000
1012
|
}
|
|
1001
1013
|
let timestamp = parseInt(req.headers.timestamp);
|
|
1002
1014
|
let currentTime = new Date().valueOf();
|
|
1003
1015
|
let maxTimeDiff = apiUtil$2.isDebugMode(req) ? 7 * 24 * 3600 : apiUtil$2.isTestMode(req) ? 4 * 3600 : 100; // 100
|
|
1004
1016
|
if (timestamp.toString() == "NaN" || currentTime < timestamp - 5000 || currentTime - timestamp > maxTimeDiff * 1000) {
|
|
1005
|
-
throw [err$1.ACCESS_REFUSED,
|
|
1017
|
+
throw [err$1.ACCESS_REFUSED, t_f$2("时戳(%s)无效,当前时戳:%s,时差 %s秒", timestamp, currentTime, (currentTime - timestamp) / 1000)];
|
|
1006
1018
|
}
|
|
1007
1019
|
let signature = req.headers.signature;
|
|
1008
1020
|
if (!signature) {
|
|
1009
|
-
throw [err$1.ACCESS_REFUSED,
|
|
1021
|
+
throw [err$1.ACCESS_REFUSED, t_f$2("必须在请求头中提供签名")];
|
|
1010
1022
|
}
|
|
1011
1023
|
let signData = apiUtil$2.extractToken(req, null, true) || tokenData.apiKey;
|
|
1012
1024
|
signData += timestamp;
|
|
@@ -1053,7 +1065,7 @@ class apiUtil$2 {
|
|
|
1053
1065
|
if (!tokenData.certPublicKeySpare) {
|
|
1054
1066
|
throw {
|
|
1055
1067
|
eo: err$1.ACCESS_REFUSED,
|
|
1056
|
-
msgArgv: "签名验证异常",
|
|
1068
|
+
msgArgv: t("签名验证异常"),
|
|
1057
1069
|
data: e
|
|
1058
1070
|
};
|
|
1059
1071
|
}
|
|
@@ -1067,7 +1079,7 @@ class apiUtil$2 {
|
|
|
1067
1079
|
verifyOK = verifySpare.verify(tokenData.certPublicKeySpare, signature, 'base64');
|
|
1068
1080
|
if (verifyOK) {
|
|
1069
1081
|
// 备用证书验证成功了,则将备用证书替换为正式证书
|
|
1070
|
-
console.log(
|
|
1082
|
+
console.log(t_f$2("公司(%s)备用证书验签成功,正式启用...", tokenData.apiKey));
|
|
1071
1083
|
return dbUtil.dbTrans(trans => {
|
|
1072
1084
|
let p1 = dbUtil.dbExec(dbSql.deleteCertRecById, {
|
|
1073
1085
|
replacements: {
|
|
@@ -1091,21 +1103,21 @@ class apiUtil$2 {
|
|
|
1091
1103
|
if (token) {
|
|
1092
1104
|
apiUtil$2.storeToken(apiUtil$2.apiTokenStoreKey(token), tokenData, tokenData.apiKey, req);
|
|
1093
1105
|
}
|
|
1094
|
-
console.log(
|
|
1106
|
+
console.log(t_f$2("公司(%s)备用证书成功转换为正式证书", tokenData.apiKey));
|
|
1095
1107
|
});
|
|
1096
1108
|
}
|
|
1097
1109
|
} catch (e) {
|
|
1098
1110
|
console.log("SPO服务签名验证异常(备用证书), ", e);
|
|
1099
1111
|
throw {
|
|
1100
1112
|
eo: err$1.ACCESS_REFUSED,
|
|
1101
|
-
msgArgv: "签名验证异常(spare)",
|
|
1113
|
+
msgArgv: t("签名验证异常(spare)"),
|
|
1102
1114
|
data: e
|
|
1103
1115
|
};
|
|
1104
1116
|
}
|
|
1105
1117
|
}
|
|
1106
1118
|
if (!verifyOK) {
|
|
1107
1119
|
console.log("SPO服务签名验证失败, tokenData: ", tokenData);
|
|
1108
|
-
throw [err$1.ACCESS_REFUSED, "签名验证未通过"];
|
|
1120
|
+
throw [err$1.ACCESS_REFUSED, t("签名验证未通过")];
|
|
1109
1121
|
}
|
|
1110
1122
|
return verifyOK;
|
|
1111
1123
|
}
|
|
@@ -1121,7 +1133,7 @@ class apiUtil$2 {
|
|
|
1121
1133
|
if (!tokenData.companyInfo) {
|
|
1122
1134
|
tokenData.companyInfo = await apiUtil$2.queryCompanyInfo(tokenData.apiKey, true).catch(e => {
|
|
1123
1135
|
console.log("执行企业信息查询发生异常", e);
|
|
1124
|
-
throw [err$1.API_KEY_INVALID, "执行企业信息查询发生异常:" + e.message || ""];
|
|
1136
|
+
throw [err$1.API_KEY_INVALID, t("执行企业信息查询发生异常:") + e.message || ""];
|
|
1125
1137
|
});
|
|
1126
1138
|
}
|
|
1127
1139
|
const companyInfo = tokenData.companyInfo;
|
|
@@ -1179,7 +1191,7 @@ class apiUtil$2 {
|
|
|
1179
1191
|
break;
|
|
1180
1192
|
}
|
|
1181
1193
|
}
|
|
1182
|
-
paramName =
|
|
1194
|
+
paramName = t_f$2("%s 之一", paramName);
|
|
1183
1195
|
} else {
|
|
1184
1196
|
paramExists = typeof params[paramName] != 'undefined' || typeof params[paramName + paramSufix] != 'undefined';
|
|
1185
1197
|
}
|
|
@@ -1249,7 +1261,7 @@ class apiUtil$2 {
|
|
|
1249
1261
|
const myEnvHosts = apiUtil$2.getEnvHosts(params);
|
|
1250
1262
|
const myIp = ppUtil$3.getMyIp();
|
|
1251
1263
|
const host = params.host || myIp;
|
|
1252
|
-
if (!myEnvHosts.hosts.contains(host)) throw [err$1.ACCESS_REFUSED,
|
|
1264
|
+
if (!myEnvHosts.hosts.contains(host)) throw [err$1.ACCESS_REFUSED, t_f$2("环境%s貌似无此主机:%s", conf$2.envId, params.host)];
|
|
1253
1265
|
if (!apiUtil$2.hostIsMySelf(host, options._res.req)) {
|
|
1254
1266
|
let result = await apiUtil$2.forwardsTo(host, myEnvHosts.port, params, options._res.req, myIp);
|
|
1255
1267
|
options._res.send(result);
|
|
@@ -1279,7 +1291,7 @@ class apiUtil$2 {
|
|
|
1279
1291
|
};
|
|
1280
1292
|
let result = await netUtil$1.apiRequest(reqOptions);
|
|
1281
1293
|
if (result.status !== 200) {
|
|
1282
|
-
console.log(
|
|
1294
|
+
console.log(t_f$2("访问 %s 出错", reqOptions.url), result.status, result.res.statusMessage);
|
|
1283
1295
|
throw [err$1.EXCEPTION, `[${result.status}] - ${result.res.statusMessage}`];
|
|
1284
1296
|
}
|
|
1285
1297
|
return result.data;
|
|
@@ -1302,7 +1314,7 @@ class apiUtil$2 {
|
|
|
1302
1314
|
key = keys[i];
|
|
1303
1315
|
value = parent[key];
|
|
1304
1316
|
if (value === undefined) {
|
|
1305
|
-
throw [err$1.INVALID_PARAM,
|
|
1317
|
+
throw [err$1.INVALID_PARAM, t_f$2("无此配置项: %s", key)];
|
|
1306
1318
|
}
|
|
1307
1319
|
}
|
|
1308
1320
|
return {
|
|
@@ -1361,6 +1373,7 @@ class apiUtil$2 {
|
|
|
1361
1373
|
await apiUtil$2.restoreTokenData(apiUtil$2.userTokenStoreKey(req.accessToken), apiUtil$2.tokenExpireTime(req)).then(function (data) {
|
|
1362
1374
|
req.userInfo = apiUtil$2.setUserIdNo(data, data._idNo);
|
|
1363
1375
|
}, function (e) {
|
|
1376
|
+
|
|
1364
1377
|
//no token
|
|
1365
1378
|
});
|
|
1366
1379
|
}
|
|
@@ -1572,7 +1585,7 @@ class apiUtil$2 {
|
|
|
1572
1585
|
await apiUtil$2.parametersOK(params, "value");
|
|
1573
1586
|
let c = apiUtil$2.parseCfgPath(cfgItem);
|
|
1574
1587
|
if (typeof c.value === "object") {
|
|
1575
|
-
throw [err$1.ACCESS_REFUSED,
|
|
1588
|
+
throw [err$1.ACCESS_REFUSED, t_f$2("暂不支持修改复杂配置")];
|
|
1576
1589
|
}
|
|
1577
1590
|
// c.oldValue = c.value;
|
|
1578
1591
|
c.newValue = params.value;
|
|
@@ -1634,18 +1647,24 @@ function configNeeded() {
|
|
|
1634
1647
|
}
|
|
1635
1648
|
var ppUtilApi = apiUtil$2;
|
|
1636
1649
|
|
|
1637
|
-
// 普通消息系统
|
|
1638
|
-
// 若 redis 可用,则使用基于 redis 的消息订阅发布系统
|
|
1639
|
-
// 若 redis 不可用,则将消息转发到其它主机
|
|
1640
|
-
|
|
1641
1650
|
const {
|
|
1642
|
-
|
|
1651
|
+
t_f: t_f$1
|
|
1643
1652
|
} = require$$2__default["default"];
|
|
1644
|
-
const
|
|
1653
|
+
const {
|
|
1654
|
+
ppUtil: ppUtil$2
|
|
1655
|
+
} = require$$3__default["default"];
|
|
1656
|
+
const RedisMessenger = require$$2__default$2["default"];
|
|
1645
1657
|
const {
|
|
1646
1658
|
netUtil
|
|
1647
|
-
} = require$$
|
|
1659
|
+
} = require$$6__default["default"];
|
|
1648
1660
|
let conf$1;
|
|
1661
|
+
|
|
1662
|
+
/**
|
|
1663
|
+
* 普通消息系统
|
|
1664
|
+
* =
|
|
1665
|
+
* 若 redis 可用,则使用基于 redis 的消息订阅发布系统
|
|
1666
|
+
* 若 redis 不可用,则将消息转发到其它主机
|
|
1667
|
+
*/
|
|
1649
1668
|
class commonMessenger$2 {
|
|
1650
1669
|
static myMsgAddr = "";
|
|
1651
1670
|
static redisMessenger = null;
|
|
@@ -1712,26 +1731,30 @@ async function forwardMessage(message) {
|
|
|
1712
1731
|
data: message
|
|
1713
1732
|
};
|
|
1714
1733
|
let res = await netUtil.apiRequest(reqOptions).catch(e => {
|
|
1715
|
-
console.log(
|
|
1734
|
+
console.log(t_f$1("转发消息失败, url: %s", reqOptions.url), e);
|
|
1716
1735
|
throw e;
|
|
1717
1736
|
});
|
|
1718
1737
|
return res.data;
|
|
1719
1738
|
}
|
|
1720
1739
|
var ppMessengerEx = commonMessenger$2;
|
|
1721
1740
|
|
|
1722
|
-
/**
|
|
1723
|
-
* CSCA 自动任务
|
|
1724
|
-
* ==============
|
|
1725
|
-
*/
|
|
1726
1741
|
const CRON = require$$0__default$1["default"];
|
|
1727
1742
|
const {
|
|
1728
|
-
|
|
1743
|
+
t_f
|
|
1729
1744
|
} = require$$2__default["default"];
|
|
1745
|
+
const {
|
|
1746
|
+
ppUtil: ppUtil$1
|
|
1747
|
+
} = require$$3__default["default"];
|
|
1730
1748
|
const apiUtil$1 = ppUtilApi;
|
|
1731
1749
|
const commonMessenger$1 = ppMessengerEx;
|
|
1732
1750
|
const MT_SCHEDULE_STATE = 'schedule-state',
|
|
1733
1751
|
MT_SCHEDULE_STATE_REPLY = 'schedule-state-reply';
|
|
1734
1752
|
let conf, err;
|
|
1753
|
+
|
|
1754
|
+
/**
|
|
1755
|
+
* CSCA 自动任务
|
|
1756
|
+
* ==============
|
|
1757
|
+
*/
|
|
1735
1758
|
class schedule$1 {
|
|
1736
1759
|
static tasks = {};
|
|
1737
1760
|
|
|
@@ -1763,9 +1786,9 @@ class schedule$1 {
|
|
|
1763
1786
|
doScheduleTask: async function () {
|
|
1764
1787
|
let self = this;
|
|
1765
1788
|
if (this._pp_task) self = this._pp_task;
|
|
1766
|
-
console.log(new Date().format('[yyyy/MM/dd hh:mm:ss:S]'),
|
|
1789
|
+
console.log(new Date().format('[yyyy/MM/dd hh:mm:ss:S]'), t_f("开始执行%s任务 ...", self.caption));
|
|
1767
1790
|
await self.taskFunc();
|
|
1768
|
-
console.log(new Date().format('[yyyy/MM/dd hh:mm:ss:S]'),
|
|
1791
|
+
console.log(new Date().format('[yyyy/MM/dd hh:mm:ss:S]'), t_f("%s任务执行结束", self.caption));
|
|
1769
1792
|
}
|
|
1770
1793
|
};
|
|
1771
1794
|
this.tasks[taskName] = task;
|
|
@@ -1799,7 +1822,7 @@ class schedule$1 {
|
|
|
1799
1822
|
if (typeof task === "string") {
|
|
1800
1823
|
task = this.findTask(taskOrName);
|
|
1801
1824
|
}
|
|
1802
|
-
if (!task) throw [err.INVALID_PARAM,
|
|
1825
|
+
if (!task) throw [err.INVALID_PARAM, t_f("任务%s不存在", taskOrName)];
|
|
1803
1826
|
cronExp = cronExp || task.cronExp;
|
|
1804
1827
|
if (task.cronExp !== cronExp) {
|
|
1805
1828
|
this.stop(task);
|
|
@@ -1824,7 +1847,7 @@ class schedule$1 {
|
|
|
1824
1847
|
if (typeof task === "string") {
|
|
1825
1848
|
task = this.findTask(taskOrName);
|
|
1826
1849
|
}
|
|
1827
|
-
if (!task) throw [err.INVALID_PARAM,
|
|
1850
|
+
if (!task) throw [err.INVALID_PARAM, t_f("任务%s不存在", taskOrName)];
|
|
1828
1851
|
if (task.schedule) {
|
|
1829
1852
|
task.schedule.stop();
|
|
1830
1853
|
task.schedule = null;
|
|
@@ -1901,7 +1924,7 @@ class schedule$1 {
|
|
|
1901
1924
|
let task;
|
|
1902
1925
|
if (params.taskName) {
|
|
1903
1926
|
task = this.findTask(params.taskName);
|
|
1904
|
-
if (!task) throw [err.INVALID_PARAM,
|
|
1927
|
+
if (!task) throw [err.INVALID_PARAM, t_f("任务%s不存在", params.taskName)];
|
|
1905
1928
|
}
|
|
1906
1929
|
if (params.state) {
|
|
1907
1930
|
if ("started" === params.state) {
|
|
@@ -1909,7 +1932,7 @@ class schedule$1 {
|
|
|
1909
1932
|
} else if ("stopped" === params.state) {
|
|
1910
1933
|
apiResult = await this.stop(task);
|
|
1911
1934
|
} else {
|
|
1912
|
-
throw [err.INVALID_PARAM,
|
|
1935
|
+
throw [err.INVALID_PARAM, t_f("(%s), 只能是 started/stopped", params.state)];
|
|
1913
1936
|
}
|
|
1914
1937
|
if (params.runOnce) {
|
|
1915
1938
|
task = this.findTask(params.taskName);
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "abler-api",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.75",
|
|
4
4
|
"description": "API服务相关工具",
|
|
5
5
|
"main": "./dist/cjs/pp-util.js",
|
|
6
6
|
"-module": "./dist/es/pp-util.js",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "npx rollup -c rollup.config.js",
|
|
9
|
+
"postbuild": "node ..\\postbuild.js",
|
|
9
10
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
10
11
|
},
|
|
11
12
|
"files": [
|
|
@@ -17,8 +18,11 @@
|
|
|
17
18
|
"q": "^1.5.1",
|
|
18
19
|
"abler-util": ">=0.1.1",
|
|
19
20
|
"abler-db": ">=0.1.1",
|
|
21
|
+
"abler-lang": "^0.1.20",
|
|
20
22
|
"abler-messenger": ">=0.1.1",
|
|
21
|
-
"abler-net": ">=0.1.1"
|
|
23
|
+
"abler-net": ">=0.1.1",
|
|
24
|
+
"basic-auth": "^2.0.1",
|
|
25
|
+
"node-cron": "^3.0.1"
|
|
22
26
|
},
|
|
23
27
|
"devDependencies": {
|
|
24
28
|
"@babel/core": "^7.18.5",
|