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