@cuppet/core 1.1.1 → 1.1.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/apiFunctions.js +12 -6
package/package.json
CHANGED
package/src/apiFunctions.js
CHANGED
|
@@ -43,9 +43,9 @@ module.exports = {
|
|
|
43
43
|
'Content-Type': 'application/json',
|
|
44
44
|
Accept: 'application/json',
|
|
45
45
|
};
|
|
46
|
-
if (this.
|
|
46
|
+
if (this.request instanceof FormData) {
|
|
47
47
|
defaultHeaders = {};
|
|
48
|
-
Object.assign(defaultHeaders, this.
|
|
48
|
+
Object.assign(defaultHeaders, this.request.getHeaders());
|
|
49
49
|
}
|
|
50
50
|
if (config.has('api.x-api-key')) {
|
|
51
51
|
defaultHeaders['X-Api-Key'] = config.get('api.x-api-key');
|
|
@@ -114,6 +114,8 @@ module.exports = {
|
|
|
114
114
|
...((data instanceof FormData || Object.keys(data).length) && { data }),
|
|
115
115
|
headers: requestHeaders,
|
|
116
116
|
});
|
|
117
|
+
// Delete the request object after the request is sent to avoid conflicts with the next request.
|
|
118
|
+
delete this.request;
|
|
117
119
|
|
|
118
120
|
return this.response;
|
|
119
121
|
} catch (error) {
|
|
@@ -302,10 +304,14 @@ module.exports = {
|
|
|
302
304
|
for (const [key, value] of Object.entries(data)) {
|
|
303
305
|
if (key === 'file') {
|
|
304
306
|
const mimeType = mime.contentType(value) || 'application/octet-stream';
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
307
|
+
if (fs.existsSync(filePath + value)) {
|
|
308
|
+
formData.append('file', fs.createReadStream(filePath + value), {
|
|
309
|
+
filename: value,
|
|
310
|
+
contentType: mimeType,
|
|
311
|
+
});
|
|
312
|
+
} else {
|
|
313
|
+
throw new Error(`File ${filePath + value} does not exist in the files folder!`);
|
|
314
|
+
}
|
|
309
315
|
formData.append('type', mimeType);
|
|
310
316
|
} else {
|
|
311
317
|
formData.append(key, await storage.checkForSavedVariable(value));
|