badmfck-api-server 3.2.6 → 3.2.9
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.
@@ -5,6 +5,7 @@ import { IBaseEndpoint } from './BaseEndpoint';
|
|
5
5
|
import { HTTPRequestVO, IError, TransferPacketVO } from './structures/Interfaces';
|
6
6
|
import { Req } from "badmfck-signal";
|
7
7
|
import http from 'http';
|
8
|
+
import { IWebsocket } from './Websocket';
|
8
9
|
export interface IMonitorUser {
|
9
10
|
login: string;
|
10
11
|
password: string;
|
@@ -39,6 +40,7 @@ export interface APIServiceOptions {
|
|
39
40
|
monitor?: IMonitorUser[];
|
40
41
|
documentation?: IMonitorUser[];
|
41
42
|
};
|
43
|
+
websocket?: IWebsocket[];
|
42
44
|
monitor?: IMonitorUser[];
|
43
45
|
appVersion?: string;
|
44
46
|
fileTempDir: string;
|
@@ -0,0 +1,15 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Websocket = void 0;
|
4
|
+
const getDefaultWebSocketServiceOptions = () => {
|
5
|
+
return {
|
6
|
+
endpoint: "/ws"
|
7
|
+
};
|
8
|
+
};
|
9
|
+
class Websocket {
|
10
|
+
options;
|
11
|
+
constructor(opt) {
|
12
|
+
this.options = { ...getDefaultWebSocketServiceOptions(), opt };
|
13
|
+
}
|
14
|
+
}
|
15
|
+
exports.Websocket = Websocket;
|
@@ -34,7 +34,10 @@ class Validator {
|
|
34
34
|
let type = typeof structure[i];
|
35
35
|
let description = structure['$__' + i] || "";
|
36
36
|
let childs = undefined;
|
37
|
-
let optional = structure['$
|
37
|
+
let optional = structure['$__' + i + "_optional"] || "";
|
38
|
+
let regex = structure['$__' + i + '_regex'] || undefined;
|
39
|
+
let min = structure['$__' + i + "_min"] || undefined;
|
40
|
+
let max = structure['$__' + i + "_max"] || undefined;
|
38
41
|
if (optional === undefined)
|
39
42
|
optional = structure[i] === null || structure[i] === undefined;
|
40
43
|
if (type === "object" && Array.isArray(structure[i]))
|
@@ -47,6 +50,9 @@ class Validator {
|
|
47
50
|
type: type,
|
48
51
|
description: description,
|
49
52
|
optional: optional,
|
53
|
+
regex: regex,
|
54
|
+
min: min,
|
55
|
+
max: max,
|
50
56
|
childs: childs
|
51
57
|
};
|
52
58
|
}
|
@@ -120,8 +126,8 @@ class Validator {
|
|
120
126
|
errors.push("wrong value for field '" + i + "', expected " + expected.join(", ") + " got: " + value);
|
121
127
|
}
|
122
128
|
}
|
123
|
-
if (typeof structure[i] === "string" && structure[i
|
124
|
-
const regex = structure[i]
|
129
|
+
if (typeof structure[i] === "string" && structure["$__" + i + "_regex"]) {
|
130
|
+
const regex = structure["$__" + i + "_regex"];
|
125
131
|
const reg = new RegExp(regex);
|
126
132
|
if (reg.test(object[i]) === false)
|
127
133
|
errors.push("wrong value for field '" + i + "', false mask for: " + object[i]);
|
@@ -154,6 +160,16 @@ class Validator {
|
|
154
160
|
}
|
155
161
|
}
|
156
162
|
}
|
163
|
+
if (typeof structure[i] === "number" && structure["$__" + i + "_min"]) {
|
164
|
+
const min = structure["$__" + i + "_min"];
|
165
|
+
if (object[i] < min)
|
166
|
+
errors.push("value for field '" + i + "' is too small, expected more than " + min + " got: " + object[i]);
|
167
|
+
}
|
168
|
+
if (typeof structure[i] === "number" && structure["$__" + i + "_max"]) {
|
169
|
+
const max = structure["$__" + i + "_max"];
|
170
|
+
if (object[i] > max)
|
171
|
+
errors.push("value for field '" + i + "' is too big, expected less than " + max + " got: " + object[i]);
|
172
|
+
}
|
157
173
|
foundKeys.push(i);
|
158
174
|
}
|
159
175
|
if (errors.length > 0)
|