buildfree 1.0.1 → 1.0.3
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 +21 -68
- package/src/index.js +1 -1
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
|
|
|
@@ -152,79 +151,32 @@ class Forms {
|
|
|
152
151
|
}
|
|
153
152
|
|
|
154
153
|
|
|
155
|
-
// ========================================================
|
|
156
|
-
// ADD FILES
|
|
157
154
|
// ========================================================
|
|
158
155
|
|
|
159
|
-
|
|
156
|
+
for (const item of files) {
|
|
160
157
|
|
|
161
|
-
if (!
|
|
158
|
+
if (!item) {
|
|
162
159
|
continue;
|
|
163
160
|
}
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
// ------------------------------------------------------
|
|
169
|
-
|
|
170
|
-
if (file.buffer && Buffer.isBuffer(file.buffer)) {
|
|
171
|
-
|
|
172
|
-
formData.append(
|
|
173
|
-
|
|
174
|
-
file.fieldname,
|
|
175
|
-
|
|
176
|
-
file.buffer,
|
|
177
|
-
|
|
178
|
-
{
|
|
179
|
-
filename:
|
|
180
|
-
file.filename ||
|
|
181
|
-
file.originalname ||
|
|
182
|
-
"upload",
|
|
183
|
-
|
|
184
|
-
contentType:
|
|
185
|
-
file.contentType ||
|
|
186
|
-
file.mimetype
|
|
187
|
-
}
|
|
188
|
-
|
|
161
|
+
|
|
162
|
+
if (!item.fieldname) {
|
|
163
|
+
throw new Error(
|
|
164
|
+
"File fieldname is required"
|
|
189
165
|
);
|
|
190
|
-
|
|
191
|
-
continue;
|
|
192
|
-
|
|
193
166
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
formData.append(
|
|
207
|
-
file.fieldname,
|
|
208
|
-
fs.createReadStream(file.path),
|
|
209
|
-
{
|
|
210
|
-
filename:
|
|
211
|
-
file.filename ||
|
|
212
|
-
file.originalname ||
|
|
213
|
-
file.path.split(/[\\/]/).pop()
|
|
214
|
-
}
|
|
215
|
-
);
|
|
216
|
-
|
|
217
|
-
continue;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
throw new Error(
|
|
222
|
-
`Invalid file for field: ${file.fieldname}`
|
|
167
|
+
|
|
168
|
+
if (!item.file) {
|
|
169
|
+
throw new Error(
|
|
170
|
+
`File is required for field: ${item.fieldname}`
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
formData.append(
|
|
175
|
+
item.fieldname,
|
|
176
|
+
item.file
|
|
223
177
|
);
|
|
224
|
-
|
|
225
178
|
}
|
|
226
179
|
|
|
227
|
-
|
|
228
180
|
// ========================================================
|
|
229
181
|
// SUBMIT
|
|
230
182
|
// ========================================================
|
|
@@ -236,10 +188,11 @@ class Forms {
|
|
|
236
188
|
formData,
|
|
237
189
|
|
|
238
190
|
{
|
|
239
|
-
|
|
240
|
-
|
|
191
|
+
headers: {
|
|
192
|
+
"x-api-key":
|
|
193
|
+
this.client.defaults.headers["x-api-key"]
|
|
194
|
+
}
|
|
241
195
|
}
|
|
242
|
-
}
|
|
243
196
|
|
|
244
197
|
);
|
|
245
198
|
|