badmfck-api-server 2.0.2 → 2.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -59,4 +59,5 @@ export declare class APIService extends BaseService {
59
59
  constructor(options?: APIServiceOptions | null);
60
60
  init(): Promise<void>;
61
61
  sendResponse(res: Response, data: TransferPacketVO<any>, requestTime: number, endpoint?: string, log?: APIServiceNetworkLogItem | null, req?: HTTPRequestVO): Promise<void>;
62
+ checkDataLength(data: any, result?: any, lvl?: number): any;
62
63
  }
@@ -194,8 +194,8 @@ class APIService extends BaseService_1.BaseService {
194
194
  log = await exports.REQ_CREATE_NET_LOG.request();
195
195
  log.request = {
196
196
  method: req.method,
197
- data: req.body,
198
- params: req.params
197
+ data: this.checkDataLength(req.body),
198
+ params: this.checkDataLength(req.params)
199
199
  };
200
200
  }
201
201
  const execute = async () => {
@@ -386,5 +386,28 @@ class APIService extends BaseService_1.BaseService {
386
386
  if (this.options.onNetworkLog && log)
387
387
  this.options.onNetworkLog(log);
388
388
  }
389
+ checkDataLength(data, result, lvl) {
390
+ if (!result)
391
+ result = {};
392
+ if (!lvl)
393
+ lvl = 0;
394
+ if (typeof data !== "object") {
395
+ if (typeof data === "string" && data.length > 1024)
396
+ return data.substring(0, 1000) + "... (total:" + data.length + ")";
397
+ return data;
398
+ }
399
+ if (typeof data === "object") {
400
+ let arrcnt = 100;
401
+ for (let i in data) {
402
+ result[i] = this.checkDataLength(data[i], result[i], lvl + 1);
403
+ arrcnt--;
404
+ if (arrcnt <= 0) {
405
+ result["..."] = "...";
406
+ break;
407
+ }
408
+ }
409
+ }
410
+ return result;
411
+ }
389
412
  }
390
413
  exports.APIService = APIService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "2.0.2",
3
+ "version": "2.0.3",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",