xzwebx-httpfilter 2.4.2 → 2.4.3

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.
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectModuleManager">
4
+ <modules>
5
+ <module fileurl="file://$PROJECT_DIR$/.idea/xzwebx-httpfilter.iml" filepath="$PROJECT_DIR$/.idea/xzwebx-httpfilter.iml" />
6
+ </modules>
7
+ </component>
8
+ </project>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <module type="WEB_MODULE" version="4">
3
+ <component name="NewModuleRootManager">
4
+ <content url="file://$MODULE_DIR$">
5
+ <excludeFolder url="file://$MODULE_DIR$/.tmp" />
6
+ <excludeFolder url="file://$MODULE_DIR$/temp" />
7
+ <excludeFolder url="file://$MODULE_DIR$/tmp" />
8
+ </content>
9
+ <orderEntry type="inheritedJdk" />
10
+ <orderEntry type="sourceFolder" forTests="false" />
11
+ </component>
12
+ </module>
package/HttpFilter.js CHANGED
@@ -134,73 +134,60 @@ class http {
134
134
  }
135
135
  checkReq(req, res, next) {
136
136
  let reqMsgId = req.interfaceInfo.reqMsgId
137
- if (!reqMsgId) {
137
+ if (!reqMsgId || !this.FieldMap[reqMsgId]) {
138
138
  return next()
139
139
  }
140
-
141
- let retMsgData = this.cycleCheckParams(this.FieldMap[reqMsgId], req.body)
142
- if (retMsgData) {
143
- return res.Msg({codeKey: 'CLT_ERR', msg: retMsgData})
140
+
141
+ for (let fieldName in this.FieldMap[reqMsgId]) {
142
+ let retMsgData = this.cycleCheckParams(this.FieldMap[reqMsgId][fieldName], req.body)
143
+ if (retMsgData) {
144
+ return res.Msg({codeKey: 'CLT_ERR', msg: retMsgData})
145
+ }
144
146
  }
145
-
147
+
146
148
  return next()
147
149
  }
148
150
  cycleCheckParams(msgFieldMap, data) {
149
- let retMsgData = null
150
-
151
151
  if (!msgFieldMap) {
152
152
  return null
153
153
  }
154
-
155
- let fCfgItem = null
156
- let isRoot = true
157
- if (msgFieldMap['__FieldCfg']) {
158
- isRoot = false
159
- fCfgItem = msgFieldMap['__FieldCfg']
154
+
155
+ let fCfgItem = msgFieldMap['__FieldCfg']
156
+ if (!fCfgItem) {
157
+ return null
160
158
  }
161
-
159
+
160
+ let retMsgData = null
161
+ if (fCfgItem.fieldType == 'STR') {
162
+ retMsgData = this.isStringOk(fCfgItem, data)
163
+ } else if (fCfgItem.fieldType == 'INT') {
164
+ retMsgData = this.isIntOk(fCfgItem, data)
165
+ } else if (fCfgItem.fieldType == 'OBJ') {
166
+ retMsgData = this.isObjOk(fCfgItem, data)
167
+ } else if (fCfgItem.fieldType == 'LIST') {
168
+ retMsgData = this.isListOk(fCfgItem, data)
169
+ }
170
+
171
+ if (retMsgData) {
172
+ return retMsgData
173
+ }
174
+
162
175
  for (let fieldName in msgFieldMap) {
163
- if (isRoot) {
164
- fCfgItem = msgFieldMap[fieldName]['__FieldCfg']
165
- }
166
-
167
- if (fCfgItem.fieldType == 'STR') {
168
- retMsgData = this.isStringOk(fCfgItem, data)
169
- } else if (fCfgItem.fieldType == 'INT') {
170
- retMsgData = this.isIntOk(fCfgItem, data)
171
- } else if (fCfgItem.fieldType == 'OBJ') {
172
- retMsgData = this.isObjOk(fCfgItem, data)
173
- } else if (fCfgItem.fieldType == 'LIST') {
174
- retMsgData = this.isListOk(fCfgItem, data)
175
- }
176
-
177
- if (retMsgData) {
178
- return retMsgData
179
- }
180
-
181
- if (fieldName == '__FieldCfg') {
176
+ if (fieldName === '__FieldCfg') {
182
177
  continue
183
178
  }
184
179
  let fatherFieldType = fCfgItem.fieldType
185
- if (fatherFieldType == 'LIST' || (fatherFieldType == 'OBJ' && fCfgItem.keyType == 'VOBJ')) {
186
- if (isRoot) {
187
- retMsgData = this.cycleCheckParams(msgFieldMap[fieldName], data)
188
- } else {
189
- for (let idx in data) {
190
- retMsgData = this.cycleCheckParams(msgFieldMap[fieldName], data[idx])
191
- if (retMsgData) {
192
- return retMsgData
193
- }
180
+ if (fCfgItem.fieldType === 'LIST' || (fCfgItem.fieldType === 'OBJ' && msgFieldMap[fieldName]['__FieldCfg'].keyType === 'VSTR')) {
181
+ for (let idx in data) {
182
+ retMsgData = this.cycleCheckParams(msgFieldMap[fieldName], data[idx])
183
+ if (retMsgData) {
184
+ return retMsgData
194
185
  }
195
186
  }
196
187
  } else {
197
- if (isRoot) {
198
- retMsgData = this.cycleCheckParams(msgFieldMap[fieldName], data)
199
- } else {
200
- retMsgData = this.cycleCheckParams(msgFieldMap[fieldName], data[fieldName])
201
- }
188
+ retMsgData = this.cycleCheckParams(msgFieldMap[fieldName], data[fieldName])
202
189
  }
203
-
190
+
204
191
  if (retMsgData) {
205
192
  return retMsgData
206
193
  }
@@ -534,11 +521,14 @@ function response(params) {
534
521
  if (p.IsCheckedRes &&
535
522
  this.interfaceInfo &&
536
523
  this.interfaceInfo.rspMsgId &&
537
- params.codeKey == 'SUCC') {
538
- let retMsgData = p.cycleCheckParams(p.FieldMap[this.interfaceInfo.rspMsgId], params.data)
539
- if (retMsgData) {
540
- params.codeKey = 'SVC_ERR'
541
- params.msg = retMsgData
524
+ p.FieldMap[this.interfaceInfo.rspMsgId] &&
525
+ params.codeKey === 'SUCC') {
526
+ for (let fieldName in p.FieldMap[this.interfaceInfo.rspMsgId]) {
527
+ let retMsgData = p.cycleCheckParams(p.FieldMap[this.interfaceInfo.rspMsgId][fieldName], params.data)
528
+ if (retMsgData) {
529
+ params.codeKey = 'SVC_ERR'
530
+ params.msg = retMsgData
531
+ }
542
532
  }
543
533
  }
544
534
  let code = ''
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xzwebx-httpfilter",
3
- "version": "2.4.2",
3
+ "version": "2.4.3",
4
4
  "main": "HttpFilter.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"