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