xzwebx-httpfilter 2.2.6 → 2.2.7
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 +435 -407
- package/package.json +1 -1
package/HttpFilter.js
CHANGED
|
@@ -2,21 +2,55 @@ const Fs = require('fs')
|
|
|
2
2
|
const Util = require("util")
|
|
3
3
|
const Path = require('path')
|
|
4
4
|
|
|
5
|
-
let
|
|
6
|
-
let TipsMap = {}
|
|
7
|
-
let ModuleMap = {}
|
|
8
|
-
let ModuleInterfaceMap = {}
|
|
9
|
-
let FieldMap = {}
|
|
10
|
-
let IsCheckedRes = true
|
|
5
|
+
let ConfigMap = {}
|
|
11
6
|
let Fun = {}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
|
|
8
|
+
Fun.SetModuleMap = function(port, m) {
|
|
9
|
+
if (!ConfigMap[port]) {
|
|
10
|
+
ConfigMap[port] = new http()
|
|
11
|
+
}
|
|
12
|
+
ConfigMap[port].ModuleMap = m
|
|
13
|
+
}
|
|
14
|
+
Fun.SetModuleInterfaceMap = function(port, m) {
|
|
15
|
+
if (!ConfigMap[port]) {
|
|
16
|
+
ConfigMap[port] = new http()
|
|
17
|
+
}
|
|
18
|
+
ConfigMap[port].ModuleInterfaceMap = m
|
|
19
|
+
}
|
|
20
|
+
Fun.SetFieldMap = function(port, m) {
|
|
21
|
+
if (!ConfigMap[port]) {
|
|
22
|
+
ConfigMap[port] = new http()
|
|
23
|
+
}
|
|
24
|
+
ConfigMap[port].FieldMap = m
|
|
25
|
+
}
|
|
26
|
+
Fun.SetResultCodeMap = function(port, m) {
|
|
27
|
+
if (!ConfigMap[port]) {
|
|
28
|
+
ConfigMap[port] = new http()
|
|
29
|
+
}
|
|
30
|
+
ConfigMap[port].ResultCodeMap = m
|
|
31
|
+
}
|
|
32
|
+
Fun.SetTipsMap = function(port, m) {
|
|
33
|
+
if (!ConfigMap[port]) {
|
|
34
|
+
ConfigMap[port] = new http()
|
|
35
|
+
}
|
|
36
|
+
ConfigMap[port].TipsMap = m
|
|
37
|
+
}
|
|
38
|
+
Fun.SetIsCheckedRes = function(port, isCheckedRes) {
|
|
39
|
+
if (!ConfigMap[port]) {
|
|
40
|
+
ConfigMap[port] = new http()
|
|
41
|
+
}
|
|
42
|
+
ConfigMap[port].IsCheckedRes = isCheckedRes
|
|
43
|
+
}
|
|
44
|
+
Fun.SetFirstFilter = function(app) {
|
|
45
|
+
let p = ConfigMap[app.get('_PORT_')]
|
|
46
|
+
app.use(p.setMsg.bind(p))
|
|
47
|
+
app.use(p.checkUrl.bind(p))
|
|
48
|
+
app.use(p.checkReq.bind(p))
|
|
18
49
|
}
|
|
19
50
|
Fun.SetRoutes = function(app, express, projectPath) {
|
|
51
|
+
const port = app.get('_PORT_')
|
|
52
|
+
let ModuleMap = ConfigMap[port].ModuleMap
|
|
53
|
+
let ModuleInterfaceMap = ConfigMap[port].ModuleInterfaceMap
|
|
20
54
|
for (let uri in ModuleMap) {
|
|
21
55
|
let module = ModuleMap[uri]
|
|
22
56
|
let router = express.Router()
|
|
@@ -32,7 +66,7 @@ Fun.SetRoutes = function(app, express, projectPath) {
|
|
|
32
66
|
if (subUri[0] != '/') {
|
|
33
67
|
subUri = '/' + subUri
|
|
34
68
|
}
|
|
35
|
-
router[method.toLowerCase()](subUri, ModuleHandle && ModuleHandle[api.moduleFun]? ModuleHandle[api.moduleFun]:
|
|
69
|
+
router[method.toLowerCase()](subUri, ModuleHandle && ModuleHandle[api.moduleFun]? ModuleHandle[api.moduleFun]: webCommResponse)
|
|
36
70
|
}
|
|
37
71
|
}
|
|
38
72
|
if (ModuleMap[uri].uri[0] != '/') {
|
|
@@ -41,497 +75,491 @@ Fun.SetRoutes = function(app, express, projectPath) {
|
|
|
41
75
|
app.use(ModuleMap[uri].uri, router)
|
|
42
76
|
}
|
|
43
77
|
}
|
|
44
|
-
Fun.CheckUrl = function(req, res, next) {
|
|
45
|
-
const baseUrlList = req.url.split('/')
|
|
46
|
-
const subUri = baseUrlList[baseUrlList.length - 1]
|
|
47
|
-
let baseUrl = ''
|
|
48
|
-
for (let idx in baseUrlList) {
|
|
49
|
-
if (idx == baseUrlList.length - 1) {
|
|
50
|
-
break
|
|
51
|
-
}
|
|
52
|
-
if (baseUrlList[idx]) {
|
|
53
|
-
baseUrl += '/' + baseUrlList[idx]
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const module = ModuleMap[baseUrl]
|
|
58
|
-
if (!module) {
|
|
59
|
-
return res.Msg({codeKey: 'CLT_ERR', msg: ['WEBX_ERR_URL']})
|
|
60
|
-
}
|
|
61
78
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
79
|
+
class http {
|
|
80
|
+
constructor(){
|
|
81
|
+
this.ModuleMap = {}
|
|
82
|
+
this.ModuleInterfaceMap = {}
|
|
83
|
+
this.FieldMap = {}
|
|
84
|
+
this.ResultCodeMap = {}
|
|
85
|
+
this.TipsMap = {}
|
|
86
|
+
this.IsCheckedRes = false
|
|
66
87
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
88
|
+
checkUrl(req, res, next) {
|
|
89
|
+
const baseUrlList = req.url.split('/')
|
|
90
|
+
const subUri = baseUrlList[baseUrlList.length - 1]
|
|
91
|
+
let baseUrl = ''
|
|
92
|
+
for (let idx in baseUrlList) {
|
|
93
|
+
if (idx == baseUrlList.length - 1) {
|
|
94
|
+
break
|
|
95
|
+
}
|
|
96
|
+
if (baseUrlList[idx]) {
|
|
97
|
+
baseUrl += '/' + baseUrlList[idx]
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const module = this.ModuleMap[baseUrl]
|
|
102
|
+
if (!module) {
|
|
103
|
+
return res.Msg({codeKey: 'CLT_ERR', msg: ['WEBX_ERR_URL']})
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!this.ModuleInterfaceMap[module.id] ||
|
|
107
|
+
!this.ModuleInterfaceMap[module.id][subUri] ||
|
|
108
|
+
!this.ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()]) {
|
|
109
|
+
return res.Msg({codeKey: 'CLT_ERR', msg: ['WEBX_ERR_URL']})
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
req.interfaceInfo = this.ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()]
|
|
113
|
+
res.interfaceInfo = this.ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()]
|
|
75
114
|
return next()
|
|
76
115
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return res.Msg({codeKey: 'CLT_ERR', msg: retMsgData})
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return next()
|
|
84
|
-
}
|
|
85
|
-
Fun.SetMsg = function(req, res, next) {
|
|
86
|
-
res.Msg = MSG
|
|
87
|
-
return next()
|
|
88
|
-
}
|
|
89
|
-
Fun.SetIsCheckedRes = function(isCheckedRes) {
|
|
90
|
-
if (isCheckedRes) {
|
|
91
|
-
IsCheckedRes = true
|
|
92
|
-
} else {
|
|
93
|
-
IsCheckedRes = false
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async function response(req, res, next) {
|
|
98
|
-
let retData = {
|
|
99
|
-
codeKey: 'SUCC',
|
|
100
|
-
data: []
|
|
116
|
+
setMsg(req, res, next) {
|
|
117
|
+
res.Msg = response
|
|
118
|
+
return next()
|
|
101
119
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
let retMsgData = cycleCheckParams(FieldMap[this.interfaceInfo.rspMsgId], params.data)
|
|
120
|
+
checkReq(req, res, next) {
|
|
121
|
+
let reqMsgId = req.interfaceInfo.reqMsgId
|
|
122
|
+
if (!reqMsgId) {
|
|
123
|
+
return next()
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
let retMsgData = this.cycleCheckParams(this.FieldMap[reqMsgId], req.body)
|
|
110
127
|
if (retMsgData) {
|
|
111
|
-
|
|
112
|
-
params.msg = retMsgData
|
|
128
|
+
return res.Msg({codeKey: 'CLT_ERR', msg: retMsgData})
|
|
113
129
|
}
|
|
130
|
+
|
|
131
|
+
return next()
|
|
114
132
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
let msg = ''
|
|
121
|
-
if (!params.msg) {
|
|
122
|
-
if (TipsMap[params.codeKey]) {
|
|
123
|
-
msg = TipsMap[params.codeKey].tips
|
|
124
|
-
} else {
|
|
125
|
-
msg = ResultCodeMap[params.codeKey].codeDesc
|
|
133
|
+
cycleCheckParams(msgFieldMap, data) {
|
|
134
|
+
let retMsgData = null
|
|
135
|
+
|
|
136
|
+
if (!msgFieldMap) {
|
|
137
|
+
return null
|
|
126
138
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
139
|
+
|
|
140
|
+
let fCfgItem = null
|
|
141
|
+
let isRoot = true
|
|
142
|
+
if (msgFieldMap['__FieldCfg']) {
|
|
143
|
+
isRoot = false
|
|
144
|
+
fCfgItem = msgFieldMap['__FieldCfg']
|
|
130
145
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
if (
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
146
|
+
|
|
147
|
+
for (let fieldName in msgFieldMap) {
|
|
148
|
+
if (isRoot) {
|
|
149
|
+
fCfgItem = msgFieldMap[fieldName]['__FieldCfg']
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (fCfgItem.fieldType == 'STR') {
|
|
153
|
+
retMsgData = this.isStringOk(fCfgItem, data)
|
|
154
|
+
} else if (fCfgItem.fieldType == 'INT') {
|
|
155
|
+
retMsgData = this.isIntOk(fCfgItem, data)
|
|
156
|
+
} else if (fCfgItem.fieldType == 'OBJ') {
|
|
157
|
+
retMsgData = this.isObjOk(fCfgItem, data)
|
|
158
|
+
} else if (fCfgItem.fieldType == 'LIST') {
|
|
159
|
+
retMsgData = this.isListOk(fCfgItem, data)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (retMsgData) {
|
|
163
|
+
return retMsgData
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (fieldName == '__FieldCfg') {
|
|
167
|
+
continue
|
|
168
|
+
}
|
|
169
|
+
let fatherFieldType = fCfgItem.fieldType
|
|
170
|
+
if (fatherFieldType == 'LIST' || (fatherFieldType == 'OBJ' && fCfgItem.keyType == 'VOBJ')) {
|
|
171
|
+
if (isRoot) {
|
|
172
|
+
retMsgData = this.cycleCheckParams(msgFieldMap[fieldName], data)
|
|
173
|
+
} else {
|
|
174
|
+
for (let idx in data) {
|
|
175
|
+
retMsgData = this.cycleCheckParams(msgFieldMap[fieldName], data[idx])
|
|
176
|
+
if (retMsgData) {
|
|
177
|
+
return retMsgData
|
|
178
|
+
}
|
|
138
179
|
}
|
|
139
180
|
}
|
|
140
181
|
} else {
|
|
141
|
-
|
|
182
|
+
if (isRoot) {
|
|
183
|
+
retMsgData = this.cycleCheckParams(msgFieldMap[fieldName], data)
|
|
184
|
+
} else {
|
|
185
|
+
retMsgData = this.cycleCheckParams(msgFieldMap[fieldName], data[fieldName])
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (retMsgData) {
|
|
190
|
+
return retMsgData
|
|
142
191
|
}
|
|
143
192
|
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return this.send(
|
|
147
|
-
{
|
|
148
|
-
code: code,
|
|
149
|
-
msg: msg,
|
|
150
|
-
data: params.data
|
|
151
|
-
}
|
|
152
|
-
)
|
|
153
|
-
}
|
|
154
|
-
function cycleCheckParams(msgFieldMap, data) {
|
|
155
|
-
let retMsgData = null
|
|
156
|
-
|
|
157
|
-
if (!msgFieldMap) {
|
|
158
193
|
return null
|
|
159
194
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
if (msgFieldMap['__FieldCfg']) {
|
|
164
|
-
isRoot = false
|
|
165
|
-
fCfgItem = msgFieldMap['__FieldCfg']
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
for (let fieldName in msgFieldMap) {
|
|
169
|
-
if (isRoot) {
|
|
170
|
-
fCfgItem = msgFieldMap[fieldName]['__FieldCfg']
|
|
195
|
+
isStringOk(fCfgItem, paramValue) {
|
|
196
|
+
if (!fCfgItem || !fCfgItem.ifMust) {
|
|
197
|
+
return null
|
|
171
198
|
}
|
|
172
|
-
|
|
173
|
-
if (fCfgItem.
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
retMsgData = IsListOk(fCfgItem, data)
|
|
199
|
+
|
|
200
|
+
if (fCfgItem.ifMust == 'NO' && (
|
|
201
|
+
paramValue == undefined ||
|
|
202
|
+
paramValue == null ||
|
|
203
|
+
paramValue == '' ||
|
|
204
|
+
(typeof paramValue === 'object' && !paramValue.length && !Object.keys(paramValue).length))
|
|
205
|
+
) {
|
|
206
|
+
return null
|
|
181
207
|
}
|
|
182
|
-
|
|
183
|
-
if (
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
continue
|
|
208
|
+
|
|
209
|
+
if (!paramValue || typeof paramValue != 'string') {
|
|
210
|
+
if (fCfgItem.nullTips) {
|
|
211
|
+
return this.getCustomTips(fCfgItem.nullTips)
|
|
212
|
+
}
|
|
213
|
+
return ['WEBX_NULL_FIELD', 'string', fCfgItem.fieldUrl]
|
|
189
214
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
215
|
+
|
|
216
|
+
for (let idx in fCfgItem.rules) {
|
|
217
|
+
let rule = fCfgItem.rules[idx]
|
|
218
|
+
if (rule.checkType == 'RANGE') {
|
|
219
|
+
let isPass = false
|
|
220
|
+
if (typeof rule.exprVal[0] == 'object') {
|
|
221
|
+
for (let i in rule.exprVal) {
|
|
222
|
+
if (paramValue.length >= parseInt(rule.exprVal[i][0]) && paramValue.length <= parseInt(rule.exprVal[i][1])) {
|
|
223
|
+
isPass = true
|
|
224
|
+
break
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
} else {
|
|
228
|
+
if (paramValue.length >= parseInt(rule.exprVal[0]) && paramValue.length <= parseInt(rule.exprVal[1])) {
|
|
229
|
+
isPass = true
|
|
199
230
|
}
|
|
200
231
|
}
|
|
232
|
+
|
|
233
|
+
if (!isPass) {
|
|
234
|
+
if (rule.ruleDesc) {
|
|
235
|
+
return this.getCustomTips(rule.ruleDesc)
|
|
236
|
+
}
|
|
237
|
+
return ['WEBX_WRONG_RANGE', fCfgItem.fieldUrl, JSON.stringify(rule.exprVal)]
|
|
238
|
+
}
|
|
239
|
+
} else if (rule.checkType == 'ENU') {
|
|
240
|
+
if (rule.isCaseSensitive == 1) {
|
|
241
|
+
if (rule.exprVal && rule.exprVal.length) {
|
|
242
|
+
if (rule.isMatched === 1) {
|
|
243
|
+
if (!rule.exprVal.includes(paramValue)) {
|
|
244
|
+
if (rule.ruleDesc) {
|
|
245
|
+
return this.getCustomTips(rule.ruleDesc)
|
|
246
|
+
}
|
|
247
|
+
return ['WEBX_WRONG_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
250
|
+
if (rule.exprVal.includes(paramValue)) {
|
|
251
|
+
if (rule.ruleDesc) {
|
|
252
|
+
return this.getCustomTips(rule.ruleDesc)
|
|
253
|
+
}
|
|
254
|
+
return ['WEBX_EXCLUSION_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
let isPass = false
|
|
260
|
+
for (let k in rule.exprVal) {
|
|
261
|
+
if (rule.isMatched === 1) {
|
|
262
|
+
if (rule.exprVal[k].toUpperCase() === paramValue.toUpperCase()) {
|
|
263
|
+
isPass = true
|
|
264
|
+
break
|
|
265
|
+
}
|
|
266
|
+
} else {
|
|
267
|
+
isPass = true
|
|
268
|
+
if (rule.exprVal[k].toUpperCase() == paramValue.toUpperCase()) {
|
|
269
|
+
isPass = false
|
|
270
|
+
break
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
if (!isPass) {
|
|
275
|
+
if (rule.ruleDesc) {
|
|
276
|
+
return this.getCustomTips(rule.ruleDesc)
|
|
277
|
+
}
|
|
278
|
+
if (rule.isMatched === 1) {
|
|
279
|
+
return ['WEBX_WRONG_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
280
|
+
} else {
|
|
281
|
+
return ['WEBX_EXCLUSION_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
} else if (rule.checkType == 'REGEX') {
|
|
286
|
+
let isPass = false
|
|
287
|
+
let exprVal = rule.exprVal + ''
|
|
288
|
+
for (let i in rule.exprVal) {
|
|
289
|
+
let reg = eval(rule.exprVal[i])
|
|
290
|
+
let found = reg.test(paramValue)
|
|
291
|
+
if (rule.matchType == 'AND') {
|
|
292
|
+
if (!found) {
|
|
293
|
+
exprVal = rule.exprVal[i] + ''
|
|
294
|
+
break
|
|
295
|
+
}
|
|
296
|
+
} else {
|
|
297
|
+
if (found) {
|
|
298
|
+
isPass = true
|
|
299
|
+
break
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
if (!isPass) {
|
|
304
|
+
if (rule.ruleDesc) {
|
|
305
|
+
return this.getCustomTips(rule.ruleDesc)
|
|
306
|
+
}
|
|
307
|
+
return ['WEBX_WRONG_REGEX_VALUE', fCfgItem.fieldUrl, exprVal]
|
|
308
|
+
}
|
|
201
309
|
}
|
|
202
|
-
} else {
|
|
203
|
-
if (isRoot) {
|
|
204
|
-
retMsgData = cycleCheckParams(msgFieldMap[fieldName], data)
|
|
205
|
-
} else {
|
|
206
|
-
retMsgData = cycleCheckParams(msgFieldMap[fieldName], data[fieldName])
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
if (retMsgData) {
|
|
211
|
-
return retMsgData
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return null
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
function getCustomTips(tips) {
|
|
218
|
-
if (tips.length > 3 && tips.substring(0, 2) === '${' && tips.substring(tips.length -1, tips.length) === '}') {
|
|
219
|
-
let tipsKey = tips.substring(2, tips.length -1)
|
|
220
|
-
tipsKey = tipsKey.trim()
|
|
221
|
-
if (TipsMap[tipsKey]) {
|
|
222
|
-
return TipsMap[tipsKey].tips
|
|
223
310
|
}
|
|
224
|
-
|
|
225
|
-
return tips
|
|
226
|
-
}
|
|
227
|
-
function IsStringOk(fCfgItem, paramValue) {
|
|
228
|
-
if (!fCfgItem || !fCfgItem.ifMust) {
|
|
229
|
-
return null
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
if (fCfgItem.ifMust == 'NO' && (
|
|
233
|
-
paramValue == undefined ||
|
|
234
|
-
paramValue == null ||
|
|
235
|
-
paramValue == '' ||
|
|
236
|
-
(typeof paramValue === 'object' && !paramValue.length && !Object.keys(paramValue).length))
|
|
237
|
-
) {
|
|
311
|
+
|
|
238
312
|
return null
|
|
239
313
|
}
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
return getCustomTips(fCfgItem.nullTips)
|
|
314
|
+
isIntOk(fCfgItem, paramValue) {
|
|
315
|
+
if (!fCfgItem || !fCfgItem.ifMust) {
|
|
316
|
+
return null
|
|
244
317
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
318
|
+
|
|
319
|
+
if (fCfgItem.ifMust == 'NO' && (
|
|
320
|
+
paramValue == undefined ||
|
|
321
|
+
paramValue == null ||
|
|
322
|
+
paramValue == '' ||
|
|
323
|
+
(typeof paramValue === 'object' && !paramValue.length && !Object.keys(paramValue).length))
|
|
324
|
+
) {
|
|
325
|
+
return null
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (paramValue == undefined || typeof paramValue != 'number') {
|
|
329
|
+
if (fCfgItem.nullTips) {
|
|
330
|
+
return this.getCustomTips(fCfgItem.nullTips)
|
|
331
|
+
}
|
|
332
|
+
return ['WEBX_NULL_FIELD', 'number', fCfgItem.fieldUrl]
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
for (let idx in fCfgItem.rules) {
|
|
336
|
+
let rule = fCfgItem.rules[idx]
|
|
337
|
+
if (rule.checkType == 'RANGE') {
|
|
338
|
+
let isPass = false
|
|
339
|
+
if (typeof rule.exprVal[0] == 'object') {
|
|
340
|
+
for (let i in rule.exprVal) {
|
|
341
|
+
if (paramValue >= +rule.exprVal[i][0] && paramValue <= +rule.exprVal[i][1]) {
|
|
342
|
+
isPass = true
|
|
343
|
+
break
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
} else {
|
|
347
|
+
if (+rule.exprVal[0] <= paramValue && +rule.exprVal[1] >= paramValue) {
|
|
255
348
|
isPass = true
|
|
256
|
-
break
|
|
257
349
|
}
|
|
258
350
|
}
|
|
259
|
-
|
|
260
|
-
if (
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
if (!isPass) {
|
|
266
|
-
if (rule.ruleDesc) {
|
|
267
|
-
return getCustomTips(rule.ruleDesc)
|
|
351
|
+
|
|
352
|
+
if (!isPass) {
|
|
353
|
+
if (rule.ruleDesc) {
|
|
354
|
+
return this.getCustomTips(rule.ruleDesc)
|
|
355
|
+
}
|
|
356
|
+
return ['WEBX_WRONG_RANGE', fCfgItem.fieldUrl, JSON.stringify(rule.exprVal)]
|
|
268
357
|
}
|
|
269
|
-
|
|
270
|
-
}
|
|
271
|
-
} else if (rule.checkType == 'ENU') {
|
|
272
|
-
if (rule.isCaseSensitive == 1) {
|
|
358
|
+
} else if (rule.checkType == 'ENU') {
|
|
273
359
|
if (rule.exprVal && rule.exprVal.length) {
|
|
274
360
|
if (rule.isMatched === 1) {
|
|
275
361
|
if (!rule.exprVal.includes(paramValue)) {
|
|
276
362
|
if (rule.ruleDesc) {
|
|
277
|
-
return getCustomTips(rule.ruleDesc)
|
|
363
|
+
return this.getCustomTips(rule.ruleDesc)
|
|
278
364
|
}
|
|
279
365
|
return ['WEBX_WRONG_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
280
366
|
}
|
|
281
367
|
} else {
|
|
282
368
|
if (rule.exprVal.includes(paramValue)) {
|
|
283
369
|
if (rule.ruleDesc) {
|
|
284
|
-
return getCustomTips(rule.ruleDesc)
|
|
370
|
+
return this.getCustomTips(rule.ruleDesc)
|
|
285
371
|
}
|
|
286
372
|
return ['WEBX_EXCLUSION_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
287
373
|
}
|
|
288
374
|
}
|
|
289
375
|
}
|
|
290
|
-
} else {
|
|
376
|
+
} else if (rule.checkType == 'REGEX') {
|
|
291
377
|
let isPass = false
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
378
|
+
let exprVal = rule.exprVal + ''
|
|
379
|
+
for (let i in rule.exprVal) {
|
|
380
|
+
let reg = eval(rule.exprVal[i])
|
|
381
|
+
let found = reg.test(paramValue + '')
|
|
382
|
+
if (rule.matchType == 'AND') {
|
|
383
|
+
if (!found) {
|
|
384
|
+
exprVal = rule.exprVal[i] + ''
|
|
296
385
|
break
|
|
297
386
|
}
|
|
298
387
|
} else {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
isPass = false
|
|
388
|
+
if (found) {
|
|
389
|
+
isPass = true
|
|
302
390
|
break
|
|
303
391
|
}
|
|
304
392
|
}
|
|
305
393
|
}
|
|
306
394
|
if (!isPass) {
|
|
307
395
|
if (rule.ruleDesc) {
|
|
308
|
-
return getCustomTips(rule.ruleDesc)
|
|
309
|
-
}
|
|
310
|
-
if (rule.isMatched === 1) {
|
|
311
|
-
return ['WEBX_WRONG_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
312
|
-
} else {
|
|
313
|
-
return ['WEBX_EXCLUSION_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
396
|
+
return this.getCustomTips(rule.ruleDesc)
|
|
314
397
|
}
|
|
398
|
+
return ['WEBX_WRONG_REGEX_VALUE', fCfgItem.fieldUrl, exprVal]
|
|
315
399
|
}
|
|
316
400
|
}
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
return null
|
|
404
|
+
}
|
|
405
|
+
isObjOk(fCfgItem, paramValue) {
|
|
406
|
+
if (!fCfgItem || !fCfgItem.ifMust) {
|
|
407
|
+
return null
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if (fCfgItem.ifMust == 'NO' && (
|
|
411
|
+
paramValue == undefined ||
|
|
412
|
+
paramValue == null ||
|
|
413
|
+
paramValue == '' ||
|
|
414
|
+
(typeof paramValue === 'object' && !paramValue.length && !Object.keys(paramValue).length))
|
|
415
|
+
) {
|
|
416
|
+
return null
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (!paramValue || typeof paramValue != 'object' || !Object.keys(paramValue).length || paramValue.length) {
|
|
420
|
+
if (fCfgItem.nullTips) {
|
|
421
|
+
return this.getCustomTips(fCfgItem.nullTips)
|
|
422
|
+
}
|
|
423
|
+
return ['WEBX_NULL_FIELD', 'map', fCfgItem.fieldUrl]
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
let length = Object.keys(paramValue).length
|
|
427
|
+
for (let idx in fCfgItem.rules) {
|
|
428
|
+
let rule = fCfgItem.rules[idx]
|
|
429
|
+
if (rule.checkType == 'RANGE') {
|
|
430
|
+
let isPass = false
|
|
431
|
+
if (typeof rule.exprVal[0] == 'object') {
|
|
432
|
+
for (let i in rule.exprVal) {
|
|
433
|
+
if (length >= parseInt(rule.exprVal[i][0]) && length <= parseInt(rule.exprVal[i][1])) {
|
|
434
|
+
isPass = true
|
|
435
|
+
break
|
|
436
|
+
}
|
|
327
437
|
}
|
|
328
438
|
} else {
|
|
329
|
-
if (
|
|
439
|
+
if (length >= parseInt(rule.exprVal[0]) && length <= parseInt(rule.exprVal[1])) {
|
|
330
440
|
isPass = true
|
|
331
|
-
break
|
|
332
441
|
}
|
|
333
442
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
443
|
+
|
|
444
|
+
if (!isPass) {
|
|
445
|
+
if (rule.ruleDesc) {
|
|
446
|
+
return this.getCustomTips(rule.ruleDesc)
|
|
447
|
+
}
|
|
448
|
+
return ['WEBX_WRONG_RANGE', fCfgItem.fieldUrl, JSON.stringify(rule.exprVal)]
|
|
338
449
|
}
|
|
339
|
-
return ['WEBX_WRONG_REGEX_VALUE', fCfgItem.fieldUrl, exprVal]
|
|
340
450
|
}
|
|
341
451
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
return null
|
|
345
|
-
}
|
|
346
|
-
function IsIntOk(fCfgItem, paramValue) {
|
|
347
|
-
if (!fCfgItem || !fCfgItem.ifMust) {
|
|
452
|
+
|
|
348
453
|
return null
|
|
349
454
|
}
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
paramValue == null ||
|
|
354
|
-
paramValue == '' ||
|
|
355
|
-
(typeof paramValue === 'object' && !paramValue.length && !Object.keys(paramValue).length))
|
|
356
|
-
) {
|
|
357
|
-
return null
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
if (paramValue == undefined || typeof paramValue != 'number') {
|
|
361
|
-
if (fCfgItem.nullTips) {
|
|
362
|
-
return getCustomTips(fCfgItem.nullTips)
|
|
455
|
+
isListOk(fCfgItem, paramValue) {
|
|
456
|
+
if (!fCfgItem || !fCfgItem.ifMust) {
|
|
457
|
+
return null
|
|
363
458
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
}
|
|
378
|
-
} else {
|
|
379
|
-
if (+rule.exprVal[0] <= paramValue && +rule.exprVal[1] >= paramValue) {
|
|
380
|
-
isPass = true
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
if (!isPass) {
|
|
385
|
-
if (rule.ruleDesc) {
|
|
386
|
-
return getCustomTips(rule.ruleDesc)
|
|
387
|
-
}
|
|
388
|
-
return ['WEBX_WRONG_RANGE', fCfgItem.fieldUrl, JSON.stringify(rule.exprVal)]
|
|
459
|
+
|
|
460
|
+
if (fCfgItem.ifMust == 'NO' && (
|
|
461
|
+
paramValue == undefined ||
|
|
462
|
+
paramValue == null ||
|
|
463
|
+
paramValue == '' ||
|
|
464
|
+
(typeof paramValue === 'object' && !paramValue.length && !Object.keys(paramValue).length))
|
|
465
|
+
) {
|
|
466
|
+
return null
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
if (!paramValue || typeof paramValue != 'object' || !paramValue.length) {
|
|
470
|
+
if (fCfgItem.nullTips) {
|
|
471
|
+
return this.getCustomTips(fCfgItem.nullTips)
|
|
389
472
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
473
|
+
return ['WEBX_NULL_FIELD', 'list', fCfgItem.fieldUrl]
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
let length = paramValue.length
|
|
477
|
+
for (let idx in fCfgItem.rules) {
|
|
478
|
+
let rule = fCfgItem.rules[idx]
|
|
479
|
+
if (rule.checkType == 'RANGE') {
|
|
480
|
+
let isPass = false
|
|
481
|
+
if (typeof rule.exprVal[0] == 'object') {
|
|
482
|
+
for (let i in rule.exprVal) {
|
|
483
|
+
if (length >= parseInt(rule.exprVal[i][0]) && length <= parseInt(rule.exprVal[i][1])) {
|
|
484
|
+
isPass = true
|
|
485
|
+
break
|
|
396
486
|
}
|
|
397
|
-
return ['WEBX_WRONG_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
398
487
|
}
|
|
399
488
|
} else {
|
|
400
|
-
if (rule.exprVal.
|
|
401
|
-
if (rule.ruleDesc) {
|
|
402
|
-
return getCustomTips(rule.ruleDesc)
|
|
403
|
-
}
|
|
404
|
-
return ['WEBX_EXCLUSION_ENU_VALUE', fCfgItem.fieldUrl, rule.exprVal]
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
} else if (rule.checkType == 'REGEX') {
|
|
409
|
-
let isPass = false
|
|
410
|
-
let exprVal = rule.exprVal + ''
|
|
411
|
-
for (let i in rule.exprVal) {
|
|
412
|
-
let reg = eval(rule.exprVal[i])
|
|
413
|
-
let found = reg.test(paramValue + '')
|
|
414
|
-
if (rule.matchType == 'AND') {
|
|
415
|
-
if (!found) {
|
|
416
|
-
exprVal = rule.exprVal[i] + ''
|
|
417
|
-
break
|
|
418
|
-
}
|
|
419
|
-
} else {
|
|
420
|
-
if (found) {
|
|
489
|
+
if (length >= parseInt(rule.exprVal[0]) && length <= parseInt(rule.exprVal[1])) {
|
|
421
490
|
isPass = true
|
|
422
|
-
break
|
|
423
491
|
}
|
|
424
492
|
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
493
|
+
|
|
494
|
+
if (!isPass) {
|
|
495
|
+
if (rule.ruleDesc) {
|
|
496
|
+
return this.getCustomTips(rule.ruleDesc)
|
|
497
|
+
}
|
|
498
|
+
return ['WEBX_WRONG_RANGE', fCfgItem.fieldUrl, JSON.stringify(rule.exprVal)]
|
|
429
499
|
}
|
|
430
|
-
return ['WEBX_WRONG_REGEX_VALUE', fCfgItem.fieldUrl, exprVal]
|
|
431
500
|
}
|
|
432
501
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
return null
|
|
436
|
-
}
|
|
437
|
-
function IsObjOk(fCfgItem, paramValue) {
|
|
438
|
-
if (!fCfgItem || !fCfgItem.ifMust) {
|
|
439
|
-
return null
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
if (fCfgItem.ifMust == 'NO' && (
|
|
443
|
-
paramValue == undefined ||
|
|
444
|
-
paramValue == null ||
|
|
445
|
-
paramValue == '' ||
|
|
446
|
-
(typeof paramValue === 'object' && !paramValue.length && !Object.keys(paramValue).length))
|
|
447
|
-
) {
|
|
502
|
+
|
|
448
503
|
return null
|
|
449
504
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
let length = Object.keys(paramValue).length
|
|
459
|
-
for (let idx in fCfgItem.rules) {
|
|
460
|
-
let rule = fCfgItem.rules[idx]
|
|
461
|
-
if (rule.checkType == 'RANGE') {
|
|
462
|
-
let isPass = false
|
|
463
|
-
if (typeof rule.exprVal[0] == 'object') {
|
|
464
|
-
for (let i in rule.exprVal) {
|
|
465
|
-
if (length >= parseInt(rule.exprVal[i][0]) && length <= parseInt(rule.exprVal[i][1])) {
|
|
466
|
-
isPass = true
|
|
467
|
-
break
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
} else {
|
|
471
|
-
if (length >= parseInt(rule.exprVal[0]) && length <= parseInt(rule.exprVal[1])) {
|
|
472
|
-
isPass = true
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
if (!isPass) {
|
|
477
|
-
if (rule.ruleDesc) {
|
|
478
|
-
return getCustomTips(rule.ruleDesc)
|
|
479
|
-
}
|
|
480
|
-
return ['WEBX_WRONG_RANGE', fCfgItem.fieldUrl, JSON.stringify(rule.exprVal)]
|
|
505
|
+
getCustomTips(tips) {
|
|
506
|
+
if (tips.length > 3 && tips.substring(0, 2) === '${' && tips.substring(tips.length -1, tips.length) === '}') {
|
|
507
|
+
let tipsKey = tips.substring(2, tips.length -1)
|
|
508
|
+
tipsKey = tipsKey.trim()
|
|
509
|
+
if (this.TipsMap[tipsKey]) {
|
|
510
|
+
return this.TipsMap[tipsKey].tips
|
|
481
511
|
}
|
|
482
512
|
}
|
|
513
|
+
return tips
|
|
483
514
|
}
|
|
484
|
-
|
|
485
|
-
return null
|
|
486
515
|
}
|
|
487
|
-
function IsListOk(fCfgItem, paramValue) {
|
|
488
|
-
if (!fCfgItem || !fCfgItem.ifMust) {
|
|
489
|
-
return null
|
|
490
|
-
}
|
|
491
516
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
517
|
+
function response(params) {
|
|
518
|
+
let p = ConfigMap[this.app.get('_PORT_')]
|
|
519
|
+
if (p.IsCheckedRes &&
|
|
520
|
+
this.interfaceInfo &&
|
|
521
|
+
this.interfaceInfo.rspMsgId &&
|
|
522
|
+
params.codeKey == 'SUCC') {
|
|
523
|
+
let retMsgData = p.cycleCheckParams(p.FieldMap[this.interfaceInfo.rspMsgId], params.data)
|
|
524
|
+
if (retMsgData) {
|
|
525
|
+
params.codeKey = 'SVC_ERR'
|
|
526
|
+
params.msg = retMsgData
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
let code = ''
|
|
530
|
+
if (p.ResultCodeMap[params.codeKey]) {
|
|
531
|
+
code = p.ResultCodeMap[params.codeKey].rstCode
|
|
499
532
|
}
|
|
500
533
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
534
|
+
let msg = ''
|
|
535
|
+
if (!params.msg) {
|
|
536
|
+
if (p.TipsMap[params.codeKey]) {
|
|
537
|
+
msg = p.TipsMap[params.codeKey].tips
|
|
538
|
+
} else {
|
|
539
|
+
msg = p.ResultCodeMap[params.codeKey].codeDesc
|
|
540
|
+
}
|
|
541
|
+
} else {
|
|
542
|
+
if (typeof params.msg == 'string') {
|
|
543
|
+
msg = params.msg
|
|
504
544
|
}
|
|
505
|
-
return ['WEBX_NULL_FIELD', 'list', fCfgItem.fieldUrl]
|
|
506
|
-
}
|
|
507
545
|
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
for (let i in rule.exprVal) {
|
|
515
|
-
if (length >= parseInt(rule.exprVal[i][0]) && length <= parseInt(rule.exprVal[i][1])) {
|
|
516
|
-
isPass = true
|
|
517
|
-
break
|
|
546
|
+
if (typeof params.msg == 'object' && params.msg.length) {
|
|
547
|
+
if (p.TipsMap[params.msg[0]]) {
|
|
548
|
+
msg = p.TipsMap[params.msg[0]].tips
|
|
549
|
+
if (params.msg.length > 1) {
|
|
550
|
+
for (let i = 1; i < params.msg.length; i++) {
|
|
551
|
+
msg = Util.format(msg, params.msg[i])
|
|
518
552
|
}
|
|
519
553
|
}
|
|
520
554
|
} else {
|
|
521
|
-
|
|
522
|
-
isPass = true
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
if (!isPass) {
|
|
527
|
-
if (rule.ruleDesc) {
|
|
528
|
-
return getCustomTips(rule.ruleDesc)
|
|
529
|
-
}
|
|
530
|
-
return ['WEBX_WRONG_RANGE', fCfgItem.fieldUrl, JSON.stringify(rule.exprVal)]
|
|
555
|
+
msg = params.msg[0]
|
|
531
556
|
}
|
|
532
557
|
}
|
|
533
558
|
}
|
|
534
559
|
|
|
535
|
-
return
|
|
560
|
+
return this.send({ code: code, msg: msg, data: params.data })
|
|
561
|
+
}
|
|
562
|
+
async function webCommResponse(req, res, next) {
|
|
563
|
+
return res.Msg({ codeKey: 'SUCC', data: [] })
|
|
536
564
|
}
|
|
537
565
|
module.exports = Fun
|