@itutoring/itutoring_application_js_api 1.24.1 → 1.24.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/apiController.js +18 -5
- package/objects/ApiFile.js +4 -0
- package/package.json +1 -1
package/apiController.js
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import CookiesManager from "./CookiesManager";
|
|
11
11
|
import APICache from "./cache";
|
|
12
12
|
import { R_KEYs } from "./objects/Enums";
|
|
13
|
+
import ApiFile from "./objects/ApiFile";
|
|
13
14
|
|
|
14
15
|
/**
|
|
15
16
|
* Main class for communicating with our backend REST api.
|
|
@@ -296,7 +297,7 @@ class APIController
|
|
|
296
297
|
{
|
|
297
298
|
let formData = new FormData();
|
|
298
299
|
// Extract ApiFiles from data and add them to formData
|
|
299
|
-
const files = this.
|
|
300
|
+
const files = this.ExtractApiFileFromObject(data);
|
|
300
301
|
Object.entries(files).forEach(([key, value]) =>
|
|
301
302
|
{
|
|
302
303
|
formData.append(key, value);
|
|
@@ -307,11 +308,10 @@ class APIController
|
|
|
307
308
|
{
|
|
308
309
|
if (typeof value === "object" && !(value instanceof File) && !(value instanceof ApiFile))
|
|
309
310
|
{
|
|
310
|
-
const files = this.
|
|
311
|
+
const files = this.ExtractApiFileFromObject(value);
|
|
311
312
|
Object.entries(files).forEach(([fKey, fValue]) =>
|
|
312
313
|
{
|
|
313
314
|
formData.append(fKey, fValue);
|
|
314
|
-
delete value[fKey];
|
|
315
315
|
});
|
|
316
316
|
|
|
317
317
|
let jsonVal = JSON.stringify(value);
|
|
@@ -322,14 +322,27 @@ class APIController
|
|
|
322
322
|
return formData;
|
|
323
323
|
}
|
|
324
324
|
|
|
325
|
-
|
|
325
|
+
/**
|
|
326
|
+
* Will remove original ApiFile objects from data and return them as key.
|
|
327
|
+
* @param {*} data
|
|
328
|
+
* @returns
|
|
329
|
+
*/
|
|
330
|
+
static ExtractApiFileFromObject(data)
|
|
326
331
|
{
|
|
327
332
|
let fileAttributes = {};
|
|
328
333
|
Object.entries(data).forEach(([key, value]) =>
|
|
329
334
|
{
|
|
330
335
|
if (typeof value === "object" && value instanceof ApiFile)
|
|
331
336
|
{
|
|
332
|
-
|
|
337
|
+
let index = 0;
|
|
338
|
+
var file = value.File
|
|
339
|
+
while (file != null)
|
|
340
|
+
{
|
|
341
|
+
fileAttributes[key + "_" + index] = file;
|
|
342
|
+
file = file.next;
|
|
343
|
+
index++;
|
|
344
|
+
}
|
|
345
|
+
delete data[key];
|
|
333
346
|
}
|
|
334
347
|
});
|
|
335
348
|
|
package/objects/ApiFile.js
CHANGED