badmfck-api-server 4.1.5 → 4.1.7
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.
|
@@ -39,6 +39,7 @@ const express_fileupload_1 = __importDefault(require("express-fileupload"));
|
|
|
39
39
|
const Liveness_1 = require("./routes/Liveness");
|
|
40
40
|
const Readiness_1 = require("./routes/Readiness");
|
|
41
41
|
const http_1 = __importDefault(require("http"));
|
|
42
|
+
const path_1 = __importDefault(require("path"));
|
|
42
43
|
const StatService_1 = require("./StatService");
|
|
43
44
|
const ExternalServiceEndpoint_1 = require("./external/ExternalServiceEndpoint");
|
|
44
45
|
const MonitorService_1 = require("./MonitorService");
|
|
@@ -97,7 +98,7 @@ async function Initializer(services) {
|
|
|
97
98
|
}
|
|
98
99
|
exports.Initializer = Initializer;
|
|
99
100
|
class APIService extends BaseService_1.BaseService {
|
|
100
|
-
version = "4.1.
|
|
101
|
+
version = "4.1.07";
|
|
101
102
|
options;
|
|
102
103
|
monitor = null;
|
|
103
104
|
started = new Date();
|
|
@@ -485,26 +486,35 @@ class APIService extends BaseService_1.BaseService {
|
|
|
485
486
|
else {
|
|
486
487
|
try {
|
|
487
488
|
if (data.file) {
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
}
|
|
495
|
-
else {
|
|
496
|
-
try {
|
|
497
|
-
res.destroy?.(err);
|
|
498
|
-
}
|
|
499
|
-
catch { }
|
|
500
|
-
return;
|
|
501
|
-
}
|
|
489
|
+
const filePath = path_1.default.isAbsolute(data.file) ? data.file : path_1.default.resolve(data.file);
|
|
490
|
+
const onSendFileError = (err) => {
|
|
491
|
+
(0, LogService_1.logError)("Can't send file: " + filePath);
|
|
492
|
+
if (!res.headersSent && !res.writableEnded) {
|
|
493
|
+
res.status(500).send({ error: DefaultErrors_1.default.CANT_SEND_FILE, data: null });
|
|
494
|
+
return;
|
|
502
495
|
}
|
|
503
496
|
else {
|
|
504
|
-
|
|
505
|
-
|
|
497
|
+
try {
|
|
498
|
+
res.destroy?.(err);
|
|
499
|
+
}
|
|
500
|
+
catch { }
|
|
501
|
+
return;
|
|
506
502
|
}
|
|
507
|
-
}
|
|
503
|
+
};
|
|
504
|
+
try {
|
|
505
|
+
res.sendFile(filePath, err => {
|
|
506
|
+
if (err) {
|
|
507
|
+
onSendFileError(err);
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
if (req && !data.ignoreHttpLogging)
|
|
511
|
+
this.addNetlog(data, req, requestTime, 0);
|
|
512
|
+
}
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
catch (e) {
|
|
516
|
+
onSendFileError(e);
|
|
517
|
+
}
|
|
508
518
|
return;
|
|
509
519
|
}
|
|
510
520
|
if (data.redirect) {
|
|
@@ -3,7 +3,7 @@ import { BaseService } from "./BaseService";
|
|
|
3
3
|
import { IDBAdapter } from "./db/IDBAdapter";
|
|
4
4
|
export interface IDBQueryField {
|
|
5
5
|
name?: string | null;
|
|
6
|
-
value: string | number | boolean | null | undefined;
|
|
6
|
+
value: string | number | boolean | Date | null | undefined;
|
|
7
7
|
system?: boolean;
|
|
8
8
|
ignoreInInsert?: boolean;
|
|
9
9
|
ignoreInUpdate?: boolean;
|
|
@@ -151,7 +151,7 @@ class DBService extends BaseService_1.BaseService {
|
|
|
151
151
|
};
|
|
152
152
|
exports.REQ_DB.listener = async (req) => {
|
|
153
153
|
if (req.fields)
|
|
154
|
-
req.fields =
|
|
154
|
+
req.fields = structuredClone(req.fields);
|
|
155
155
|
const executionStartTime = Date.now();
|
|
156
156
|
if (!req.dbid && DBService.allInstances.length === 1 && DBService.allInstances[0].adapter) {
|
|
157
157
|
return await DBService.allInstances[0].adapter.query(req);
|
|
@@ -586,6 +586,8 @@ class MysqlAdapter {
|
|
|
586
586
|
queryField = { value: null, system: true };
|
|
587
587
|
if (typeof queryField === "string" || typeof queryField === "number" || typeof queryField === "boolean")
|
|
588
588
|
queryField = { value: queryField, system: false };
|
|
589
|
+
if (queryField instanceof Date)
|
|
590
|
+
queryField = { value: queryField, system: false };
|
|
589
591
|
if (queryField === null)
|
|
590
592
|
queryField = { value: null, system: true };
|
|
591
593
|
if (queryField.value === undefined) {
|
|
@@ -669,24 +671,26 @@ class MysqlAdapter {
|
|
|
669
671
|
field.__parsedValue = "NULL";
|
|
670
672
|
return "NULL";
|
|
671
673
|
}
|
|
672
|
-
if (
|
|
673
|
-
try {
|
|
674
|
-
value = JSON.stringify(value);
|
|
675
|
-
}
|
|
676
|
-
catch (e) {
|
|
677
|
-
console.error("Can't prepare JSON object", e);
|
|
678
|
-
value = "{}";
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
if (!system && typeof value === "string") {
|
|
682
|
-
value = promise_1.default.escape(value);
|
|
683
|
-
}
|
|
684
|
-
if (typeof value === "boolean")
|
|
685
|
-
value = value ? 1 : 0;
|
|
686
|
-
if (typeof value === "object" && value instanceof Date) {
|
|
674
|
+
if (value instanceof Date) {
|
|
687
675
|
const utcString = value.toISOString().slice(0, 19).replace('T', ' ');
|
|
688
676
|
value = promise_1.default.escape(utcString);
|
|
689
677
|
}
|
|
678
|
+
else {
|
|
679
|
+
if (!system && typeof value === "object") {
|
|
680
|
+
try {
|
|
681
|
+
value = JSON.stringify(value);
|
|
682
|
+
}
|
|
683
|
+
catch (e) {
|
|
684
|
+
console.error("Can't prepare JSON object", e);
|
|
685
|
+
value = "{}";
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
if (!system && typeof value === "string") {
|
|
689
|
+
value = promise_1.default.escape(value);
|
|
690
|
+
}
|
|
691
|
+
if (typeof value === "boolean")
|
|
692
|
+
value = value ? 1 : 0;
|
|
693
|
+
}
|
|
690
694
|
if (field.fields && typeof field.fields === "object" && value && typeof value === "string" && value.indexOf("@") !== -1) {
|
|
691
695
|
for (let key in field.fields) {
|
|
692
696
|
if (!field.fields[key])
|