badmfck-api-server 4.0.99 → 4.1.2
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/dist/apiServer/APIService.js +27 -15
- package/dist/apiServer/db/MysqlAdapter.js +2 -17
- package/dist/apiServer/documentation/index.html +175 -224
- package/dist/apiServer/monitor/Monitor.js +0 -10
- package/dist/apiServer/monitor/index.html +224 -161
- package/dist/apiServer/structures/Interfaces.d.ts +1 -0
- package/package.json +1 -1
|
@@ -97,7 +97,7 @@ async function Initializer(services) {
|
|
|
97
97
|
}
|
|
98
98
|
exports.Initializer = Initializer;
|
|
99
99
|
class APIService extends BaseService_1.BaseService {
|
|
100
|
-
version = "4.
|
|
100
|
+
version = "4.1.02";
|
|
101
101
|
options;
|
|
102
102
|
monitor = null;
|
|
103
103
|
started = new Date();
|
|
@@ -300,6 +300,18 @@ class APIService extends BaseService_1.BaseService {
|
|
|
300
300
|
files: req.files ?? null,
|
|
301
301
|
referer: req.get("Referer"),
|
|
302
302
|
};
|
|
303
|
+
let ignoreHttpLogging = j.ignoreHttpLogging ?? false;
|
|
304
|
+
if (!ignoreHttpLogging && typeof j.handler === "object") {
|
|
305
|
+
const handler = j.handler[httpRequest.method.toUpperCase()];
|
|
306
|
+
if (typeof handler === "object")
|
|
307
|
+
ignoreHttpLogging = handler.ignoreHttpLogging ?? false;
|
|
308
|
+
}
|
|
309
|
+
if (!ignoreHttpLogging)
|
|
310
|
+
ignoreHttpLogging = i.ignoreHttpLogging ?? false;
|
|
311
|
+
const respond = (data) => {
|
|
312
|
+
data.ignoreHttpLogging = ignoreHttpLogging || data.ignoreHttpLogging || false;
|
|
313
|
+
return this.sendResponse(req.get("Referer") ?? "", res, data, tme, ep, httpRequest);
|
|
314
|
+
};
|
|
303
315
|
if (this.options.preproducer && ep !== "--sys-monitor") {
|
|
304
316
|
try {
|
|
305
317
|
const preproducerResult = await this.options.preproducer(httpRequest);
|
|
@@ -315,10 +327,10 @@ class APIService extends BaseService_1.BaseService {
|
|
|
315
327
|
stack = [e];
|
|
316
328
|
}
|
|
317
329
|
if ((0, MysqlAdapter_1.isError)(e)) {
|
|
318
|
-
|
|
330
|
+
respond({ error: { ...DefaultErrors_1.default.DB_ERROR, details: e.message } });
|
|
319
331
|
return;
|
|
320
332
|
}
|
|
321
|
-
|
|
333
|
+
respond({ error: { code: 10002, message: "Internal server error!", stack: stack, details: details }, data: null, httpStatus: 500 });
|
|
322
334
|
return;
|
|
323
335
|
}
|
|
324
336
|
}
|
|
@@ -344,7 +356,7 @@ class APIService extends BaseService_1.BaseService {
|
|
|
344
356
|
if (this.options.interceptor) {
|
|
345
357
|
interceptorResult = await this.options.interceptor.intercept(httpRequest, j.internalCallParams);
|
|
346
358
|
if (DefaultErrors_1.ErrorUtils.isError(interceptorResult) && !allowInterceptorError) {
|
|
347
|
-
|
|
359
|
+
respond(interceptorResult);
|
|
348
360
|
return;
|
|
349
361
|
}
|
|
350
362
|
httpRequest.interceptorResult = interceptorResult;
|
|
@@ -352,7 +364,7 @@ class APIService extends BaseService_1.BaseService {
|
|
|
352
364
|
}
|
|
353
365
|
const precheck = await i.__precheck(httpRequest);
|
|
354
366
|
if (precheck && precheck.error) {
|
|
355
|
-
|
|
367
|
+
respond(precheck);
|
|
356
368
|
return;
|
|
357
369
|
}
|
|
358
370
|
httpRequest.precheck = precheck;
|
|
@@ -388,10 +400,10 @@ class APIService extends BaseService_1.BaseService {
|
|
|
388
400
|
error: { ...DefaultErrors_1.default.DB_ERROR, details: e.message }
|
|
389
401
|
};
|
|
390
402
|
}
|
|
391
|
-
|
|
403
|
+
respond(data);
|
|
392
404
|
return;
|
|
393
405
|
}
|
|
394
|
-
|
|
406
|
+
respond(result);
|
|
395
407
|
};
|
|
396
408
|
return execute();
|
|
397
409
|
});
|
|
@@ -420,10 +432,8 @@ class APIService extends BaseService_1.BaseService {
|
|
|
420
432
|
});
|
|
421
433
|
}
|
|
422
434
|
addNetlog(data, req, created, time) {
|
|
423
|
-
if (time === 0)
|
|
435
|
+
if (time === 0)
|
|
424
436
|
time = +new Date() - created;
|
|
425
|
-
created = +new Date();
|
|
426
|
-
}
|
|
427
437
|
const logItem = {
|
|
428
438
|
id: nextLogID++,
|
|
429
439
|
created: created,
|
|
@@ -446,12 +456,14 @@ class APIService extends BaseService_1.BaseService {
|
|
|
446
456
|
}
|
|
447
457
|
async sendResponse(ref, res, data, requestTime, endpoint, req) {
|
|
448
458
|
if (data.blockResponse) {
|
|
449
|
-
(
|
|
450
|
-
|
|
459
|
+
if (!data.ignoreHttpLogging)
|
|
460
|
+
(0, LogService_1.logAPI)("Response blocked");
|
|
461
|
+
if (req && !data.ignoreHttpLogging)
|
|
451
462
|
this.addNetlog(data, req, requestTime, 0);
|
|
452
463
|
return;
|
|
453
464
|
}
|
|
454
|
-
|
|
465
|
+
if (!data.ignoreHttpLogging)
|
|
466
|
+
MonitorService_1.S_STAT_REGISTRATE_REQUEST.invoke({ ...data, endpoint: data.endpoint ?? endpoint });
|
|
455
467
|
if (this.options.postproducer) {
|
|
456
468
|
try {
|
|
457
469
|
data = await this.options.postproducer(req, res, data, requestTime, endpoint);
|
|
@@ -489,7 +501,7 @@ class APIService extends BaseService_1.BaseService {
|
|
|
489
501
|
}
|
|
490
502
|
}
|
|
491
503
|
else {
|
|
492
|
-
if (req)
|
|
504
|
+
if (req && !data.ignoreHttpLogging)
|
|
493
505
|
this.addNetlog(data, req, requestTime, 0);
|
|
494
506
|
}
|
|
495
507
|
});
|
|
@@ -522,7 +534,7 @@ class APIService extends BaseService_1.BaseService {
|
|
|
522
534
|
console.error(e);
|
|
523
535
|
}
|
|
524
536
|
}
|
|
525
|
-
if (req)
|
|
537
|
+
if (req && !data.ignoreHttpLogging)
|
|
526
538
|
this.addNetlog(data, req, requestTime, 0);
|
|
527
539
|
}
|
|
528
540
|
checkDataLength(data, result, lvl) {
|
|
@@ -194,25 +194,17 @@ class MysqlAdapter {
|
|
|
194
194
|
this.poolConnections = 0;
|
|
195
195
|
this.acquiredPoolConnections = 0;
|
|
196
196
|
this.pool?.on('connection', (connection) => {
|
|
197
|
-
|
|
198
|
-
(0, LogService_1.logDB)("MysqlAdapter", "pool -> connection created, total:" + this.poolConnections++);
|
|
197
|
+
(0, LogService_1.logDB)("MysqlAdapter", "pool -> connection created, total:" + this.poolConnections++);
|
|
199
198
|
});
|
|
200
199
|
this.pool?.on('acquire', (connection) => {
|
|
201
200
|
this.acquiredPoolConnections++;
|
|
202
|
-
if (this.options.debug)
|
|
203
|
-
(0, LogService_1.logDB)("MysqlAdapter", "pool -> connection acquire, busy:" + this.acquiredPoolConnections);
|
|
204
201
|
});
|
|
205
202
|
this.pool?.on('release', (connection) => {
|
|
206
203
|
this.acquiredPoolConnections--;
|
|
207
|
-
if (this.options.debug)
|
|
208
|
-
(0, LogService_1.logDB)("MysqlAdapter", "pool -> connection release, busy:" + this.acquiredPoolConnections);
|
|
209
204
|
});
|
|
210
205
|
this.pool?.on('enqueue', () => {
|
|
211
|
-
|
|
212
|
-
(0, LogService_1.logDB)("MysqlAdapter", "pool -> waiting for available connection");
|
|
206
|
+
(0, LogService_1.logDB)("MysqlAdapter", "pool -> waiting for available connection");
|
|
213
207
|
});
|
|
214
|
-
if (this.options.debug)
|
|
215
|
-
console.log("Check mysql connection");
|
|
216
208
|
const res = await this.query({ query: "SELECT 1 @NOLIMIT" });
|
|
217
209
|
if (res.error) {
|
|
218
210
|
(0, LogService_1.logCrit)("MysqlAdapter", "pool -> check connection livenes was failed: " + res.error.message);
|
|
@@ -418,11 +410,6 @@ class MysqlAdapter {
|
|
|
418
410
|
}
|
|
419
411
|
else
|
|
420
412
|
conn = await this.pool.getConnection();
|
|
421
|
-
if (this.options.debug) {
|
|
422
|
-
(0, LogService_1.logDB)("Pool status: ", this.poolConnections, this.acquiredPoolConnections);
|
|
423
|
-
}
|
|
424
|
-
if (this.options.debug)
|
|
425
|
-
(0, LogService_1.logDB)("Execute query", conn?.threadId);
|
|
426
413
|
if (conn)
|
|
427
414
|
return conn;
|
|
428
415
|
}
|
|
@@ -581,8 +568,6 @@ class MysqlAdapter {
|
|
|
581
568
|
try {
|
|
582
569
|
conn.removeAllListeners();
|
|
583
570
|
conn.release();
|
|
584
|
-
if (this.options.debug)
|
|
585
|
-
(0, LogService_1.logDB)("Release connection: ", conn.threadId);
|
|
586
571
|
}
|
|
587
572
|
catch (e) {
|
|
588
573
|
(0, LogService_1.logCrit)("MysqlAdapter", `Can't release connection: ${e}`);
|