xzwebx-httpfilter 2.0.0 → 2.1.8
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/HttpFilter.js +78 -136
- package/package.json +1 -1
package/HttpFilter.js
CHANGED
|
@@ -7,57 +7,72 @@ let TipsMap = {}
|
|
|
7
7
|
let ModuleMap = {}
|
|
8
8
|
let ModuleInterfaceMap = {}
|
|
9
9
|
let FieldMap = {}
|
|
10
|
+
let IsCheckedRes = true
|
|
10
11
|
async function response(req, res, next) {
|
|
11
12
|
let retData = {
|
|
12
13
|
codeKey: 'SVC_ERR',
|
|
13
14
|
data: []
|
|
14
15
|
}
|
|
15
16
|
retData.codeKey = 'SUCC'
|
|
16
|
-
return res.send(res.Msg(retData))
|
|
17
|
+
return res.send(res.Msg(retData, req.GetRspMsgId()))
|
|
18
|
+
}
|
|
19
|
+
function SetIsCheckedRes(isCheckedRes) {
|
|
20
|
+
if (isCheckedRes) {
|
|
21
|
+
IsCheckedRes = true
|
|
22
|
+
} else {
|
|
23
|
+
IsCheckedRes = false
|
|
24
|
+
}
|
|
17
25
|
}
|
|
18
26
|
function Init(language, resultCodeMap, tipsMap, moduleMap, moduleInterfaceMap, fieldMap) {
|
|
19
27
|
ResultCodeMap = resultCodeMap
|
|
20
|
-
TipsMap = tipsMap[language]
|
|
28
|
+
TipsMap = tipsMap[language] || {}
|
|
21
29
|
ModuleMap = moduleMap
|
|
22
30
|
ModuleInterfaceMap = moduleInterfaceMap
|
|
23
31
|
FieldMap = fieldMap
|
|
24
32
|
}
|
|
25
|
-
function MSG(params) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
let msg = ''
|
|
32
|
-
if (!params.msg) {
|
|
33
|
-
if (TipsMap[params.codeKey]) {
|
|
34
|
-
msg = TipsMap[params.codeKey].tips
|
|
35
|
-
} else {
|
|
36
|
-
msg = ResultCodeMap[params.codeKey].codeDesc
|
|
33
|
+
function MSG(params, rspMsgId) {
|
|
34
|
+
if (IsCheckedRes && rspMsgId) {
|
|
35
|
+
let retMsgData = cycleCheckParams(FieldMap[rspMsgId], params.data)
|
|
36
|
+
if (retMsgData) {
|
|
37
|
+
return MSG({codeKey: 'CLT_ERR', msg: retMsgData, data: params.data})
|
|
37
38
|
}
|
|
38
39
|
} else {
|
|
39
|
-
|
|
40
|
-
|
|
40
|
+
let code = ''
|
|
41
|
+
if (ResultCodeMap[params.codeKey]) {
|
|
42
|
+
code = ResultCodeMap[params.codeKey].rstCode
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
let msg = ''
|
|
46
|
+
if (!params.msg) {
|
|
47
|
+
if (TipsMap[params.codeKey]) {
|
|
48
|
+
msg = TipsMap[params.codeKey].tips
|
|
49
|
+
} else {
|
|
50
|
+
msg = ResultCodeMap[params.codeKey].codeDesc
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
if (typeof params.msg == 'string') {
|
|
54
|
+
msg = params.msg
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (typeof params.msg == 'object' && params.msg.length) {
|
|
58
|
+
if (TipsMap[params.msg[0]]) {
|
|
59
|
+
msg = TipsMap[params.msg[0]].tips
|
|
60
|
+
if (params.msg.length > 1) {
|
|
61
|
+
for (let i = 1; i < params.msg.length; i++) {
|
|
62
|
+
msg = Util.format(msg, params.msg[i])
|
|
63
|
+
}
|
|
49
64
|
}
|
|
65
|
+
} else {
|
|
66
|
+
msg = params.msg[0]
|
|
50
67
|
}
|
|
51
|
-
} else {
|
|
52
|
-
msg = params.msg[0]
|
|
53
68
|
}
|
|
54
69
|
}
|
|
55
|
-
}
|
|
56
70
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
71
|
+
return {
|
|
72
|
+
code: code,
|
|
73
|
+
msg: msg,
|
|
74
|
+
data: params.data
|
|
75
|
+
}
|
|
61
76
|
}
|
|
62
77
|
}
|
|
63
78
|
function SetRoutes(app, express, projectPath) {
|
|
@@ -110,6 +125,11 @@ function CheckReq(req, res, next) {
|
|
|
110
125
|
return res.send(res.Msg({codeKey: 'CLT_ERR', msg: ['WEBX_ERR_URL']}))
|
|
111
126
|
}
|
|
112
127
|
|
|
128
|
+
req['__rspMsgId'] = ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()].rspMsgId || ''
|
|
129
|
+
req['GetRspMsgId'] = function() {
|
|
130
|
+
return req['__rspMsgId']
|
|
131
|
+
}
|
|
132
|
+
|
|
113
133
|
req.headers['interfaceInfo'] = ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()]
|
|
114
134
|
let reqMsgId = ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()].reqMsgId
|
|
115
135
|
if (!reqMsgId) {
|
|
@@ -185,6 +205,17 @@ function cycleCheckParams(msgFieldMap, data) {
|
|
|
185
205
|
}
|
|
186
206
|
return null
|
|
187
207
|
}
|
|
208
|
+
|
|
209
|
+
function getCustomTips(tips) {
|
|
210
|
+
if (tips.length > 3 && tips.substring(0, 2) === '${' && tips.substring(tips.length -1, tips.length) === '}') {
|
|
211
|
+
let tipsKey = tips.substring(2, tips.length -1)
|
|
212
|
+
tipsKey = tipsKey.trim()
|
|
213
|
+
if (TipsMap[tipsKey]) {
|
|
214
|
+
return TipsMap[tipsKey].tips
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
return tips
|
|
218
|
+
}
|
|
188
219
|
function IsStringOk(fCfgItem, paramValue) {
|
|
189
220
|
if (!fCfgItem || !fCfgItem.ifMust) {
|
|
190
221
|
return null
|
|
@@ -201,13 +232,7 @@ function IsStringOk(fCfgItem, paramValue) {
|
|
|
201
232
|
|
|
202
233
|
if (!paramValue || typeof paramValue != 'string') {
|
|
203
234
|
if (fCfgItem.nullTips) {
|
|
204
|
-
|
|
205
|
-
let nullTipsKey = fCfgItem.nullTips.substring(2, fCfgItem.nullTips.length -1)
|
|
206
|
-
if (TipsMap[nullTipsKey]) {
|
|
207
|
-
return TipsMap[nullTipsKey].tips
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return fCfgItem.nullTips
|
|
235
|
+
return getCustomTips(fCfgItem.nullTips)
|
|
211
236
|
}
|
|
212
237
|
return ['WEBX_NULL_FIELD', 'string', fCfgItem.fieldUrl]
|
|
213
238
|
}
|
|
@@ -231,13 +256,7 @@ function IsStringOk(fCfgItem, paramValue) {
|
|
|
231
256
|
|
|
232
257
|
if (!isPass) {
|
|
233
258
|
if (rule.ruleDesc) {
|
|
234
|
-
|
|
235
|
-
let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
|
|
236
|
-
if (TipsMap[ruleTipsKey]) {
|
|
237
|
-
return TipsMap[ruleTipsKey].tips
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return rule.ruleDesc
|
|
259
|
+
return getCustomTips(rule.ruleDesc)
|
|
241
260
|
}
|
|
242
261
|
return ['WEBX_WRONG_RANGE', fCfgItem.fieldUrl, JSON.stringify(rule.exprVal)]
|
|
243
262
|
}
|
|
@@ -247,26 +266,14 @@ function IsStringOk(fCfgItem, paramValue) {
|
|
|
247
266
|
if (rule.isMatched === 1) {
|
|
248
267
|
if (!rule.exprVal.includes(paramValue)) {
|
|
249
268
|
if (rule.ruleDesc) {
|
|
250
|
-
|
|
251
|
-
let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
|
|
252
|
-
if (TipsMap[ruleTipsKey]) {
|
|
253
|
-
return TipsMap[ruleTipsKey].tips
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
return rule.ruleDesc
|
|
269
|
+
return getCustomTips(rule.ruleDesc)
|
|
257
270
|
}
|
|
258
271
|
return ['WEBX_WRONG_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
259
272
|
}
|
|
260
273
|
} else {
|
|
261
274
|
if (rule.exprVal.includes(paramValue)) {
|
|
262
275
|
if (rule.ruleDesc) {
|
|
263
|
-
|
|
264
|
-
let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
|
|
265
|
-
if (TipsMap[ruleTipsKey]) {
|
|
266
|
-
return TipsMap[ruleTipsKey].tips
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
return rule.ruleDesc
|
|
276
|
+
return getCustomTips(rule.ruleDesc)
|
|
270
277
|
}
|
|
271
278
|
return ['WEBX_EXCLUSION_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
272
279
|
}
|
|
@@ -290,13 +297,7 @@ function IsStringOk(fCfgItem, paramValue) {
|
|
|
290
297
|
}
|
|
291
298
|
if (!isPass) {
|
|
292
299
|
if (rule.ruleDesc) {
|
|
293
|
-
|
|
294
|
-
let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
|
|
295
|
-
if (TipsMap[ruleTipsKey]) {
|
|
296
|
-
return TipsMap[ruleTipsKey].tips
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
return rule.ruleDesc
|
|
300
|
+
return getCustomTips(rule.ruleDesc)
|
|
300
301
|
}
|
|
301
302
|
if (rule.isMatched === 1) {
|
|
302
303
|
return ['WEBX_WRONG_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
@@ -325,13 +326,7 @@ function IsStringOk(fCfgItem, paramValue) {
|
|
|
325
326
|
}
|
|
326
327
|
if (!isPass) {
|
|
327
328
|
if (rule.ruleDesc) {
|
|
328
|
-
|
|
329
|
-
let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
|
|
330
|
-
if (TipsMap[ruleTipsKey]) {
|
|
331
|
-
return TipsMap[ruleTipsKey].tips
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
return rule.ruleDesc
|
|
329
|
+
return getCustomTips(rule.ruleDesc)
|
|
335
330
|
}
|
|
336
331
|
return ['WEBX_WRONG_REGEX_VALUE', fCfgItem.fieldUrl, exprVal]
|
|
337
332
|
}
|
|
@@ -356,13 +351,7 @@ function IsIntOk(fCfgItem, paramValue) {
|
|
|
356
351
|
|
|
357
352
|
if (paramValue == undefined || typeof paramValue != 'number') {
|
|
358
353
|
if (fCfgItem.nullTips) {
|
|
359
|
-
|
|
360
|
-
let nullTipsKey = fCfgItem.nullTips.substring(2, fCfgItem.nullTips.length -1)
|
|
361
|
-
if (TipsMap[nullTipsKey]) {
|
|
362
|
-
return TipsMap[nullTipsKey].tips
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
return fCfgItem.nullTips
|
|
354
|
+
return getCustomTips(fCfgItem.nullTips)
|
|
366
355
|
}
|
|
367
356
|
return ['WEBX_NULL_FIELD', 'number', fCfgItem.fieldUrl]
|
|
368
357
|
}
|
|
@@ -386,13 +375,7 @@ function IsIntOk(fCfgItem, paramValue) {
|
|
|
386
375
|
|
|
387
376
|
if (!isPass) {
|
|
388
377
|
if (rule.ruleDesc) {
|
|
389
|
-
|
|
390
|
-
let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
|
|
391
|
-
if (TipsMap[ruleTipsKey]) {
|
|
392
|
-
return TipsMap[ruleTipsKey].tips
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
return rule.ruleDesc
|
|
378
|
+
return getCustomTips(rule.ruleDesc)
|
|
396
379
|
}
|
|
397
380
|
return ['WEBX_WRONG_RANGE', fCfgItem.fieldUrl, JSON.stringify(rule.exprVal)]
|
|
398
381
|
}
|
|
@@ -401,26 +384,14 @@ function IsIntOk(fCfgItem, paramValue) {
|
|
|
401
384
|
if (rule.isMatched === 1) {
|
|
402
385
|
if (!rule.exprVal.includes(paramValue)) {
|
|
403
386
|
if (rule.ruleDesc) {
|
|
404
|
-
|
|
405
|
-
let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
|
|
406
|
-
if (TipsMap[ruleTipsKey]) {
|
|
407
|
-
return TipsMap[ruleTipsKey].tips
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
return rule.ruleDesc
|
|
387
|
+
return getCustomTips(rule.ruleDesc)
|
|
411
388
|
}
|
|
412
389
|
return ['WEBX_WRONG_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
413
390
|
}
|
|
414
391
|
} else {
|
|
415
392
|
if (rule.exprVal.includes(paramValue)) {
|
|
416
393
|
if (rule.ruleDesc) {
|
|
417
|
-
|
|
418
|
-
let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
|
|
419
|
-
if (TipsMap[ruleTipsKey]) {
|
|
420
|
-
return TipsMap[ruleTipsKey].tips
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
return rule.ruleDesc
|
|
394
|
+
return getCustomTips(rule.ruleDesc)
|
|
424
395
|
}
|
|
425
396
|
return ['WEBX_EXCLUSION_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
426
397
|
}
|
|
@@ -446,13 +417,7 @@ function IsIntOk(fCfgItem, paramValue) {
|
|
|
446
417
|
}
|
|
447
418
|
if (!isPass) {
|
|
448
419
|
if (rule.ruleDesc) {
|
|
449
|
-
|
|
450
|
-
let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
|
|
451
|
-
if (TipsMap[ruleTipsKey]) {
|
|
452
|
-
return TipsMap[ruleTipsKey].tips
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
return rule.ruleDesc
|
|
420
|
+
return getCustomTips(rule.ruleDesc)
|
|
456
421
|
}
|
|
457
422
|
return ['WEBX_WRONG_REGEX_VALUE', fCfgItem.fieldUrl, exprVal]
|
|
458
423
|
}
|
|
@@ -475,15 +440,9 @@ function IsObjOk(fCfgItem, paramValue) {
|
|
|
475
440
|
return null
|
|
476
441
|
}
|
|
477
442
|
|
|
478
|
-
if (!paramValue || paramValue
|
|
443
|
+
if (!paramValue || typeof paramValue != 'object' || !Object.keys(paramValue).length || paramValue.length) {
|
|
479
444
|
if (fCfgItem.nullTips) {
|
|
480
|
-
|
|
481
|
-
let nullTipsKey = fCfgItem.nullTips.substring(2, fCfgItem.nullTips.length -1)
|
|
482
|
-
if (TipsMap[nullTipsKey]) {
|
|
483
|
-
return TipsMap[nullTipsKey].tips
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
return fCfgItem.nullTips
|
|
445
|
+
return getCustomTips(fCfgItem.nullTips)
|
|
487
446
|
}
|
|
488
447
|
return ['WEBX_NULL_FIELD', 'map', fCfgItem.fieldUrl]
|
|
489
448
|
}
|
|
@@ -508,13 +467,7 @@ function IsObjOk(fCfgItem, paramValue) {
|
|
|
508
467
|
|
|
509
468
|
if (!isPass) {
|
|
510
469
|
if (rule.ruleDesc) {
|
|
511
|
-
|
|
512
|
-
let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
|
|
513
|
-
if (TipsMap[ruleTipsKey]) {
|
|
514
|
-
return TipsMap[ruleTipsKey].tips
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
return rule.ruleDesc
|
|
470
|
+
return getCustomTips(rule.ruleDesc)
|
|
518
471
|
}
|
|
519
472
|
return ['WEBX_WRONG_RANGE', fCfgItem.fieldUrl, JSON.stringify(rule.exprVal)]
|
|
520
473
|
}
|
|
@@ -537,15 +490,9 @@ function IsListOk(fCfgItem, paramValue) {
|
|
|
537
490
|
return null
|
|
538
491
|
}
|
|
539
492
|
|
|
540
|
-
if (!paramValue || paramValue
|
|
493
|
+
if (!paramValue || typeof paramValue != 'object' || !paramValue.length) {
|
|
541
494
|
if (fCfgItem.nullTips) {
|
|
542
|
-
|
|
543
|
-
let nullTipsKey = fCfgItem.nullTips.substring(2, fCfgItem.nullTips.length -1)
|
|
544
|
-
if (TipsMap[nullTipsKey]) {
|
|
545
|
-
return TipsMap[nullTipsKey].tips
|
|
546
|
-
}
|
|
547
|
-
}
|
|
548
|
-
return fCfgItem.nullTips
|
|
495
|
+
return getCustomTips(fCfgItem.nullTips)
|
|
549
496
|
}
|
|
550
497
|
return ['WEBX_NULL_FIELD', 'list', fCfgItem.fieldUrl]
|
|
551
498
|
}
|
|
@@ -570,13 +517,7 @@ function IsListOk(fCfgItem, paramValue) {
|
|
|
570
517
|
|
|
571
518
|
if (!isPass) {
|
|
572
519
|
if (rule.ruleDesc) {
|
|
573
|
-
|
|
574
|
-
let ruleTipsKey = rule.ruleDesc.substring(2, rule.ruleDesc.length -1)
|
|
575
|
-
if (TipsMap[ruleTipsKey]) {
|
|
576
|
-
return TipsMap[ruleTipsKey].tips
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
return rule.ruleDesc
|
|
520
|
+
return getCustomTips(rule.ruleDesc)
|
|
580
521
|
}
|
|
581
522
|
return ['WEBX_WRONG_RANGE', fCfgItem.fieldUrl, JSON.stringify(rule.exprVal)]
|
|
582
523
|
}
|
|
@@ -595,4 +536,5 @@ module.exports = {
|
|
|
595
536
|
SetRoutes: SetRoutes,
|
|
596
537
|
CheckReq: CheckReq,
|
|
597
538
|
SetMsg: SetMsg,
|
|
539
|
+
SetIsCheckedRes: SetIsCheckedRes
|
|
598
540
|
}
|