badmfck-api-server 1.2.3 → 1.2.4
Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,7 @@ exports.MysqlService = exports.executeQuery = exports.REQ_MYSQL_QUERY = void 0;
|
|
7
7
|
const mysql_1 = __importDefault(require("mysql"));
|
8
8
|
const BaseService_1 = require("./BaseService");
|
9
9
|
const badmfck_signal_1 = require("badmfck-signal");
|
10
|
+
const crypto_1 = require("crypto");
|
10
11
|
exports.REQ_MYSQL_QUERY = new badmfck_signal_1.Req("REQ_MYSQL_QUERY");
|
11
12
|
const executeQuery = async (query) => { return await exports.REQ_MYSQL_QUERY.request(query); };
|
12
13
|
exports.executeQuery = executeQuery;
|
@@ -21,6 +22,12 @@ class MysqlService extends BaseService_1.BaseService {
|
|
21
22
|
constructor(options) {
|
22
23
|
super("mysql");
|
23
24
|
this.options = options;
|
25
|
+
if (this.options.host.startsWith("_"))
|
26
|
+
this.options.host = decrypt(this.options.host) ?? this.options.host;
|
27
|
+
if (this.options.user.startsWith("_"))
|
28
|
+
this.options.user = decrypt(this.options.user) ?? this.options.user;
|
29
|
+
if (this.options.database.startsWith("_"))
|
30
|
+
this.options.database = decrypt(this.options.database) ?? this.options.database;
|
24
31
|
}
|
25
32
|
static async executeQuery(query) { return await exports.REQ_MYSQL_QUERY.request(query); }
|
26
33
|
async init() {
|
@@ -306,4 +313,30 @@ class MysqlService extends BaseService_1.BaseService {
|
|
306
313
|
}
|
307
314
|
}
|
308
315
|
exports.MysqlService = MysqlService;
|
316
|
+
const secret_key = "AKLWkajw%^&dgwqhw#98453i23bfk23rn2knknglrgjeit";
|
317
|
+
const secret_iv = "rthadrfk23rn2kn#*FNKA@gt44df3tslrgj##!it";
|
318
|
+
const key = (0, crypto_1.createHash)('sha512').update(secret_key).digest('hex').substring(0, 32);
|
319
|
+
const iv = (0, crypto_1.createHash)('sha512').update(secret_iv).digest('hex').substring(0, 16);
|
320
|
+
const decrypt = (encrypted) => {
|
321
|
+
try {
|
322
|
+
encrypted = Buffer.from(encrypted, 'base64').toString('binary');
|
323
|
+
const decipher = (0, crypto_1.createDecipheriv)('aes-256-cbc', key, iv);
|
324
|
+
let decrypted = decipher.update(encrypted, 'binary', 'utf8');
|
325
|
+
decrypted += decipher.final('utf8');
|
326
|
+
return decrypted;
|
327
|
+
}
|
328
|
+
catch (e) {
|
329
|
+
return null;
|
330
|
+
}
|
331
|
+
};
|
332
|
+
const encrypt = (txt) => {
|
333
|
+
try {
|
334
|
+
let encipher = (0, crypto_1.createCipheriv)('aes-256-cbc', key, iv), encrypted = encipher.update(txt, 'utf8', 'binary');
|
335
|
+
encrypted += encipher.final('binary');
|
336
|
+
return Buffer.from(encrypted, 'binary').toString('base64');
|
337
|
+
}
|
338
|
+
catch (e) {
|
339
|
+
return null;
|
340
|
+
}
|
341
|
+
};
|
309
342
|
exports.default = MysqlService;
|
@@ -0,0 +1,18 @@
|
|
1
|
+
export interface IValidatorOptions {
|
2
|
+
min?: number;
|
3
|
+
max?: number;
|
4
|
+
type?: "string" | "boolean" | "number";
|
5
|
+
regex?: RegExp;
|
6
|
+
}
|
7
|
+
export declare enum ValidationReport {
|
8
|
+
OK = 1,
|
9
|
+
VALUE_IS_NULL = 2,
|
10
|
+
TYPE_MISSMATCH = 3,
|
11
|
+
VALUE_TOO_BIG = 4,
|
12
|
+
VALUE_TOO_SHORT = 5,
|
13
|
+
VALUE_INCORRECT = 6
|
14
|
+
}
|
15
|
+
export declare class Validator {
|
16
|
+
static validateObject(fields: string[], object: any): boolean;
|
17
|
+
static validateValue(value: string | number | boolean, opt?: IValidatorOptions): ValidationReport;
|
18
|
+
}
|
@@ -0,0 +1,60 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Validator = exports.ValidationReport = void 0;
|
4
|
+
var ValidationReport;
|
5
|
+
(function (ValidationReport) {
|
6
|
+
ValidationReport[ValidationReport["OK"] = 1] = "OK";
|
7
|
+
ValidationReport[ValidationReport["VALUE_IS_NULL"] = 2] = "VALUE_IS_NULL";
|
8
|
+
ValidationReport[ValidationReport["TYPE_MISSMATCH"] = 3] = "TYPE_MISSMATCH";
|
9
|
+
ValidationReport[ValidationReport["VALUE_TOO_BIG"] = 4] = "VALUE_TOO_BIG";
|
10
|
+
ValidationReport[ValidationReport["VALUE_TOO_SHORT"] = 5] = "VALUE_TOO_SHORT";
|
11
|
+
ValidationReport[ValidationReport["VALUE_INCORRECT"] = 6] = "VALUE_INCORRECT";
|
12
|
+
})(ValidationReport || (exports.ValidationReport = ValidationReport = {}));
|
13
|
+
class Validator {
|
14
|
+
static validateObject(fields, object) {
|
15
|
+
if (!object || typeof object !== "object")
|
16
|
+
return false;
|
17
|
+
for (let i of fields) {
|
18
|
+
if (!(i in object) || object[i] === undefined)
|
19
|
+
return false;
|
20
|
+
}
|
21
|
+
return true;
|
22
|
+
}
|
23
|
+
static validateValue(value, opt) {
|
24
|
+
if (!value)
|
25
|
+
return ValidationReport.VALUE_IS_NULL;
|
26
|
+
if (!opt)
|
27
|
+
return ValidationReport.OK;
|
28
|
+
if (!opt.type)
|
29
|
+
opt.type = "string";
|
30
|
+
if (opt.type === "boolean") {
|
31
|
+
if (typeof value === "boolean")
|
32
|
+
return ValidationReport.OK;
|
33
|
+
if (typeof value === "number" && (value === 1 || value === 0))
|
34
|
+
return ValidationReport.OK;
|
35
|
+
return ValidationReport.TYPE_MISSMATCH;
|
36
|
+
}
|
37
|
+
if (opt.type === "number") {
|
38
|
+
if (typeof value !== "number")
|
39
|
+
return ValidationReport.TYPE_MISSMATCH;
|
40
|
+
if (opt.max && value > opt.max)
|
41
|
+
return ValidationReport.VALUE_TOO_BIG;
|
42
|
+
if (opt.min && value < opt.min)
|
43
|
+
return ValidationReport.VALUE_TOO_BIG;
|
44
|
+
return ValidationReport.OK;
|
45
|
+
}
|
46
|
+
if (typeof value !== "string")
|
47
|
+
return ValidationReport.TYPE_MISSMATCH;
|
48
|
+
if (opt.max && value.length > opt.max)
|
49
|
+
return ValidationReport.VALUE_TOO_BIG;
|
50
|
+
if (opt.min && value.length < opt.min)
|
51
|
+
return ValidationReport.VALUE_TOO_SHORT;
|
52
|
+
if (opt.regex) {
|
53
|
+
const tmp = value.replaceAll(opt.regex, "");
|
54
|
+
if (tmp.length !== 0)
|
55
|
+
return ValidationReport.VALUE_INCORRECT;
|
56
|
+
}
|
57
|
+
return ValidationReport.OK;
|
58
|
+
}
|
59
|
+
}
|
60
|
+
exports.Validator = Validator;
|
package/dist/index.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import { APIService, Initializer } from "./apiServer/APIService";
|
2
2
|
import { LocalRequest } from "./apiServer/LocalRequest";
|
3
3
|
import { MysqlService } from "./apiServer/MysqlService";
|
4
|
-
|
4
|
+
import { Validator } from "./apiServer/helper/Validator";
|
5
|
+
export { APIService, Initializer, LocalRequest, MysqlService, Validator };
|
package/dist/index.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.MysqlService = exports.LocalRequest = exports.Initializer = exports.APIService = void 0;
|
3
|
+
exports.Validator = exports.MysqlService = exports.LocalRequest = exports.Initializer = exports.APIService = void 0;
|
4
4
|
const APIService_1 = require("./apiServer/APIService");
|
5
5
|
Object.defineProperty(exports, "APIService", { enumerable: true, get: function () { return APIService_1.APIService; } });
|
6
6
|
Object.defineProperty(exports, "Initializer", { enumerable: true, get: function () { return APIService_1.Initializer; } });
|
@@ -8,3 +8,5 @@ const LocalRequest_1 = require("./apiServer/LocalRequest");
|
|
8
8
|
Object.defineProperty(exports, "LocalRequest", { enumerable: true, get: function () { return LocalRequest_1.LocalRequest; } });
|
9
9
|
const MysqlService_1 = require("./apiServer/MysqlService");
|
10
10
|
Object.defineProperty(exports, "MysqlService", { enumerable: true, get: function () { return MysqlService_1.MysqlService; } });
|
11
|
+
const Validator_1 = require("./apiServer/helper/Validator");
|
12
|
+
Object.defineProperty(exports, "Validator", { enumerable: true, get: function () { return Validator_1.Validator; } });
|