flamerest 1.0.63 → 1.0.65

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.
Files changed (2) hide show
  1. package/REST.js +69 -30
  2. package/package.json +1 -1
package/REST.js CHANGED
@@ -504,37 +504,63 @@ class FLAMEREST {
504
504
  // Если в один из параметров передан FileList или input[type=file], т.е. нужно загрузить файлы
505
505
  for (let val in values) {
506
506
 
507
- // Преобразуем
508
- let value = values[val];
509
- let isRef = false;
510
- if (value instanceof Object
511
- && value.hasOwnProperty('_value')
512
- && (
513
- value._value instanceof Event ||
514
- value._value instanceof HTMLInputElement ||
515
- value._value instanceof ClipboardEvent ||
516
- value._value instanceof DataTransfer ||
517
- value._value instanceof FileList
518
- )
519
- ) { value = value.value; isRef = true }
520
-
521
- if (value instanceof Event && value.target instanceof HTMLInputElement && value.target.type === 'file') value = value.target.files;
522
- if (value instanceof HTMLInputElement && value.type === 'file') value = value.files;
523
- if (value instanceof ClipboardEvent) value = value.clipboardData.files;
524
- if (value instanceof DataTransfer) value = value.files;
525
- if (value instanceof FileList) {
526
- let newValues = [];
527
- value = Array.from(value);
528
- for (let file in value) {
529
- newValues.push({
530
- 'name': value[file].name,
531
- 'data': await this.readFileAsync(value[file])
532
- });
507
+ // Пустые значения нам не нужны
508
+ if (values[val] === undefined || values[val] === null) continue;
509
+
510
+ // Любой вариант захода делаем массивом
511
+ let valuesArr = [];
512
+ if (values[val] instanceof Array) valuesArr = values[val];
513
+ else valuesArr = [values[val]];
514
+
515
+ // Идём по каждому значению в массиве
516
+ for (let value of valuesArr) {
517
+
518
+
519
+ // Преобразуем
520
+ let isRef = false;
521
+ if (value instanceof Object
522
+ && value.hasOwnProperty('_value')
523
+ && (
524
+ value._value instanceof Event ||
525
+ value._value instanceof HTMLInputElement ||
526
+ value._value instanceof ClipboardEvent ||
527
+ value._value instanceof DataTransfer ||
528
+ value._value instanceof FileList
529
+ )
530
+ ) { value = value.value; isRef = true }
531
+
532
+ if (value instanceof Event && value.target instanceof HTMLInputElement && value.target.type === 'file') value = value.target.files;
533
+ if (value instanceof HTMLInputElement && value.type === 'file') value = value.files;
534
+ if (value instanceof ClipboardEvent) value = value.clipboardData.files;
535
+ if (value instanceof DataTransfer) value = value.files;
536
+ if (value instanceof FileList) {
537
+ let newValues = [];
538
+ value = Array.from(value);
539
+ for (let file in value) {
540
+ newValues.push({
541
+ 'name': value[file].name,
542
+ 'data': await this.readFileAsync(value[file]),
543
+ 'id': this.generateID(32)
544
+ });
545
+ }
546
+
547
+ /*
548
+ if (isRef)
549
+ values[val].value = newValues;
550
+ else
551
+ values[val] = newValues;
552
+ */
553
+
554
+ if (values[val] instanceof Array) {
555
+ values[val].splice(val);
556
+ values[val].push(...newValues);
557
+ }
558
+ else {
559
+ values[val] = newValues;
560
+ }
561
+
562
+
533
563
  }
534
- if (isRef)
535
- values[val].value = newValues;
536
- else
537
- values[val] = newValues;
538
564
  }
539
565
  }
540
566
 
@@ -583,6 +609,19 @@ class FLAMEREST {
583
609
  return object;
584
610
  }
585
611
 
612
+ generateID(length) {
613
+ let result = '';
614
+ const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
615
+ const charactersLength = characters.length;
616
+ let counter = 0;
617
+ while (counter < length) {
618
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
619
+ counter += 1;
620
+ }
621
+ return result;
622
+ }
623
+
624
+
586
625
  }
587
626
 
588
627
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "flamerest",
3
- "version": "1.0.63",
3
+ "version": "1.0.65",
4
4
  "description": "",
5
5
  "main": "REST.js",
6
6
  "typings": "./REST.d.ts",