formflux 0.0.3 → 0.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/dist/EventHandlers.js +8 -3
- package/dist/EventHandlers.js.map +1 -1
- package/dist/ExtractContent.js +30 -24
- package/dist/ExtractContent.js.map +1 -1
- package/dist/FormFlux.Types.js +2 -1
- package/dist/FormFlux.js +469 -427
- package/dist/FormFlux.js.map +1 -1
- package/dist/FormFluxError.js +3 -1
- package/dist/FormFluxError.js.map +1 -1
- package/dist/SetBodyContentToReq.js +13 -8
- package/dist/SetBodyContentToReq.js.map +1 -1
- package/dist/SetFileContentToReqFile.js +8 -3
- package/dist/SetFileContentToReqFile.js.map +1 -1
- package/dist/WriteFileContent.js +28 -22
- package/dist/WriteFileContent.js.map +1 -1
- package/dist/defaultOptions.js +4 -1
- package/dist/defaultOptions.js.map +1 -1
- package/dist/helpers/resBodyMaker.js +4 -1
- package/dist/helpers/resBodyMaker.js.map +1 -1
- package/dist/setDatatoReqobj.js +3 -1
- package/dist/setDatatoReqobj.js.map +1 -1
- package/dist/setFileNameToBody.js +11 -6
- package/dist/setFileNameToBody.js.map +1 -1
- package/package.json +1 -1
package/dist/FormFlux.js
CHANGED
|
@@ -1,206 +1,232 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const ExtractContent_1 = __importDefault(require("./ExtractContent"));
|
|
16
|
+
const WriteFileContent_1 = __importDefault(require("./WriteFileContent"));
|
|
17
|
+
const SetBodyContentToReq_1 = __importDefault(require("./SetBodyContentToReq"));
|
|
18
|
+
const setFileNameToBody_1 = __importDefault(require("./setFileNameToBody"));
|
|
19
|
+
const setDatatoReqobj_1 = __importDefault(require("./setDatatoReqobj"));
|
|
20
|
+
const EventHandlers_1 = __importDefault(require("./EventHandlers"));
|
|
21
|
+
const FormFluxError_1 = __importDefault(require("./FormFluxError"));
|
|
8
22
|
class Formflux {
|
|
9
23
|
static diskStorage(options) {
|
|
10
24
|
return {
|
|
11
25
|
any() {
|
|
12
|
-
return
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
26
|
+
return function (req, res, next) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
var _a;
|
|
29
|
+
let obj = {
|
|
30
|
+
"originalReq": "",
|
|
31
|
+
"modifiedReq": Buffer.from(""),
|
|
32
|
+
"data": [],
|
|
33
|
+
"content": [],
|
|
34
|
+
"metaData": [],
|
|
35
|
+
"mimeType": [],
|
|
36
|
+
"fieldNameBody": [],
|
|
37
|
+
"fileName": [],
|
|
38
|
+
"modifiedFileName": [],
|
|
39
|
+
"contentBody": [],
|
|
40
|
+
"fieldNameFile": [],
|
|
41
|
+
"filePath": [],
|
|
42
|
+
"filesize": [],
|
|
43
|
+
"streams": []
|
|
44
|
+
};
|
|
45
|
+
let buff = [];
|
|
46
|
+
let reqType = req.headers["content-type"];
|
|
47
|
+
if (reqType && !reqType.includes("multipart/form-data"))
|
|
48
|
+
throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
|
|
49
|
+
let boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
|
|
50
|
+
req.on("data", (chunk) => {
|
|
51
|
+
buff.push(chunk);
|
|
52
|
+
});
|
|
53
|
+
req.on("end", () => {
|
|
54
|
+
var _a;
|
|
55
|
+
try {
|
|
56
|
+
obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
|
|
57
|
+
obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split(`--${boundary}`); // separating the boundary
|
|
58
|
+
obj.data.pop();
|
|
59
|
+
obj.data.shift();
|
|
60
|
+
//*****Defaults*****
|
|
61
|
+
//To*********extract content
|
|
62
|
+
new ExtractContent_1.default(obj, options, null, null).extraction();
|
|
63
|
+
//To*********SetFileDataToReqObj
|
|
64
|
+
new setDatatoReqobj_1.default(obj).populate();
|
|
65
|
+
let writeBool = false;
|
|
66
|
+
let parseBool = false;
|
|
67
|
+
let checkCompletion = (writeComplete, parsecomplete) => {
|
|
68
|
+
if (writeComplete && parsecomplete)
|
|
69
|
+
next();
|
|
70
|
+
};
|
|
71
|
+
EventHandlers_1.default.on("parseEnd", (message) => {
|
|
72
|
+
parseBool = true;
|
|
73
|
+
checkCompletion(writeBool, parseBool);
|
|
74
|
+
});
|
|
75
|
+
EventHandlers_1.default.on("writeEnd", (message) => {
|
|
76
|
+
writeBool = true;
|
|
77
|
+
checkCompletion(writeBool, parseBool);
|
|
78
|
+
});
|
|
79
|
+
new WriteFileContent_1.default(req, obj, options, "any", "disk").writeContent();
|
|
80
|
+
if (options.attachFileToReqBody && options.attachFileToReqBody == true)
|
|
81
|
+
new setFileNameToBody_1.default(obj).setFileNames(req);
|
|
82
|
+
new SetBodyContentToReq_1.default(obj).setBody(req);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
next(err);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
req.on("error", () => {
|
|
89
|
+
next(new FormFluxError_1.default("Error in recieving request", 500));
|
|
90
|
+
});
|
|
73
91
|
});
|
|
74
92
|
};
|
|
75
93
|
},
|
|
76
94
|
fields(optionFields) {
|
|
77
|
-
return
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
new
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
95
|
+
return function (req, res, next) {
|
|
96
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
+
var _a;
|
|
98
|
+
let obj = {
|
|
99
|
+
"originalReq": "",
|
|
100
|
+
"modifiedReq": Buffer.from(""),
|
|
101
|
+
"data": [],
|
|
102
|
+
"content": [],
|
|
103
|
+
"metaData": [],
|
|
104
|
+
"mimeType": [],
|
|
105
|
+
"fieldNameBody": [],
|
|
106
|
+
"fileName": [],
|
|
107
|
+
"modifiedFileName": [],
|
|
108
|
+
"contentBody": [],
|
|
109
|
+
"fieldNameFile": [],
|
|
110
|
+
"filePath": [],
|
|
111
|
+
"filesize": [],
|
|
112
|
+
"streams": []
|
|
113
|
+
};
|
|
114
|
+
let buff = [];
|
|
115
|
+
let reqType = req.headers["content-type"];
|
|
116
|
+
if (reqType && !reqType.includes("multipart/form-data"))
|
|
117
|
+
throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
|
|
118
|
+
let boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
|
|
119
|
+
req.on("data", (chunk) => {
|
|
120
|
+
buff.push(chunk);
|
|
121
|
+
});
|
|
122
|
+
req.on("end", () => {
|
|
123
|
+
var _a;
|
|
124
|
+
try {
|
|
125
|
+
obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
|
|
126
|
+
obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split(`--${boundary}`); // separating the boundary
|
|
127
|
+
obj.data.pop();
|
|
128
|
+
obj.data.shift();
|
|
129
|
+
//*****Defaults*****
|
|
130
|
+
//To*********extract content
|
|
131
|
+
new ExtractContent_1.default(obj, options, optionFields, null).extraction();
|
|
132
|
+
//To*********SetFileDataToReqObj
|
|
133
|
+
new setDatatoReqobj_1.default(obj).populate();
|
|
134
|
+
let writeBool = false;
|
|
135
|
+
let parseBool = false;
|
|
136
|
+
let checkCompletion = (writeComplete, parsecomplete) => {
|
|
137
|
+
if (writeComplete && parsecomplete)
|
|
138
|
+
next();
|
|
139
|
+
};
|
|
140
|
+
EventHandlers_1.default.on("parseEnd", (message) => {
|
|
141
|
+
parseBool = true;
|
|
142
|
+
checkCompletion(writeBool, parseBool);
|
|
143
|
+
});
|
|
144
|
+
EventHandlers_1.default.on("writeEnd", (message) => {
|
|
145
|
+
writeBool = true;
|
|
146
|
+
checkCompletion(writeBool, parseBool);
|
|
147
|
+
});
|
|
148
|
+
new WriteFileContent_1.default(req, obj, options, "fields", "disk").writeContent();
|
|
149
|
+
// new setFileContentToReq(obj).setFileNames(req);
|
|
150
|
+
if (options.attachFileToReqBody && options.attachFileToReqBody == true)
|
|
151
|
+
new setFileNameToBody_1.default(obj).setFileNames(req);
|
|
152
|
+
new SetBodyContentToReq_1.default(obj).setBody(req);
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
next(err);
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
req.on("error", () => {
|
|
159
|
+
next(new FormFluxError_1.default("Error in recieving request", 500));
|
|
160
|
+
});
|
|
139
161
|
});
|
|
140
162
|
};
|
|
141
163
|
},
|
|
142
164
|
single(field) {
|
|
143
|
-
return
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
165
|
+
return function (req, res, next) {
|
|
166
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
167
|
+
var _a;
|
|
168
|
+
let obj = {
|
|
169
|
+
"originalReq": "",
|
|
170
|
+
"modifiedReq": Buffer.from(""),
|
|
171
|
+
"data": [],
|
|
172
|
+
"content": [],
|
|
173
|
+
"metaData": [],
|
|
174
|
+
"mimeType": [],
|
|
175
|
+
"fieldNameBody": [],
|
|
176
|
+
"fileName": [],
|
|
177
|
+
"modifiedFileName": [],
|
|
178
|
+
"contentBody": [],
|
|
179
|
+
"fieldNameFile": [],
|
|
180
|
+
"filePath": [],
|
|
181
|
+
"filesize": [],
|
|
182
|
+
"streams": []
|
|
183
|
+
};
|
|
184
|
+
let buff = [];
|
|
185
|
+
let reqType = req.headers["content-type"];
|
|
186
|
+
if (reqType && !reqType.includes("multipart/form-data"))
|
|
187
|
+
throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
|
|
188
|
+
let boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
|
|
189
|
+
req.on("data", (chunk) => {
|
|
190
|
+
buff.push(chunk);
|
|
191
|
+
});
|
|
192
|
+
req.on("end", () => {
|
|
193
|
+
var _a;
|
|
194
|
+
try {
|
|
195
|
+
obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
|
|
196
|
+
obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split(`--${boundary}`); // separating the boundary
|
|
197
|
+
obj.data.pop();
|
|
198
|
+
obj.data.shift();
|
|
199
|
+
//*****Defaults*****
|
|
200
|
+
//To*********extract content
|
|
201
|
+
new ExtractContent_1.default(obj, options, null, field).extraction();
|
|
202
|
+
//To*********SetFileDataToReqObj
|
|
203
|
+
new setDatatoReqobj_1.default(obj).populate();
|
|
204
|
+
let writeBool = false;
|
|
205
|
+
let parseBool = false;
|
|
206
|
+
let checkCompletion = (writeComplete, parsecomplete) => {
|
|
207
|
+
if (writeComplete && parsecomplete)
|
|
208
|
+
next();
|
|
209
|
+
};
|
|
210
|
+
EventHandlers_1.default.on("parseEnd", (message) => {
|
|
211
|
+
parseBool = true;
|
|
212
|
+
checkCompletion(writeBool, parseBool);
|
|
213
|
+
});
|
|
214
|
+
EventHandlers_1.default.on("writeEnd", (message) => {
|
|
215
|
+
writeBool = true;
|
|
216
|
+
checkCompletion(writeBool, parseBool);
|
|
217
|
+
});
|
|
218
|
+
new WriteFileContent_1.default(req, obj, options, "single", "disk").writeContent();
|
|
219
|
+
if (options.attachFileToReqBody && options.attachFileToReqBody == true)
|
|
220
|
+
new setFileNameToBody_1.default(obj).setFileNames(req);
|
|
221
|
+
new SetBodyContentToReq_1.default(obj).setBody(req);
|
|
222
|
+
}
|
|
223
|
+
catch (err) {
|
|
224
|
+
next(err);
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
req.on("error", () => {
|
|
228
|
+
next(new FormFluxError_1.default("Error in recieving request", 500));
|
|
229
|
+
});
|
|
204
230
|
});
|
|
205
231
|
};
|
|
206
232
|
},
|
|
@@ -209,259 +235,275 @@ class Formflux {
|
|
|
209
235
|
static memoryStorage(options) {
|
|
210
236
|
return {
|
|
211
237
|
any() {
|
|
212
|
-
return
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
238
|
+
return function (req, res, next) {
|
|
239
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
240
|
+
var _a;
|
|
241
|
+
let obj = {
|
|
242
|
+
"originalReq": "",
|
|
243
|
+
"modifiedReq": Buffer.from(""),
|
|
244
|
+
"data": [],
|
|
245
|
+
"content": [],
|
|
246
|
+
"metaData": [],
|
|
247
|
+
"mimeType": [],
|
|
248
|
+
"fieldNameBody": [],
|
|
249
|
+
"fileName": [],
|
|
250
|
+
"modifiedFileName": [],
|
|
251
|
+
"contentBody": [],
|
|
252
|
+
"fieldNameFile": [],
|
|
253
|
+
"filePath": [],
|
|
254
|
+
"filesize": [],
|
|
255
|
+
"streams": []
|
|
256
|
+
};
|
|
257
|
+
let buff = [];
|
|
258
|
+
let reqType = req.headers["content-type"];
|
|
259
|
+
if (reqType && !reqType.includes("multipart/form-data"))
|
|
260
|
+
throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
|
|
261
|
+
let boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
|
|
262
|
+
req.on("data", (chunk) => {
|
|
263
|
+
buff.push(chunk);
|
|
264
|
+
});
|
|
265
|
+
req.on("end", () => {
|
|
266
|
+
var _a;
|
|
267
|
+
try {
|
|
268
|
+
obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
|
|
269
|
+
obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split(`--${boundary}`); // separating the boundary
|
|
270
|
+
obj.data.pop();
|
|
271
|
+
obj.data.shift();
|
|
272
|
+
//*****Defaults*****
|
|
273
|
+
//To*********extract content
|
|
274
|
+
new ExtractContent_1.default(obj, options, null, null).extraction();
|
|
275
|
+
//To*********SetFileDataToReqObj
|
|
276
|
+
new setDatatoReqobj_1.default(obj).populate();
|
|
277
|
+
let writeBool = false;
|
|
278
|
+
let parseBool = false;
|
|
279
|
+
let checkCompletion = (writeComplete, parsecomplete) => {
|
|
280
|
+
if (writeComplete && parsecomplete)
|
|
281
|
+
next();
|
|
282
|
+
};
|
|
283
|
+
EventHandlers_1.default.on("parseEnd", (message) => {
|
|
284
|
+
parseBool = true;
|
|
285
|
+
checkCompletion(writeBool, parseBool);
|
|
286
|
+
});
|
|
287
|
+
EventHandlers_1.default.on("writeEnd", (message) => {
|
|
288
|
+
writeBool = true;
|
|
289
|
+
checkCompletion(writeBool, parseBool);
|
|
290
|
+
});
|
|
291
|
+
new WriteFileContent_1.default(req, obj, options, "any", "memory").writeContent();
|
|
292
|
+
if (options.attachFileToReqBody && options.attachFileToReqBody == true)
|
|
293
|
+
new setFileNameToBody_1.default(obj).setFileNames(req);
|
|
294
|
+
new SetBodyContentToReq_1.default(obj).setBody(req);
|
|
295
|
+
}
|
|
296
|
+
catch (err) {
|
|
297
|
+
next(err);
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
req.on("error", () => {
|
|
301
|
+
next(new FormFluxError_1.default("Error in recieving request", 500));
|
|
302
|
+
});
|
|
273
303
|
});
|
|
274
304
|
};
|
|
275
305
|
},
|
|
276
306
|
fields(optionFields) {
|
|
277
|
-
return
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
307
|
+
return function (req, res, next) {
|
|
308
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
309
|
+
var _a;
|
|
310
|
+
let obj = {
|
|
311
|
+
"originalReq": "",
|
|
312
|
+
"modifiedReq": Buffer.from(""),
|
|
313
|
+
"data": [],
|
|
314
|
+
"content": [],
|
|
315
|
+
"metaData": [],
|
|
316
|
+
"mimeType": [],
|
|
317
|
+
"fieldNameBody": [],
|
|
318
|
+
"fileName": [],
|
|
319
|
+
"modifiedFileName": [],
|
|
320
|
+
"contentBody": [],
|
|
321
|
+
"fieldNameFile": [],
|
|
322
|
+
"filePath": [],
|
|
323
|
+
"filesize": [],
|
|
324
|
+
"streams": []
|
|
325
|
+
};
|
|
326
|
+
let buff = [];
|
|
327
|
+
let reqType = req.headers["content-type"];
|
|
328
|
+
if (reqType && !reqType.includes("multipart/form-data"))
|
|
329
|
+
throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
|
|
330
|
+
let boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
|
|
331
|
+
req.on("data", (chunk) => {
|
|
332
|
+
buff.push(chunk);
|
|
333
|
+
});
|
|
334
|
+
req.on("end", () => {
|
|
335
|
+
var _a;
|
|
336
|
+
try {
|
|
337
|
+
obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
|
|
338
|
+
obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split(`--${boundary}`); // separating the boundary
|
|
339
|
+
obj.data.pop();
|
|
340
|
+
obj.data.shift();
|
|
341
|
+
//*****Defaults*****
|
|
342
|
+
//To*********extract content
|
|
343
|
+
new ExtractContent_1.default(obj, options, optionFields, null).extraction();
|
|
344
|
+
//To*********SetFileDataToReqObj
|
|
345
|
+
new setDatatoReqobj_1.default(obj).populate();
|
|
346
|
+
let writeBool = false;
|
|
347
|
+
let parseBool = false;
|
|
348
|
+
let checkCompletion = (writeComplete, parsecomplete) => {
|
|
349
|
+
if (writeComplete && parsecomplete)
|
|
350
|
+
next();
|
|
351
|
+
};
|
|
352
|
+
EventHandlers_1.default.on("parseEnd", (message) => {
|
|
353
|
+
parseBool = true;
|
|
354
|
+
checkCompletion(writeBool, parseBool);
|
|
355
|
+
});
|
|
356
|
+
EventHandlers_1.default.on("writeEnd", (message) => {
|
|
357
|
+
writeBool = true;
|
|
358
|
+
checkCompletion(writeBool, parseBool);
|
|
359
|
+
});
|
|
360
|
+
new WriteFileContent_1.default(req, obj, options, "fields", "memory").writeContent();
|
|
361
|
+
if (options.attachFileToReqBody && options.attachFileToReqBody == true)
|
|
362
|
+
new setFileNameToBody_1.default(obj).setFileNames(req);
|
|
363
|
+
new SetBodyContentToReq_1.default(obj).setBody(req);
|
|
364
|
+
}
|
|
365
|
+
catch (err) {
|
|
366
|
+
next(err);
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
req.on("error", () => {
|
|
370
|
+
next(new FormFluxError_1.default("Error in recieving request", 500));
|
|
371
|
+
});
|
|
338
372
|
});
|
|
339
373
|
};
|
|
340
374
|
},
|
|
341
375
|
single(field) {
|
|
342
|
-
return
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
376
|
+
return function (req, res, next) {
|
|
377
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
378
|
+
var _a;
|
|
379
|
+
let obj = {
|
|
380
|
+
"originalReq": "",
|
|
381
|
+
"modifiedReq": Buffer.from(""),
|
|
382
|
+
"data": [],
|
|
383
|
+
"content": [],
|
|
384
|
+
"metaData": [],
|
|
385
|
+
"mimeType": [],
|
|
386
|
+
"fieldNameBody": [],
|
|
387
|
+
"fileName": [],
|
|
388
|
+
"modifiedFileName": [],
|
|
389
|
+
"contentBody": [],
|
|
390
|
+
"fieldNameFile": [],
|
|
391
|
+
"filePath": [],
|
|
392
|
+
"filesize": [],
|
|
393
|
+
"streams": []
|
|
394
|
+
};
|
|
395
|
+
let buff = [];
|
|
396
|
+
let reqType = req.headers["content-type"];
|
|
397
|
+
if (reqType && !reqType.includes("multipart/form-data"))
|
|
398
|
+
throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
|
|
399
|
+
let boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
|
|
400
|
+
req.on("data", (chunk) => {
|
|
401
|
+
buff.push(chunk);
|
|
402
|
+
});
|
|
403
|
+
req.on("end", () => {
|
|
404
|
+
var _a;
|
|
405
|
+
try {
|
|
406
|
+
obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
|
|
407
|
+
obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split(`--${boundary}`); // separating the boundary
|
|
408
|
+
obj.data.pop();
|
|
409
|
+
obj.data.shift();
|
|
410
|
+
//*****Defaults*****
|
|
411
|
+
//To*********extract content
|
|
412
|
+
new ExtractContent_1.default(obj, options, null, field).extraction();
|
|
413
|
+
//To*********SetFileDataToReqObj
|
|
414
|
+
new setDatatoReqobj_1.default(obj).populate();
|
|
415
|
+
let writeBool = false;
|
|
416
|
+
let parseBool = false;
|
|
417
|
+
let checkCompletion = (writeComplete, parsecomplete) => {
|
|
418
|
+
if (writeComplete && parsecomplete)
|
|
419
|
+
next();
|
|
420
|
+
};
|
|
421
|
+
EventHandlers_1.default.on("parseEnd", (message) => {
|
|
422
|
+
parseBool = true;
|
|
423
|
+
checkCompletion(writeBool, parseBool);
|
|
424
|
+
});
|
|
425
|
+
EventHandlers_1.default.on("writeEnd", (message) => {
|
|
426
|
+
writeBool = true;
|
|
427
|
+
checkCompletion(writeBool, parseBool);
|
|
428
|
+
});
|
|
429
|
+
new WriteFileContent_1.default(req, obj, options, "single", "memory").writeContent();
|
|
430
|
+
if (options.attachFileToReqBody && options.attachFileToReqBody == true)
|
|
431
|
+
new setFileNameToBody_1.default(obj).setFileNames(req);
|
|
432
|
+
new SetBodyContentToReq_1.default(obj).setBody(req);
|
|
433
|
+
}
|
|
434
|
+
catch (err) {
|
|
435
|
+
next(err);
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
req.on("error", () => {
|
|
439
|
+
next(new FormFluxError_1.default("Error in recieving request", 500));
|
|
440
|
+
});
|
|
403
441
|
});
|
|
404
442
|
};
|
|
405
443
|
},
|
|
406
444
|
};
|
|
407
445
|
}
|
|
408
446
|
bodyParser() {
|
|
409
|
-
return
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
447
|
+
return function (req, res, next) {
|
|
448
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
449
|
+
var _a;
|
|
450
|
+
let obj = {
|
|
451
|
+
"originalReq": "",
|
|
452
|
+
"modifiedReq": Buffer.from(""),
|
|
453
|
+
"data": [],
|
|
454
|
+
"content": [],
|
|
455
|
+
"metaData": [],
|
|
456
|
+
"mimeType": [],
|
|
457
|
+
"fieldNameBody": [],
|
|
458
|
+
"fileName": [],
|
|
459
|
+
"modifiedFileName": [],
|
|
460
|
+
"contentBody": [],
|
|
461
|
+
"fieldNameFile": [],
|
|
462
|
+
"filePath": [],
|
|
463
|
+
"filesize": [],
|
|
464
|
+
"streams": []
|
|
465
|
+
};
|
|
466
|
+
let buff = [];
|
|
467
|
+
let reqType = req.headers["content-type"];
|
|
468
|
+
if (reqType && !reqType.includes("multipart/form-data"))
|
|
469
|
+
throw new FormFluxError_1.default("Invalid Request Type.Expected multipart/form-data", 400);
|
|
470
|
+
let boundary = (_a = req.headers["content-type"]) === null || _a === void 0 ? void 0 : _a.split("boundary=")[1];
|
|
471
|
+
req.on("data", (chunk) => {
|
|
472
|
+
buff.push(chunk);
|
|
473
|
+
});
|
|
474
|
+
req.on("end", () => {
|
|
475
|
+
var _a;
|
|
476
|
+
try {
|
|
477
|
+
obj.modifiedReq = Buffer.concat(buff); // holding the concatinated buffer
|
|
478
|
+
obj.data = (_a = obj.modifiedReq.toString("binary")) === null || _a === void 0 ? void 0 : _a.split(`--${boundary}`); // separating the boundary
|
|
479
|
+
obj.data.pop();
|
|
480
|
+
obj.data.shift();
|
|
481
|
+
//*****Defaults*****
|
|
482
|
+
//To*********extract content
|
|
483
|
+
new ExtractContent_1.default(obj, null, null, null).extraction();
|
|
484
|
+
//To*********SetFileDataToReqObj
|
|
485
|
+
let writeBool = false;
|
|
486
|
+
let parseBool = false;
|
|
487
|
+
let checkCompletion = (writeComplete, parsecomplete) => {
|
|
488
|
+
if (writeComplete && parsecomplete)
|
|
489
|
+
next();
|
|
490
|
+
};
|
|
491
|
+
EventHandlers_1.default.on("parseEnd", (message) => {
|
|
492
|
+
parseBool = true;
|
|
448
493
|
next();
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
next(
|
|
458
|
-
}
|
|
459
|
-
});
|
|
460
|
-
req.on("error", () => {
|
|
461
|
-
next(new FormfluxError("Error in recieving request", 500));
|
|
494
|
+
});
|
|
495
|
+
new SetBodyContentToReq_1.default(obj).setBody(req);
|
|
496
|
+
}
|
|
497
|
+
catch (err) {
|
|
498
|
+
next(err);
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
req.on("error", () => {
|
|
502
|
+
next(new FormFluxError_1.default("Error in recieving request", 500));
|
|
503
|
+
});
|
|
462
504
|
});
|
|
463
505
|
};
|
|
464
506
|
}
|
|
465
507
|
}
|
|
466
|
-
|
|
508
|
+
exports.default = Formflux;
|
|
467
509
|
//# sourceMappingURL=FormFlux.js.map
|