turbo-express-js 1.0.2 → 1.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.
- package/bin/attachmentupload.test.js +26 -0
- package/bin/custombadrequesterror.test.js +11 -0
- package/bin/exemasterworker.test.js +66 -0
- package/index.test.js +31 -0
- package/lib/TurboServer.js +36 -25
- package/lib/middlewares/attachment_middleware.js +11 -57
- package/lib/middlewares/index.js +17 -0
- package/lib/services/FormDataService.js +112 -0
- package/lib/services/LocaleService.js +46 -0
- package/lib/services/index.js +13 -0
- package/lib/statictypes/ContentType.js +51 -0
- package/lib/types/FileType.js +40 -17
- package/lib/types/RequestInterface.js +91 -30
- package/lib/types/ResponseMongo.js +0 -1
- package/lib/types/Route.js +3 -4
- package/lib/types/SystemTypes.js +21 -0
- package/lib/types/ValidationError.js +193 -7
- package/lib/types/ValidationSchema.js +109 -21
- package/lib/types/ValidationStaticTypes.js +19 -3
- package/lib/types/ValidationTypes.js +11 -0
- package/locales/en/homepage.json +3 -0
- package/locales/gr/homepage.json +3 -0
- package/package.json +1 -1
- package/samples/5uo91B-4WVVFeSLPHupguHXw.png +0 -0
- package/samples/ELIhfER0oegQK0tz_CwOil_1.png +0 -0
- package/samples/Fo6AaX1yJ1tczanzboHrA_xY.png +0 -0
- package/lib/enum/ValidationMethodType.js +0 -6
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* @param {RequestInterface} req
|
|
5
|
+
* @param {ResponseInterface} res
|
|
6
|
+
*/
|
|
7
|
+
async function controller (req, res)
|
|
8
|
+
{
|
|
9
|
+
//console.log(req._validation_errors)
|
|
10
|
+
|
|
11
|
+
req._files.map(f => f.unlink());
|
|
12
|
+
|
|
13
|
+
res.status(200).json({
|
|
14
|
+
body: await req.body(),
|
|
15
|
+
body_hash: req.body_hash(),
|
|
16
|
+
valid_data: req.validDataObj(),
|
|
17
|
+
files: req.files(),
|
|
18
|
+
|
|
19
|
+
//bb: req.validDataObj(),
|
|
20
|
+
cont: req.content_type
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
app.use("/*", TurboExpress.Upload({ memory: true, folder: "/public" }));
|
|
25
|
+
|
|
26
|
+
app.post("/api/v1/test", controller);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
const TurboExpress = require("./lib/TurboServer");
|
|
2
|
+
const RequestInterface = require("./lib/types/RequestInterface");
|
|
3
|
+
const ResponseInterface = require("./lib/types/ResponseInterface");
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const app = new TurboExpress(2);
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
TurboExpress.exeWorker(async () =>
|
|
11
|
+
{
|
|
12
|
+
console.log("Hey")
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
TurboExpress.exeMaster(async () =>
|
|
17
|
+
{
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
console.log("Hello world");
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class MyResponse extends ResponseInterface
|
|
27
|
+
{
|
|
28
|
+
mymethod () {
|
|
29
|
+
console.log("my method")
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
app.Response = MyResponse;
|
|
34
|
+
|
|
35
|
+
app.use("/*", TurboExpress.Cors({
|
|
36
|
+
origins: ["http://localhost:3000"]
|
|
37
|
+
}));
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param {RequestInterface} req
|
|
41
|
+
* @param {ResponseInterface} res
|
|
42
|
+
*/
|
|
43
|
+
function homepage (req, res) {
|
|
44
|
+
console.log("controller")
|
|
45
|
+
res.header("something", "wowowowo")
|
|
46
|
+
res.status(200).json({ user: { username: "kristina" } })
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const router = new TurboExpress.Router();
|
|
50
|
+
router.use("/*", TurboExpress.Cors({}))
|
|
51
|
+
router.get("/something", homepage)
|
|
52
|
+
|
|
53
|
+
app.use("", router);
|
|
54
|
+
|
|
55
|
+
app.get("/something1", homepage);
|
|
56
|
+
// app.options("/something", (req, res) => res.send(""));
|
|
57
|
+
// app.head("/something", (req, res) => res.send(""));
|
|
58
|
+
// app.get("/", homepage);
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
// app.all("/*", (req, res) => {
|
|
62
|
+
// res.send("not")
|
|
63
|
+
// })
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
app.listen(3001, () => console.log("Server is running on port 3000"));
|
package/index.test.js
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const TurboExpress = require("./lib/TurboServer");
|
|
2
|
+
const RequestInterface = require("./lib/types/RequestInterface");
|
|
3
|
+
const ResponseInterface = require("./lib/types/ResponseInterface");
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
const app = new TurboExpress(1);
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class MyValidationError extends TurboExpress.ValidationTypes.ValidationError
|
|
10
|
+
{
|
|
11
|
+
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
class MyRequest extends RequestInterface
|
|
15
|
+
{
|
|
16
|
+
ValidationError = MyValidationError
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
app.Request = MyRequest;
|
|
20
|
+
|
|
21
|
+
app.setLocales("/locales")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
app.get("/public/*", TurboExpress.Static({ folder: "/public" }))
|
|
25
|
+
|
|
26
|
+
// 6976355584
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
app.get("/", () => {});
|
|
30
|
+
|
|
31
|
+
app.listen(3001, () => console.log("Server is running on port 3000"));
|
package/lib/TurboServer.js
CHANGED
|
@@ -23,23 +23,16 @@ const Router = require("./Router");
|
|
|
23
23
|
const cluster = require("cluster");
|
|
24
24
|
const RequestInterface = require("./types/RequestInterface");
|
|
25
25
|
const ResponseInterface = require("./types/ResponseInterface");
|
|
26
|
-
const
|
|
26
|
+
const Util = require("./utils");
|
|
27
27
|
const Route = require("./types/Route");
|
|
28
28
|
const Middleware= require("./types/Middleware");
|
|
29
29
|
const RequestMethods = require("./statictypes/RequestMethods");
|
|
30
30
|
const ServerCallback = require("./ServerCallback");
|
|
31
|
-
const static_middleware = require("./middlewares
|
|
32
|
-
const attachment_middleware = require("./middlewares/attachment_middleware");
|
|
33
|
-
const ValidationSchema = require("./types/ValidationSchema");
|
|
34
|
-
const ValidationMethodType = require("./enum/ValidationMethodType");
|
|
35
|
-
const validation_middleware = require("./middlewares/validation_middleware");
|
|
36
|
-
const runmethod_middleware = require("./middlewares/runmethod_middleware");
|
|
37
|
-
const buildform_middleware = require("./middlewares/buildform_middleware");
|
|
38
|
-
const authentication_middleware = require("./middlewares/authentication_middleware");
|
|
39
|
-
const cors_middleware = require("./middlewares/cors_middleware");
|
|
31
|
+
const { static_middleware, attachment_middleware, validation_middleware, runmethod_middleware, buildform_middleware, authentication_middleware, cors_middleware } = require("./middlewares");
|
|
40
32
|
const AuthenticationService = require("./services/AuthenticationService");
|
|
41
|
-
const
|
|
42
|
-
const
|
|
33
|
+
const SystemTypes = require("./types/SystemTypes");
|
|
34
|
+
const ValidationTypes = require("./types/ValidationTypes");
|
|
35
|
+
const ExpressServices = require("./services");
|
|
43
36
|
|
|
44
37
|
|
|
45
38
|
module.exports = class TurboServer
|
|
@@ -47,15 +40,12 @@ module.exports = class TurboServer
|
|
|
47
40
|
static Router = Router;
|
|
48
41
|
static AuthenticationService = AuthenticationService;
|
|
49
42
|
|
|
50
|
-
static ValidationSchema = ValidationSchema;
|
|
51
|
-
static ValidationMethodType = ValidationMethodType;
|
|
52
|
-
|
|
53
|
-
static SystemService = SystemService;
|
|
54
|
-
static JWTBcryptMongoDBAuthService = JWTBcryptMongoDBAuthService;
|
|
55
|
-
|
|
56
43
|
|
|
57
|
-
static
|
|
44
|
+
static ValidationTypes = ValidationTypes;
|
|
45
|
+
static ExpressServices = ExpressServices;
|
|
58
46
|
|
|
47
|
+
static Log = Util.Log;
|
|
48
|
+
static Util = Util;
|
|
59
49
|
|
|
60
50
|
/**
|
|
61
51
|
* @typedef {Object} StaticOptions
|
|
@@ -94,16 +84,13 @@ module.exports = class TurboServer
|
|
|
94
84
|
* @typedef {Object} AttachmentOptions
|
|
95
85
|
* @property {String} folder - default /storage
|
|
96
86
|
* @property {Boolean} memory - default true
|
|
97
|
-
* @property {Boolean} as_middleware - default true
|
|
98
87
|
*
|
|
99
88
|
* @param {AttachmentOptions} AttachmentOptions
|
|
100
89
|
* @returns
|
|
101
90
|
*/
|
|
102
91
|
static Upload (AttachmentOptions={})
|
|
103
92
|
{
|
|
104
|
-
return attachment_middleware.bind({
|
|
105
|
-
folder: AttachmentOptions.folder || "/storage", memory: AttachmentOptions.memory || true, as_middleware: AttachmentOptions.as_middleware || true
|
|
106
|
-
})
|
|
93
|
+
return attachment_middleware.bind({ folder: AttachmentOptions.folder || "/storage", memory: AttachmentOptions.memory || true })
|
|
107
94
|
}
|
|
108
95
|
|
|
109
96
|
/**
|
|
@@ -111,7 +98,7 @@ module.exports = class TurboServer
|
|
|
111
98
|
* If there is an error, it throws the response with that error.
|
|
112
99
|
*
|
|
113
100
|
* @typedef {Object} ValidationOptions
|
|
114
|
-
* @property {ValidationSchema[]} validations
|
|
101
|
+
* @property {import("./types/ValidationSchema")[]} validations
|
|
115
102
|
*
|
|
116
103
|
* @param {ValidationOptions} ValidationOptions
|
|
117
104
|
* @returns
|
|
@@ -146,7 +133,7 @@ module.exports = class TurboServer
|
|
|
146
133
|
/**
|
|
147
134
|
*
|
|
148
135
|
* @typedef {Object} AuthenticationOptions
|
|
149
|
-
* @property {AuthenticationService} authentication_service
|
|
136
|
+
* @property {import("./services/AuthenticationService")} authentication_service
|
|
150
137
|
*
|
|
151
138
|
* @param {AuthenticationOptions} AuthenticationOptions
|
|
152
139
|
* @returns
|
|
@@ -184,6 +171,19 @@ module.exports = class TurboServer
|
|
|
184
171
|
}
|
|
185
172
|
}
|
|
186
173
|
|
|
174
|
+
/**
|
|
175
|
+
* Execute code only in master instance
|
|
176
|
+
*
|
|
177
|
+
* @param {Function} cb
|
|
178
|
+
*/
|
|
179
|
+
static async exeWorker (cb)
|
|
180
|
+
{
|
|
181
|
+
if(cluster.isWorker)
|
|
182
|
+
{
|
|
183
|
+
await cb();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
187
|
|
|
188
188
|
|
|
189
189
|
/** @type{http.Server} */ #server;
|
|
@@ -218,6 +218,7 @@ module.exports = class TurboServer
|
|
|
218
218
|
/** @type {Map<String, Object>} */ appState = new Map();
|
|
219
219
|
/** @type {Map<String, import("mongoose").Model} */ models = new Map();
|
|
220
220
|
/** @type {Map<String, import("mongoose").Model} */ sqlModels = new Map(); // TODO later
|
|
221
|
+
/** @type {import("./services/LocaleService")} */ localeService = new ExpressServices.LocaleService();
|
|
221
222
|
|
|
222
223
|
/**
|
|
223
224
|
* @param {Number} CLUSTERSLENGTH
|
|
@@ -305,6 +306,16 @@ module.exports = class TurboServer
|
|
|
305
306
|
|
|
306
307
|
}
|
|
307
308
|
|
|
309
|
+
setLocales (locale_directory)
|
|
310
|
+
{
|
|
311
|
+
this.localeService.fillLocales(locale_directory);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/** @returns {http.Server} */
|
|
315
|
+
getServer () {
|
|
316
|
+
return this.#server;
|
|
317
|
+
}
|
|
318
|
+
|
|
308
319
|
|
|
309
320
|
logRoutes ()
|
|
310
321
|
{
|
|
@@ -25,65 +25,19 @@ const multiparty = require("multiparty")
|
|
|
25
25
|
* @param {ResponseInterface} res
|
|
26
26
|
* @param {*} next
|
|
27
27
|
*/
|
|
28
|
-
module.exports = function attachment_middleware (req, res, next)
|
|
28
|
+
module.exports = async function attachment_middleware (req, res, next)
|
|
29
29
|
{
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const { memory, folder } = this;
|
|
33
|
-
console.log(memory, folder);
|
|
34
|
-
|
|
35
|
-
const httpRequest = req.IncomingMessage; //http.IncomingMessage
|
|
36
|
-
const httpResponse = res.OutgoingMessage; //http.OutgoingMessage
|
|
37
|
-
|
|
38
|
-
const files = new Array();
|
|
39
|
-
|
|
40
|
-
if(memory)
|
|
30
|
+
if(this.memory)
|
|
41
31
|
{
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const mine_type = part.headers["content-type"] || "";
|
|
48
|
-
const turboExpressFile = new FileType();
|
|
49
|
-
turboExpressFile.name = part.name;
|
|
50
|
-
turboExpressFile.fileName = part.filename;
|
|
51
|
-
turboExpressFile.is_binary = true;
|
|
52
|
-
turboExpressFile.is_compressible = false;
|
|
53
|
-
turboExpressFile.is_encrypted = false;
|
|
54
|
-
turboExpressFile.extension = mine_type.split("/")[1] || "not-found"
|
|
55
|
-
turboExpressFile.mime_type = mine_type;
|
|
56
|
-
turboExpressFile.buffer_size = part.byteCount;
|
|
57
|
-
turboExpressFile.metadata = {}
|
|
58
|
-
turboExpressFile.description = `File with name = {${turboExpressFile.fileName}}, sent with name = {${turboExpressFile.name}} and stored into server memory;`
|
|
59
|
-
turboExpressFile.owner = null;
|
|
60
|
-
|
|
61
|
-
console.log(turboExpressFile)
|
|
62
|
-
|
|
63
|
-
part.on("data", (chunk) => {
|
|
64
|
-
console.log("$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
|
|
65
|
-
buffer = Buffer.concat([buffer, chunk]);
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
part.on("end", () => {
|
|
69
|
-
console.log("ennennenen")
|
|
70
|
-
turboExpressFile.buffer = buffer;
|
|
71
|
-
turboExpressFile.buffer_size = buffer.length;
|
|
72
|
-
req._files.push(turboExpressFile);
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
})
|
|
76
|
-
form.parse(req.IncomingMessage);
|
|
77
|
-
|
|
78
|
-
form.on("close", () => {
|
|
79
|
-
console.log(req._files, "@@@")
|
|
32
|
+
await req.body();
|
|
33
|
+
req._files.map(f => {
|
|
34
|
+
if(req.body_hash()[f.name]) {
|
|
35
|
+
req._body_hash[f.name] = f.save(this.folder);
|
|
36
|
+
}
|
|
80
37
|
})
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
throw new Error("Currently method to store files not in memory and handle large files, is not implemented.")
|
|
38
|
+
next();
|
|
39
|
+
} else {
|
|
40
|
+
console.log("Attachment middleware is not implemented for large files that require streaming os.write yet");
|
|
41
|
+
res.send("Attachment middleware is not implemented for large files that require streaming os.write yet");
|
|
86
42
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
43
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const attachment_middleware = require("./attachment_middleware");
|
|
2
|
+
const authentication_middleware = require("./authentication_middleware");
|
|
3
|
+
const buildform_middleware = require("./buildform_middleware");
|
|
4
|
+
const cors_middleware = require("./cors_middleware");
|
|
5
|
+
const runmethod_middleware = require("./runmethod_middleware");
|
|
6
|
+
const static_middleware = require("./static_middleware");
|
|
7
|
+
const validation_middleware = require("./validation_middleware");
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
attachment_middleware,
|
|
11
|
+
authentication_middleware,
|
|
12
|
+
buildform_middleware,
|
|
13
|
+
cors_middleware,
|
|
14
|
+
runmethod_middleware,
|
|
15
|
+
static_middleware,
|
|
16
|
+
validation_middleware
|
|
17
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* -->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>
|
|
3
|
+
*
|
|
4
|
+
* @PerfecTEvolutioN
|
|
5
|
+
* @MikeKarypidis
|
|
6
|
+
* @project - TurboExpress
|
|
7
|
+
* @name Middleware
|
|
8
|
+
* @namespace TurboExpress::services::AuthenticationService
|
|
9
|
+
* @license - MIT
|
|
10
|
+
* @copyright - ©2022 PerfectEvolution Corporation;
|
|
11
|
+
* @author - Mike Karypidis
|
|
12
|
+
* @version - 1.0.0
|
|
13
|
+
* @link - https://turboserverjs.org
|
|
14
|
+
* @github - https://github.com/breathfunwithmindte/turbo-server.git
|
|
15
|
+
*
|
|
16
|
+
* -->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const multiparty = require("multiparty")
|
|
20
|
+
const FileType = require("../types/FileType");
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
module.exports = class FormDataService
|
|
24
|
+
{
|
|
25
|
+
|
|
26
|
+
/** @type {import("../types/RequestInterface")} */ req;
|
|
27
|
+
/** @type {Boolean} */ log;
|
|
28
|
+
/** @type {Boolean} */ idk;
|
|
29
|
+
|
|
30
|
+
constructor(props) { this.req = props.req; this.log = props["log"] || false }
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
async memory_read ()
|
|
34
|
+
{
|
|
35
|
+
const _body_hash = new Object();
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
const form = new multiparty.Form({ });
|
|
38
|
+
form.on("part", (part) => {
|
|
39
|
+
let buffer = Buffer.alloc(0);
|
|
40
|
+
let mine_type = part.headers["content-type"] || "";
|
|
41
|
+
let turboExpressFile = new FileType();
|
|
42
|
+
turboExpressFile.name = part.name;
|
|
43
|
+
turboExpressFile.file_name = part.filename || "nofilename";
|
|
44
|
+
turboExpressFile.is_binary= true;
|
|
45
|
+
turboExpressFile.extension = mine_type.split("/")[1] || "not-found"
|
|
46
|
+
turboExpressFile.mime_type = mine_type;
|
|
47
|
+
turboExpressFile.buffer_size = part.byteCount;
|
|
48
|
+
turboExpressFile.description = `File with name = {${turboExpressFile.file_name}}, sent with name = {${turboExpressFile.name}} and stored into server memory;`
|
|
49
|
+
|
|
50
|
+
part.on("data", (chunk) => buffer = Buffer.concat([buffer, chunk]));
|
|
51
|
+
part.on("error", (err) => console.log(err))
|
|
52
|
+
part.on("end", () => {
|
|
53
|
+
turboExpressFile.buffer = buffer;
|
|
54
|
+
turboExpressFile.buffer_size = buffer.length;
|
|
55
|
+
this.req._files.push(turboExpressFile)
|
|
56
|
+
_body_hash[part.name] = `attachment::${turboExpressFile.id}`
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
form.on("error", (err) => {
|
|
60
|
+
console.log(err);
|
|
61
|
+
reject(err);
|
|
62
|
+
})
|
|
63
|
+
form.on("field", (name, value) => _body_hash[name] = this.#getValueByType(value));
|
|
64
|
+
form.on("progress", (...props) => {/** console.log(props) */})
|
|
65
|
+
form.on("close", () => {
|
|
66
|
+
if(this.log === true) console.log("Form data service completed without error, body hash is ~> ", _body_hash);
|
|
67
|
+
resolve(_body_hash);
|
|
68
|
+
})
|
|
69
|
+
form.parse(this.req.IncomingMessage);
|
|
70
|
+
})
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
#getValueByType (value)
|
|
75
|
+
{
|
|
76
|
+
if(typeof value !== "string") return null
|
|
77
|
+
if(value.toLowerCase() === "true") return true;
|
|
78
|
+
if(value.toLowerCase() === "false") return false;
|
|
79
|
+
if(value.toLowerCase() === "nil" || value.toLowerCase() === "null") return null;
|
|
80
|
+
if(!isNaN(Number(value))) return Number(value);
|
|
81
|
+
return value;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
// ! store files
|
|
89
|
+
// async memory_read ()
|
|
90
|
+
// {
|
|
91
|
+
// const _body_hash = new Object();
|
|
92
|
+
// return new Promise((resolve, reject) => {
|
|
93
|
+
// const form = new multiparty.Form({
|
|
94
|
+
// autoFields: true,
|
|
95
|
+
// autoFiles: true,
|
|
96
|
+
// uploadDir: require("path").resolve() + "/samples"
|
|
97
|
+
// });
|
|
98
|
+
// // form.on("part", (part) => {
|
|
99
|
+
// // console.log(part);
|
|
100
|
+
// // //part.on("data", () => {console.log("dataa")})
|
|
101
|
+
// // //part.on("end", (...e) => { console.log("end", e)})
|
|
102
|
+
// // })
|
|
103
|
+
// form.on("error", (err) => {
|
|
104
|
+
// console.log(err);
|
|
105
|
+
// reject(err);
|
|
106
|
+
// })
|
|
107
|
+
// form.on("field", (name, value) => _body_hash[name] = this.#getValueByType(value));
|
|
108
|
+
// form.on("progress", (...props) => {/** console.log(props) */})
|
|
109
|
+
// form.on("close", () => resolve(_body_hash))
|
|
110
|
+
// form.parse(this.req.IncomingMessage);
|
|
111
|
+
// })
|
|
112
|
+
// }
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
|
|
3
|
+
module.exports = class LocaleService
|
|
4
|
+
{
|
|
5
|
+
|
|
6
|
+
/** @type {String[]} */ allowed_locales = new Array();
|
|
7
|
+
/** @type {Map<String, Map<String, String>>} */ locales = new Map();
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param {String} directory
|
|
13
|
+
*/
|
|
14
|
+
fillLocales (directory)
|
|
15
|
+
{
|
|
16
|
+
fs.readdirSync(require("path").resolve() + directory).map(f => {
|
|
17
|
+
if(fs.statSync(require("path").resolve() + directory + "/" + f).isFile() === false)
|
|
18
|
+
{
|
|
19
|
+
this.allowed_locales.push(f);
|
|
20
|
+
const localeMap = new Map();
|
|
21
|
+
fs.readdirSync(require("path").resolve() + directory + "/" + f).map(j => {
|
|
22
|
+
const content = JSON.parse(fs.readFileSync(require("path").resolve() + directory + "/" + f + "/" + j, "utf-8"));
|
|
23
|
+
for (const key in content) if (Object.hasOwnProperty.call(content, key)) { localeMap.set(key, content[key]) }
|
|
24
|
+
this.locales.set(f, localeMap);
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
console.log(this)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
*
|
|
33
|
+
* @param {String} locale
|
|
34
|
+
* @param {String} key
|
|
35
|
+
* @returns {String | null}
|
|
36
|
+
*/
|
|
37
|
+
get (locale, key)
|
|
38
|
+
{
|
|
39
|
+
if(this.locales.has(locale))
|
|
40
|
+
{
|
|
41
|
+
return this.locales.get(locale).get(key) || null
|
|
42
|
+
}
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const AuthenticationService = require("./AuthenticationService");
|
|
2
|
+
const FormDataService = require("./FormDataService");
|
|
3
|
+
const LocaleService = require("./LocaleService");
|
|
4
|
+
const SystemService = require("./SystemService");
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
module.exports = class ExpressService
|
|
8
|
+
{
|
|
9
|
+
static AuthenticationService = AuthenticationService;
|
|
10
|
+
static FormDataService = FormDataService;
|
|
11
|
+
static SystemService = SystemService;
|
|
12
|
+
static LocaleService = LocaleService;
|
|
13
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* -->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>
|
|
3
|
+
*
|
|
4
|
+
* @PerfecTEvolutioN
|
|
5
|
+
* @project - TurboExpress
|
|
6
|
+
* @name TurboExpress
|
|
7
|
+
* @namespace TurboExpress::StaticTypes::ContentType
|
|
8
|
+
* @license - MIT
|
|
9
|
+
* @author - Mike Karypidis
|
|
10
|
+
* @version - 1.0.0
|
|
11
|
+
* @link - https://npmjs.com/TurboExpress
|
|
12
|
+
* @github - https://github.com/TurboExpress
|
|
13
|
+
*
|
|
14
|
+
* -->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
module.exports = class ContentType
|
|
18
|
+
{
|
|
19
|
+
static UNSET = "unset";
|
|
20
|
+
static UNKNOWN = "unknown";
|
|
21
|
+
static APPLICATION_JSON = "application/json";
|
|
22
|
+
static APPLICATION_JAVASCRIPT = "application/javascript";
|
|
23
|
+
static APPLICATION_XML = "application/xml";
|
|
24
|
+
static TEXT_HTML = "text/html";
|
|
25
|
+
static TEXT_PLAIN = "text/plain";
|
|
26
|
+
static APPLICATION_XWWWFORM_URLENCODED = "application/x-www-form-urlencoded"
|
|
27
|
+
static FORMDATA = "multipart/form-data"
|
|
28
|
+
|
|
29
|
+
static GET_CONTENT_TYPE (content_type)
|
|
30
|
+
{
|
|
31
|
+
if(!content_type) return ContentType.UNKNOWN;
|
|
32
|
+
if(content_type.includes("multipart/form-data")) return ContentType.FORMDATA;
|
|
33
|
+
switch (content_type) {
|
|
34
|
+
case "application/json":
|
|
35
|
+
return ContentType.APPLICATION_JSON;
|
|
36
|
+
case "application/javascript":
|
|
37
|
+
return ContentType.APPLICATION_JAVASCRIPT;
|
|
38
|
+
case "application/xml":
|
|
39
|
+
return ContentType.APPLICATION_XML;
|
|
40
|
+
case "text/html":
|
|
41
|
+
return ContentType.TEXT_HTML;
|
|
42
|
+
case "text/plain":
|
|
43
|
+
return ContentType.TEXT_PLAIN;
|
|
44
|
+
case "application/x-www-form-urlencoded":
|
|
45
|
+
return ContentType.APPLICATION_XWWWFORM_URLENCODED;
|
|
46
|
+
default:
|
|
47
|
+
return ContentType.UNKNOWN;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
}
|
package/lib/types/FileType.js
CHANGED
|
@@ -16,40 +16,63 @@
|
|
|
16
16
|
* -->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>-->>
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
|
+
const { random_string } = require("../utils");
|
|
20
|
+
|
|
19
21
|
/** @type */
|
|
20
22
|
module.exports = class FileType
|
|
21
23
|
{
|
|
24
|
+
/** @type {String} */ id;
|
|
22
25
|
/** @type {String} */ name;
|
|
23
|
-
/** @type {String} */
|
|
26
|
+
/** @type {String} */ file_name;
|
|
24
27
|
/** @type {String} */ extension;
|
|
25
28
|
/** @type {String} */ mime_type;
|
|
26
|
-
/** @type {String} */ description;
|
|
27
|
-
/** @type {
|
|
28
|
-
/** @type {boolean} */
|
|
29
|
-
/** @type {boolean} */
|
|
30
|
-
/** @type {boolean} */
|
|
29
|
+
/** @type {String} */ description = "";
|
|
30
|
+
/** @type {String} */ saved_url = "";
|
|
31
|
+
/** @type {boolean} */ is_saved = false;
|
|
32
|
+
/** @type {boolean} */ is_binary = true;
|
|
33
|
+
/** @type {boolean} */ is_compressible = false;
|
|
34
|
+
/** @type {boolean} */ is_encrypted = false;
|
|
31
35
|
/** @type {number} */ buffer_size;
|
|
32
36
|
/** @type {Buffer} */ buffer;
|
|
33
|
-
/** @type {String} */ owner;
|
|
34
|
-
/** @type {*} */ metadata;
|
|
35
|
-
|
|
37
|
+
/** @type {String} */ owner = null;
|
|
38
|
+
/** @type {*} */ metadata = {};
|
|
36
39
|
|
|
37
|
-
|
|
40
|
+
constructor ()
|
|
38
41
|
{
|
|
39
|
-
|
|
42
|
+
this.id = random_string(14);
|
|
40
43
|
}
|
|
41
44
|
|
|
42
|
-
saveSync (path)
|
|
43
|
-
{
|
|
44
45
|
|
|
46
|
+
save(path)
|
|
47
|
+
{
|
|
48
|
+
try {
|
|
49
|
+
require("fs").writeFileSync(`${require("path").resolve()}${path}/${this.id}.${this.extension}`, this.buffer);
|
|
50
|
+
this.is_saved = true;
|
|
51
|
+
this.saved_url = `${path}/${this.id}.${this.extension}`;
|
|
52
|
+
return this.saved_url;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
this.is_saved = false;
|
|
55
|
+
return error.toString();
|
|
56
|
+
}
|
|
45
57
|
}
|
|
46
58
|
|
|
47
|
-
|
|
48
|
-
* @param {*} by
|
|
49
|
-
*/
|
|
50
|
-
fileExtension (by)
|
|
59
|
+
unlink ()
|
|
51
60
|
{
|
|
61
|
+
if(this.is_saved)
|
|
62
|
+
{
|
|
63
|
+
try {
|
|
64
|
+
require("fs").unlinkSync(`${require("path").resolve()}${this.saved_url}`);
|
|
65
|
+
this.is_saved = false;
|
|
66
|
+
this.saved_url = "";
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.log(error);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
52
72
|
|
|
73
|
+
build ()
|
|
74
|
+
{
|
|
75
|
+
return {...this, buffer: null}
|
|
53
76
|
}
|
|
54
77
|
|
|
55
78
|
}
|