xzwebx-httpfilter 2.4.1 → 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
@@ -122,6 +122,8 @@ class http {
122
122
  return res.Msg({codeKey: 'CLT_ERR', msg: ['WEBX_ERR_URL']})
123
123
  }
124
124
 
125
+ req.moduleInfo = module
126
+ res.moduleInfo = module
125
127
  req.interfaceInfo = this.ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()]
126
128
  res.interfaceInfo = this.ModuleInterfaceMap[module.id][subUri][req.method.toLowerCase()]
127
129
  return next()
@@ -132,73 +134,60 @@ class http {
132
134
  }
133
135
  checkReq(req, res, next) {
134
136
  let reqMsgId = req.interfaceInfo.reqMsgId
135
- if (!reqMsgId) {
137
+ if (!reqMsgId || !this.FieldMap[reqMsgId]) {
136
138
  return next()
137
139
  }
138
-
139
- let retMsgData = this.cycleCheckParams(this.FieldMap[reqMsgId], req.body)
140
- if (retMsgData) {
141
- 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
+ }
142
146
  }
143
-
147
+
144
148
  return next()
145
149
  }
146
150
  cycleCheckParams(msgFieldMap, data) {
147
- let retMsgData = null
148
-
149
151
  if (!msgFieldMap) {
150
152
  return null
151
153
  }
152
-
153
- let fCfgItem = null
154
- let isRoot = true
155
- if (msgFieldMap['__FieldCfg']) {
156
- isRoot = false
157
- fCfgItem = msgFieldMap['__FieldCfg']
154
+
155
+ let fCfgItem = msgFieldMap['__FieldCfg']
156
+ if (!fCfgItem) {
157
+ return null
158
158
  }
159
-
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
+
160
175
  for (let fieldName in msgFieldMap) {
161
- if (isRoot) {
162
- fCfgItem = msgFieldMap[fieldName]['__FieldCfg']
163
- }
164
-
165
- if (fCfgItem.fieldType == 'STR') {
166
- retMsgData = this.isStringOk(fCfgItem, data)
167
- } else if (fCfgItem.fieldType == 'INT') {
168
- retMsgData = this.isIntOk(fCfgItem, data)
169
- } else if (fCfgItem.fieldType == 'OBJ') {
170
- retMsgData = this.isObjOk(fCfgItem, data)
171
- } else if (fCfgItem.fieldType == 'LIST') {
172
- retMsgData = this.isListOk(fCfgItem, data)
173
- }
174
-
175
- if (retMsgData) {
176
- return retMsgData
177
- }
178
-
179
- if (fieldName == '__FieldCfg') {
176
+ if (fieldName === '__FieldCfg') {
180
177
  continue
181
178
  }
182
179
  let fatherFieldType = fCfgItem.fieldType
183
- if (fatherFieldType == 'LIST' || (fatherFieldType == 'OBJ' && fCfgItem.keyType == 'VOBJ')) {
184
- if (isRoot) {
185
- retMsgData = this.cycleCheckParams(msgFieldMap[fieldName], data)
186
- } else {
187
- for (let idx in data) {
188
- retMsgData = this.cycleCheckParams(msgFieldMap[fieldName], data[idx])
189
- if (retMsgData) {
190
- return retMsgData
191
- }
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
192
185
  }
193
186
  }
194
187
  } else {
195
- if (isRoot) {
196
- retMsgData = this.cycleCheckParams(msgFieldMap[fieldName], data)
197
- } else {
198
- retMsgData = this.cycleCheckParams(msgFieldMap[fieldName], data[fieldName])
199
- }
188
+ retMsgData = this.cycleCheckParams(msgFieldMap[fieldName], data[fieldName])
200
189
  }
201
-
190
+
202
191
  if (retMsgData) {
203
192
  return retMsgData
204
193
  }
@@ -532,11 +521,14 @@ function response(params) {
532
521
  if (p.IsCheckedRes &&
533
522
  this.interfaceInfo &&
534
523
  this.interfaceInfo.rspMsgId &&
535
- params.codeKey == 'SUCC') {
536
- let retMsgData = p.cycleCheckParams(p.FieldMap[this.interfaceInfo.rspMsgId], params.data)
537
- if (retMsgData) {
538
- params.codeKey = 'SVC_ERR'
539
- 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
+ }
540
532
  }
541
533
  }
542
534
  let code = ''
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xzwebx-httpfilter",
3
- "version": "2.4.1",
3
+ "version": "2.4.3",
4
4
  "main": "HttpFilter.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"