badmfck-api-server 2.0.2 → 2.0.4
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.
@@ -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
|
}
|
@@ -193,9 +193,10 @@ class APIService extends BaseService_1.BaseService {
|
|
193
193
|
if (!i.ignoreHttpLogging) {
|
194
194
|
log = await exports.REQ_CREATE_NET_LOG.request();
|
195
195
|
log.request = {
|
196
|
+
url: req.url,
|
196
197
|
method: req.method,
|
197
|
-
data: req.body,
|
198
|
-
params: req.params
|
198
|
+
data: this.checkDataLength(req.body),
|
199
|
+
params: this.checkDataLength(req.params)
|
199
200
|
};
|
200
201
|
}
|
201
202
|
const execute = async () => {
|
@@ -363,12 +364,12 @@ class APIService extends BaseService_1.BaseService {
|
|
363
364
|
if (data.rawResponse) {
|
364
365
|
res.send(data.data);
|
365
366
|
if (log)
|
366
|
-
log.response =
|
367
|
+
log.response = this.checkDataLength(data);
|
367
368
|
}
|
368
369
|
else {
|
369
370
|
res.send(data);
|
370
371
|
if (log)
|
371
|
-
log.response = data;
|
372
|
+
log.response = this.checkDataLength(data);
|
372
373
|
if (data.error && this.monitor)
|
373
374
|
this.monitor.registrateAPIError(data.endpoint);
|
374
375
|
}
|
@@ -386,5 +387,28 @@ class APIService extends BaseService_1.BaseService {
|
|
386
387
|
if (this.options.onNetworkLog && log)
|
387
388
|
this.options.onNetworkLog(log);
|
388
389
|
}
|
390
|
+
checkDataLength(data, result, lvl) {
|
391
|
+
if (!lvl)
|
392
|
+
lvl = 0;
|
393
|
+
if (typeof data !== "object") {
|
394
|
+
if (typeof data === "string" && data.length > 1024)
|
395
|
+
return data.substring(0, 1000) + "... (total:" + data.length + ")";
|
396
|
+
return data;
|
397
|
+
}
|
398
|
+
if (typeof data === "object") {
|
399
|
+
if (!result)
|
400
|
+
result = {};
|
401
|
+
let arrcnt = 100;
|
402
|
+
for (let i in data) {
|
403
|
+
result[i] = this.checkDataLength(data[i], result[i], lvl + 1);
|
404
|
+
arrcnt--;
|
405
|
+
if (arrcnt <= 0) {
|
406
|
+
result["..."] = "...";
|
407
|
+
break;
|
408
|
+
}
|
409
|
+
}
|
410
|
+
}
|
411
|
+
return result ?? null;
|
412
|
+
}
|
389
413
|
}
|
390
414
|
exports.APIService = APIService;
|