buildfree 1.0.1 → 1.0.2
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/package.json +1 -1
- package/src/forms.js +74 -51
package/package.json
CHANGED
package/src/forms.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const axios = require("axios");
|
|
2
|
-
|
|
3
|
-
const fs = require("fs");
|
|
2
|
+
|
|
4
3
|
|
|
5
4
|
class Forms {
|
|
6
5
|
|
|
@@ -156,74 +155,97 @@ class Forms {
|
|
|
156
155
|
// ADD FILES
|
|
157
156
|
// ========================================================
|
|
158
157
|
|
|
159
|
-
|
|
158
|
+
// for (const file of files) {
|
|
160
159
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
160
|
+
// if (!file) {
|
|
161
|
+
// continue;
|
|
162
|
+
// }
|
|
164
163
|
|
|
165
164
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
165
|
+
// // ------------------------------------------------------
|
|
166
|
+
// // BUFFER
|
|
167
|
+
// // ------------------------------------------------------
|
|
169
168
|
|
|
170
|
-
|
|
169
|
+
// // if (file.buffer && Buffer.isBuffer(file.buffer)) {
|
|
171
170
|
|
|
172
|
-
|
|
171
|
+
// // formData.append(
|
|
173
172
|
|
|
174
|
-
|
|
173
|
+
// // file.fieldname,
|
|
175
174
|
|
|
176
|
-
|
|
175
|
+
// // file.buffer,
|
|
177
176
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
177
|
+
// // {
|
|
178
|
+
// // filename:
|
|
179
|
+
// // file.filename ||
|
|
180
|
+
// // file.originalname ||
|
|
181
|
+
// // "upload",
|
|
183
182
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
183
|
+
// // contentType:
|
|
184
|
+
// // file.contentType ||
|
|
185
|
+
// // file.mimetype
|
|
186
|
+
// // }
|
|
188
187
|
|
|
189
|
-
|
|
188
|
+
// // );
|
|
190
189
|
|
|
191
|
-
|
|
190
|
+
// // continue;
|
|
192
191
|
|
|
193
|
-
|
|
192
|
+
// // }
|
|
194
193
|
|
|
195
194
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
195
|
+
// // // ------------------------------------------------------
|
|
196
|
+
// // // FILE PATH
|
|
197
|
+
// // // ------------------------------------------------------
|
|
199
198
|
|
|
200
|
-
|
|
199
|
+
// // if (file.path) {
|
|
201
200
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
201
|
+
// // if (!fs.existsSync(file.path)) {
|
|
202
|
+
// // throw new Error(`File not found: ${file.path}`);
|
|
203
|
+
// // }
|
|
205
204
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
205
|
+
// // formData.append(
|
|
206
|
+
// // file.fieldname,
|
|
207
|
+
// // fs.createReadStream(file.path),
|
|
208
|
+
// // {
|
|
209
|
+
// // filename:
|
|
210
|
+
// // file.filename ||
|
|
211
|
+
// // file.originalname ||
|
|
212
|
+
// // file.path.split(/[\\/]/).pop()
|
|
213
|
+
// // }
|
|
214
|
+
// // );
|
|
216
215
|
|
|
217
|
-
|
|
218
|
-
|
|
216
|
+
// // continue;
|
|
217
|
+
// // }
|
|
219
218
|
|
|
220
219
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
220
|
+
// throw new Error(
|
|
221
|
+
// `Invalid file for field: ${file.fieldname}`
|
|
222
|
+
// );
|
|
224
223
|
|
|
225
|
-
|
|
224
|
+
// }
|
|
226
225
|
|
|
226
|
+
for (const item of files) {
|
|
227
|
+
|
|
228
|
+
if (!item) {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (!item.fieldname) {
|
|
233
|
+
throw new Error(
|
|
234
|
+
"File fieldname is required"
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (!item.file) {
|
|
239
|
+
throw new Error(
|
|
240
|
+
`File is required for field: ${item.fieldname}`
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
formData.append(
|
|
245
|
+
item.fieldname,
|
|
246
|
+
item.file
|
|
247
|
+
);
|
|
248
|
+
}
|
|
227
249
|
|
|
228
250
|
// ========================================================
|
|
229
251
|
// SUBMIT
|
|
@@ -236,10 +258,11 @@ class Forms {
|
|
|
236
258
|
formData,
|
|
237
259
|
|
|
238
260
|
{
|
|
239
|
-
|
|
240
|
-
|
|
261
|
+
headers: {
|
|
262
|
+
"x-api-key":
|
|
263
|
+
this.client.defaults.headers["x-api-key"]
|
|
264
|
+
}
|
|
241
265
|
}
|
|
242
|
-
}
|
|
243
266
|
|
|
244
267
|
);
|
|
245
268
|
|