@eluvio/elv-client-js 4.0.19 → 4.0.20

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.
@@ -534,6 +534,7 @@ exports.UploadFiles = /*#__PURE__*/function () {
534
534
  writeToken: writeToken,
535
535
  uploadId: id,
536
536
  jobId: jobId,
537
+ filePath: _fileInfo2.path,
537
538
  fileData: _fileInfo2.data
538
539
  });
539
540
  case 12:
@@ -728,7 +729,7 @@ exports.UploadStatus = /*#__PURE__*/function () {
728
729
  }();
729
730
  exports.UploadJobStatus = /*#__PURE__*/function () {
730
731
  var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref14) {
731
- var libraryId, objectId, writeToken, uploadId, jobId, path;
732
+ var libraryId, objectId, writeToken, uploadId, jobId, path, jobStatus;
732
733
  return _regeneratorRuntime.wrap(function _callee9$(_context9) {
733
734
  while (1) switch (_context9.prev = _context9.next) {
734
735
  case 0:
@@ -738,16 +739,18 @@ exports.UploadJobStatus = /*#__PURE__*/function () {
738
739
  objectId: objectId
739
740
  });
740
741
  ValidateWriteToken(writeToken);
741
- path = UrlJoin("q", writeToken, "file_jobs", uploadId, "uploads", jobId);
742
+ path = UrlJoin("q", writeToken, "file_jobs", uploadId, "uploads", jobId); // This request is sent during file data upload and might fail due to congestion
743
+ case 4:
744
+ _context9.prev = 4;
742
745
  _context9.t0 = this.utils;
743
746
  _context9.t1 = this.HttpClient;
744
- _context9.next = 8;
747
+ _context9.next = 9;
745
748
  return this.authClient.AuthorizationHeader({
746
749
  libraryId: libraryId,
747
750
  objectId: objectId,
748
751
  update: true
749
752
  });
750
- case 8:
753
+ case 9:
751
754
  _context9.t2 = _context9.sent;
752
755
  _context9.t3 = path;
753
756
  _context9.t4 = {
@@ -757,12 +760,33 @@ exports.UploadJobStatus = /*#__PURE__*/function () {
757
760
  failover: false
758
761
  };
759
762
  _context9.t5 = _context9.t1.Request.call(_context9.t1, _context9.t4);
760
- return _context9.abrupt("return", _context9.t0.ResponseToJson.call(_context9.t0, _context9.t5));
761
- case 13:
763
+ jobStatus = _context9.t0.ResponseToJson.call(_context9.t0, _context9.t5);
764
+ return _context9.abrupt("return", jobStatus);
765
+ case 17:
766
+ _context9.prev = 17;
767
+ _context9.t6 = _context9["catch"](4);
768
+ this.Log(_context9.t6, true);
769
+ retries += 1;
770
+ if (!(retries >= 5)) {
771
+ _context9.next = 23;
772
+ break;
773
+ }
774
+ throw _context9.t6;
775
+ case 23:
776
+ _context9.next = 25;
777
+ return new Promise(function (resolve) {
778
+ return setTimeout(resolve, 10 * retries * 1000);
779
+ });
780
+ case 25:
781
+ if (retries < 5) {
782
+ _context9.next = 4;
783
+ break;
784
+ }
785
+ case 26:
762
786
  case "end":
763
787
  return _context9.stop();
764
788
  }
765
- }, _callee9, this);
789
+ }, _callee9, this, [[4, 17]]);
766
790
  }));
767
791
  return function (_x10) {
768
792
  return _ref15.apply(this, arguments);
@@ -770,11 +794,11 @@ exports.UploadJobStatus = /*#__PURE__*/function () {
770
794
  }();
771
795
  exports.UploadFileData = /*#__PURE__*/function () {
772
796
  var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(_ref16) {
773
- var libraryId, objectId, writeToken, uploadId, jobId, fileData, retries, jobStatus, path;
797
+ var libraryId, objectId, writeToken, uploadId, jobId, filePath, fileData, retries, jobStatus, fileStatus, path;
774
798
  return _regeneratorRuntime.wrap(function _callee10$(_context10) {
775
799
  while (1) switch (_context10.prev = _context10.next) {
776
800
  case 0:
777
- libraryId = _ref16.libraryId, objectId = _ref16.objectId, writeToken = _ref16.writeToken, uploadId = _ref16.uploadId, jobId = _ref16.jobId, fileData = _ref16.fileData;
801
+ libraryId = _ref16.libraryId, objectId = _ref16.objectId, writeToken = _ref16.writeToken, uploadId = _ref16.uploadId, jobId = _ref16.jobId, filePath = _ref16.filePath, fileData = _ref16.fileData;
778
802
  ValidateParameters({
779
803
  libraryId: libraryId,
780
804
  objectId: objectId
@@ -793,16 +817,20 @@ exports.UploadFileData = /*#__PURE__*/function () {
793
817
  });
794
818
  case 7:
795
819
  jobStatus = _context10.sent;
796
- if (!(jobStatus.rem === 0)) {
797
- _context10.next = 12;
820
+ // Find the status of this file
821
+ fileStatus = jobStatus.files.find(function (item) {
822
+ return item.path == filePath;
823
+ });
824
+ if (!(fileStatus.rem === 0)) {
825
+ _context10.next = 13;
798
826
  break;
799
827
  }
800
828
  return _context10.abrupt("return");
801
- case 12:
802
- if (jobStatus.skip) {
803
- fileData = fileData.slice(jobStatus.skip);
804
- }
805
829
  case 13:
830
+ if (fileStatus.skip) {
831
+ fileData = fileData.slice(fileStatus.skip);
832
+ }
833
+ case 14:
806
834
  path = UrlJoin("q", writeToken, "file_jobs", uploadId, jobId);
807
835
  _context10.t0 = this.utils;
808
836
  _context10.t1 = this.HttpClient;
@@ -812,13 +840,13 @@ exports.UploadFileData = /*#__PURE__*/function () {
812
840
  _context10.t5 = {
813
841
  "Content-type": "application/octet-stream"
814
842
  };
815
- _context10.next = 22;
843
+ _context10.next = 23;
816
844
  return this.authClient.AuthorizationHeader({
817
845
  libraryId: libraryId,
818
846
  objectId: objectId,
819
847
  update: true
820
848
  });
821
- case 22:
849
+ case 23:
822
850
  _context10.t6 = _context10.sent;
823
851
  _context10.t7 = (0, _context10.t4)(_context10.t5, _context10.t6);
824
852
  _context10.t8 = {
@@ -830,35 +858,35 @@ exports.UploadFileData = /*#__PURE__*/function () {
830
858
  failover: false
831
859
  };
832
860
  _context10.t9 = _context10.t1.Request.call(_context10.t1, _context10.t8);
833
- _context10.next = 28;
861
+ _context10.next = 29;
834
862
  return _context10.t0.ResponseToJson.call(_context10.t0, _context10.t9);
835
- case 28:
863
+ case 29:
836
864
  return _context10.abrupt("return", _context10.sent);
837
- case 31:
838
- _context10.prev = 31;
865
+ case 32:
866
+ _context10.prev = 32;
839
867
  _context10.t10 = _context10["catch"](4);
840
868
  this.Log(_context10.t10, true);
841
869
  retries += 1;
842
870
  if (!(retries >= 5)) {
843
- _context10.next = 37;
871
+ _context10.next = 38;
844
872
  break;
845
873
  }
846
874
  throw _context10.t10;
847
- case 37:
848
- _context10.next = 39;
875
+ case 38:
876
+ _context10.next = 40;
849
877
  return new Promise(function (resolve) {
850
878
  return setTimeout(resolve, 10 * retries * 1000);
851
879
  });
852
- case 39:
880
+ case 40:
853
881
  if (retries < 5) {
854
882
  _context10.next = 4;
855
883
  break;
856
884
  }
857
- case 40:
885
+ case 41:
858
886
  case "end":
859
887
  return _context10.stop();
860
888
  }
861
- }, _callee10, this, [[4, 31]]);
889
+ }, _callee10, this, [[4, 32]]);
862
890
  }));
863
891
  return function (_x11) {
864
892
  return _ref17.apply(this, arguments);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eluvio/elv-client-js",
3
- "version": "4.0.19",
3
+ "version": "4.0.20",
4
4
  "description": "Javascript client for the Eluvio Content Fabric",
5
5
  "main": "src/index.js",
6
6
  "author": "Kevin Talmadge",
@@ -387,7 +387,7 @@ exports.UploadFiles = async function({libraryId, objectId, writeToken, fileInfo,
387
387
  for(let f = 0; f < files.length; f++) {
388
388
  const fileInfo = files[f];
389
389
 
390
- await this.UploadFileData({libraryId, objectId, writeToken, uploadId: id, jobId, fileData: fileInfo.data});
390
+ await this.UploadFileData({libraryId, objectId, writeToken, uploadId: id, jobId, filePath: fileInfo.path, fileData: fileInfo.data});
391
391
 
392
392
  delete jobSpecs[j].files[f].data;
393
393
  uploaded += fileInfo.len;
@@ -487,30 +487,51 @@ exports.UploadJobStatus = async function({libraryId, objectId, writeToken, uploa
487
487
 
488
488
  const path = UrlJoin("q", writeToken, "file_jobs", uploadId, "uploads", jobId);
489
489
 
490
- return this.utils.ResponseToJson(
491
- this.HttpClient.Request({
492
- headers: await this.authClient.AuthorizationHeader({libraryId, objectId, update: true}),
493
- method: "GET",
494
- path: path,
495
- failover: false
496
- })
497
- );
490
+ // This request is sent during file data upload and might fail due to congestion
491
+ do {
492
+ try {
493
+ let jobStatus = this.utils.ResponseToJson(
494
+ this.HttpClient.Request({
495
+ headers: await this.authClient.AuthorizationHeader({libraryId, objectId, update: true}),
496
+ method: "GET",
497
+ path: path,
498
+ failover: false
499
+ })
500
+ );
501
+ return jobStatus;
502
+ } catch(error) {
503
+ this.Log(error, true);
504
+
505
+ retries += 1;
506
+ if(retries >= 5) {
507
+ throw error;
508
+ }
509
+ await new Promise(resolve => setTimeout(resolve, 10 * retries * 1000));
510
+ }
511
+ } while(retries < 5);
512
+
498
513
  };
499
514
 
500
- exports.UploadFileData = async function({libraryId, objectId, writeToken, uploadId, jobId, fileData}) {
515
+ exports.UploadFileData = async function({libraryId, objectId, writeToken, uploadId, jobId, filePath, fileData}) {
501
516
  ValidateParameters({libraryId, objectId});
502
517
  ValidateWriteToken(writeToken);
503
518
 
504
519
  let retries = 0;
505
520
  do {
506
521
  try {
522
+
507
523
  const jobStatus = await this.UploadJobStatus({libraryId, objectId, writeToken, uploadId, jobId});
508
524
 
509
- if(jobStatus.rem === 0) {
525
+ // Find the status of this file
526
+ const fileStatus = jobStatus.files.find(item => {
527
+ return item.path == filePath
528
+ });
529
+
530
+ if(fileStatus.rem === 0) {
510
531
  // Job is actually done
511
532
  return;
512
- } else if(jobStatus.skip) {
513
- fileData = fileData.slice(jobStatus.skip);
533
+ } else if(fileStatus.skip) {
534
+ fileData = fileData.slice(fileStatus.skip);
514
535
  }
515
536
 
516
537
  let path = UrlJoin("q", writeToken, "file_jobs", uploadId, jobId);