@eluvio/elv-client-js 4.0.19 → 4.0.21
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/dist/ElvClient-min.js +3 -3
- package/dist/ElvClient-node-min.js +3 -3
- package/dist/ElvFrameClient-min.js +1 -1
- package/dist/ElvWalletClient-min.js +3 -3
- package/dist/ElvWalletClient-node-min.js +3 -3
- package/dist/src/AuthorizationClient.js +1 -0
- package/dist/src/client/ContentAccess.js +1 -0
- package/dist/src/client/Files.js +63 -29
- package/package.json +1 -1
- package/src/AuthorizationClient.js +1 -1
- package/src/client/ContentAccess.js +1 -1
- package/src/client/Files.js +47 -15
package/dist/src/client/Files.js
CHANGED
|
@@ -534,7 +534,9 @@ exports.UploadFiles = /*#__PURE__*/function () {
|
|
|
534
534
|
writeToken: writeToken,
|
|
535
535
|
uploadId: id,
|
|
536
536
|
jobId: jobId,
|
|
537
|
-
|
|
537
|
+
filePath: _fileInfo2.path,
|
|
538
|
+
fileData: _fileInfo2.data,
|
|
539
|
+
encryption: encryption
|
|
538
540
|
});
|
|
539
541
|
case 12:
|
|
540
542
|
delete jobSpecs[j].files[f].data;
|
|
@@ -728,7 +730,7 @@ exports.UploadStatus = /*#__PURE__*/function () {
|
|
|
728
730
|
}();
|
|
729
731
|
exports.UploadJobStatus = /*#__PURE__*/function () {
|
|
730
732
|
var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref14) {
|
|
731
|
-
var libraryId, objectId, writeToken, uploadId, jobId, path;
|
|
733
|
+
var libraryId, objectId, writeToken, uploadId, jobId, path, retries, jobStatus;
|
|
732
734
|
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
733
735
|
while (1) switch (_context9.prev = _context9.next) {
|
|
734
736
|
case 0:
|
|
@@ -738,16 +740,19 @@ exports.UploadJobStatus = /*#__PURE__*/function () {
|
|
|
738
740
|
objectId: objectId
|
|
739
741
|
});
|
|
740
742
|
ValidateWriteToken(writeToken);
|
|
741
|
-
path = UrlJoin("q", writeToken, "file_jobs", uploadId, "uploads", jobId);
|
|
743
|
+
path = UrlJoin("q", writeToken, "file_jobs", uploadId, "uploads", jobId); // This request is sent during file data upload and might fail due to congestion
|
|
744
|
+
retries = 0;
|
|
745
|
+
case 5:
|
|
746
|
+
_context9.prev = 5;
|
|
742
747
|
_context9.t0 = this.utils;
|
|
743
748
|
_context9.t1 = this.HttpClient;
|
|
744
|
-
_context9.next =
|
|
749
|
+
_context9.next = 10;
|
|
745
750
|
return this.authClient.AuthorizationHeader({
|
|
746
751
|
libraryId: libraryId,
|
|
747
752
|
objectId: objectId,
|
|
748
753
|
update: true
|
|
749
754
|
});
|
|
750
|
-
case
|
|
755
|
+
case 10:
|
|
751
756
|
_context9.t2 = _context9.sent;
|
|
752
757
|
_context9.t3 = path;
|
|
753
758
|
_context9.t4 = {
|
|
@@ -757,12 +762,33 @@ exports.UploadJobStatus = /*#__PURE__*/function () {
|
|
|
757
762
|
failover: false
|
|
758
763
|
};
|
|
759
764
|
_context9.t5 = _context9.t1.Request.call(_context9.t1, _context9.t4);
|
|
760
|
-
|
|
761
|
-
|
|
765
|
+
jobStatus = _context9.t0.ResponseToJson.call(_context9.t0, _context9.t5);
|
|
766
|
+
return _context9.abrupt("return", jobStatus);
|
|
767
|
+
case 18:
|
|
768
|
+
_context9.prev = 18;
|
|
769
|
+
_context9.t6 = _context9["catch"](5);
|
|
770
|
+
this.Log(_context9.t6, true);
|
|
771
|
+
retries += 1;
|
|
772
|
+
if (!(retries >= 5)) {
|
|
773
|
+
_context9.next = 24;
|
|
774
|
+
break;
|
|
775
|
+
}
|
|
776
|
+
throw _context9.t6;
|
|
777
|
+
case 24:
|
|
778
|
+
_context9.next = 26;
|
|
779
|
+
return new Promise(function (resolve) {
|
|
780
|
+
return setTimeout(resolve, 10 * retries * 1000);
|
|
781
|
+
});
|
|
782
|
+
case 26:
|
|
783
|
+
if (retries < 5) {
|
|
784
|
+
_context9.next = 5;
|
|
785
|
+
break;
|
|
786
|
+
}
|
|
787
|
+
case 27:
|
|
762
788
|
case "end":
|
|
763
789
|
return _context9.stop();
|
|
764
790
|
}
|
|
765
|
-
}, _callee9, this);
|
|
791
|
+
}, _callee9, this, [[5, 18]]);
|
|
766
792
|
}));
|
|
767
793
|
return function (_x10) {
|
|
768
794
|
return _ref15.apply(this, arguments);
|
|
@@ -770,11 +796,11 @@ exports.UploadJobStatus = /*#__PURE__*/function () {
|
|
|
770
796
|
}();
|
|
771
797
|
exports.UploadFileData = /*#__PURE__*/function () {
|
|
772
798
|
var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(_ref16) {
|
|
773
|
-
var libraryId, objectId, writeToken, uploadId, jobId, fileData, retries, jobStatus, path;
|
|
799
|
+
var libraryId, objectId, writeToken, encryption, uploadId, jobId, filePath, fileData, retries, jobStatus, fileStatus, path;
|
|
774
800
|
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
775
801
|
while (1) switch (_context10.prev = _context10.next) {
|
|
776
802
|
case 0:
|
|
777
|
-
libraryId = _ref16.libraryId, objectId = _ref16.objectId, writeToken = _ref16.writeToken, uploadId = _ref16.uploadId, jobId = _ref16.jobId, fileData = _ref16.fileData;
|
|
803
|
+
libraryId = _ref16.libraryId, objectId = _ref16.objectId, writeToken = _ref16.writeToken, encryption = _ref16.encryption, uploadId = _ref16.uploadId, jobId = _ref16.jobId, filePath = _ref16.filePath, fileData = _ref16.fileData;
|
|
778
804
|
ValidateParameters({
|
|
779
805
|
libraryId: libraryId,
|
|
780
806
|
objectId: objectId
|
|
@@ -793,16 +819,23 @@ exports.UploadFileData = /*#__PURE__*/function () {
|
|
|
793
819
|
});
|
|
794
820
|
case 7:
|
|
795
821
|
jobStatus = _context10.sent;
|
|
796
|
-
|
|
797
|
-
|
|
822
|
+
// Find the status of this file
|
|
823
|
+
fileStatus = jobStatus.files.find(function (item) {
|
|
824
|
+
return item.path == filePath;
|
|
825
|
+
});
|
|
826
|
+
if (encryption && encryption !== "none") {
|
|
827
|
+
fileStatus = fileStatus.encrypted;
|
|
828
|
+
}
|
|
829
|
+
if (!(fileStatus.rem === 0)) {
|
|
830
|
+
_context10.next = 14;
|
|
798
831
|
break;
|
|
799
832
|
}
|
|
800
833
|
return _context10.abrupt("return");
|
|
801
|
-
case
|
|
802
|
-
if (
|
|
803
|
-
fileData = fileData.slice(
|
|
834
|
+
case 14:
|
|
835
|
+
if (fileStatus.skip) {
|
|
836
|
+
fileData = fileData.slice(fileStatus.skip);
|
|
804
837
|
}
|
|
805
|
-
case
|
|
838
|
+
case 15:
|
|
806
839
|
path = UrlJoin("q", writeToken, "file_jobs", uploadId, jobId);
|
|
807
840
|
_context10.t0 = this.utils;
|
|
808
841
|
_context10.t1 = this.HttpClient;
|
|
@@ -812,13 +845,13 @@ exports.UploadFileData = /*#__PURE__*/function () {
|
|
|
812
845
|
_context10.t5 = {
|
|
813
846
|
"Content-type": "application/octet-stream"
|
|
814
847
|
};
|
|
815
|
-
_context10.next =
|
|
848
|
+
_context10.next = 24;
|
|
816
849
|
return this.authClient.AuthorizationHeader({
|
|
817
850
|
libraryId: libraryId,
|
|
818
851
|
objectId: objectId,
|
|
819
852
|
update: true
|
|
820
853
|
});
|
|
821
|
-
case
|
|
854
|
+
case 24:
|
|
822
855
|
_context10.t6 = _context10.sent;
|
|
823
856
|
_context10.t7 = (0, _context10.t4)(_context10.t5, _context10.t6);
|
|
824
857
|
_context10.t8 = {
|
|
@@ -830,35 +863,35 @@ exports.UploadFileData = /*#__PURE__*/function () {
|
|
|
830
863
|
failover: false
|
|
831
864
|
};
|
|
832
865
|
_context10.t9 = _context10.t1.Request.call(_context10.t1, _context10.t8);
|
|
833
|
-
_context10.next =
|
|
866
|
+
_context10.next = 30;
|
|
834
867
|
return _context10.t0.ResponseToJson.call(_context10.t0, _context10.t9);
|
|
835
|
-
case
|
|
868
|
+
case 30:
|
|
836
869
|
return _context10.abrupt("return", _context10.sent);
|
|
837
|
-
case
|
|
838
|
-
_context10.prev =
|
|
870
|
+
case 33:
|
|
871
|
+
_context10.prev = 33;
|
|
839
872
|
_context10.t10 = _context10["catch"](4);
|
|
840
873
|
this.Log(_context10.t10, true);
|
|
841
874
|
retries += 1;
|
|
842
875
|
if (!(retries >= 5)) {
|
|
843
|
-
_context10.next =
|
|
876
|
+
_context10.next = 39;
|
|
844
877
|
break;
|
|
845
878
|
}
|
|
846
879
|
throw _context10.t10;
|
|
847
|
-
case
|
|
848
|
-
_context10.next =
|
|
880
|
+
case 39:
|
|
881
|
+
_context10.next = 41;
|
|
849
882
|
return new Promise(function (resolve) {
|
|
850
883
|
return setTimeout(resolve, 10 * retries * 1000);
|
|
851
884
|
});
|
|
852
|
-
case
|
|
885
|
+
case 41:
|
|
853
886
|
if (retries < 5) {
|
|
854
887
|
_context10.next = 4;
|
|
855
888
|
break;
|
|
856
889
|
}
|
|
857
|
-
case
|
|
890
|
+
case 42:
|
|
858
891
|
case "end":
|
|
859
892
|
return _context10.stop();
|
|
860
893
|
}
|
|
861
|
-
}, _callee10, this, [[4,
|
|
894
|
+
}, _callee10, this, [[4, 33]]);
|
|
862
895
|
}));
|
|
863
896
|
return function (_x11) {
|
|
864
897
|
return _ref17.apply(this, arguments);
|
|
@@ -1018,7 +1051,7 @@ exports.DeleteFiles = /*#__PURE__*/function () {
|
|
|
1018
1051
|
* @param {string=} versionHash - Hash of the object version - if not specified, latest version will be used
|
|
1019
1052
|
* @param {string=} writeToken - Write token for the draft from which to download the file
|
|
1020
1053
|
* @param {string} filePath - Path to the file to download
|
|
1021
|
-
* @param {string=} format="
|
|
1054
|
+
* @param {string=} format="arrayBuffer" - Format in which to return the data ("blob" | "arraybuffer" | "buffer")
|
|
1022
1055
|
* @param {boolean=} chunked=false - If specified, file will be downloaded and decrypted in chunks. The
|
|
1023
1056
|
* specified callback will be invoked on completion of each chunk. This is recommended for large files.
|
|
1024
1057
|
* @param {number=} chunkSize=1000000 - Size of file chunks to request for download
|
|
@@ -1098,6 +1131,7 @@ exports.DownloadFile = /*#__PURE__*/function () {
|
|
|
1098
1131
|
return this.ContentObjectMetadata({
|
|
1099
1132
|
libraryId: libraryId,
|
|
1100
1133
|
objectId: objectId,
|
|
1134
|
+
versionHash: versionHash,
|
|
1101
1135
|
metadataSubtree: ownerCapKey
|
|
1102
1136
|
});
|
|
1103
1137
|
case 17:
|
package/package.json
CHANGED
|
@@ -192,7 +192,7 @@ class AuthorizationClient {
|
|
|
192
192
|
if(encryption && encryption !== "none" && objectId && await this.AccessType(objectId) === ACCESS_TYPES.OBJECT) {
|
|
193
193
|
const owner = await this.Owner({id: objectId});
|
|
194
194
|
const ownerCapKey = `eluv.caps.iusr${Utils.AddressToHash(this.client.signer.address)}`;
|
|
195
|
-
const ownerCap = await this.client.ContentObjectMetadata({libraryId, objectId, metadataSubtree: ownerCapKey});
|
|
195
|
+
const ownerCap = await this.client.ContentObjectMetadata({libraryId, objectId, versionHash, metadataSubtree: ownerCapKey});
|
|
196
196
|
|
|
197
197
|
if(!Utils.EqualAddress(owner, this.client.signer.address) && !ownerCap) {
|
|
198
198
|
const cap = await this.ReEncryptionConk({libraryId, objectId});
|
|
@@ -2477,7 +2477,7 @@ exports.EncryptionConk = async function({libraryId, objectId, versionHash, write
|
|
|
2477
2477
|
const owner = await this.authClient.Owner({id: objectId});
|
|
2478
2478
|
|
|
2479
2479
|
const ownerCapKey = `eluv.caps.iusr${this.utils.AddressToHash(this.signer.address)}`;
|
|
2480
|
-
const ownerCap = await this.ContentObjectMetadata({libraryId, objectId, metadataSubtree: ownerCapKey});
|
|
2480
|
+
const ownerCap = await this.ContentObjectMetadata({libraryId, objectId, versionHash, metadataSubtree: ownerCapKey});
|
|
2481
2481
|
|
|
2482
2482
|
if(!this.utils.EqualAddress(owner, this.signer.address) && !ownerCap) {
|
|
2483
2483
|
if(download) {
|
package/src/client/Files.js
CHANGED
|
@@ -387,7 +387,16 @@ 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({
|
|
390
|
+
await this.UploadFileData({
|
|
391
|
+
libraryId,
|
|
392
|
+
objectId,
|
|
393
|
+
writeToken,
|
|
394
|
+
uploadId: id,
|
|
395
|
+
jobId,
|
|
396
|
+
filePath: fileInfo.path,
|
|
397
|
+
fileData: fileInfo.data,
|
|
398
|
+
encryption
|
|
399
|
+
});
|
|
391
400
|
|
|
392
401
|
delete jobSpecs[j].files[f].data;
|
|
393
402
|
uploaded += fileInfo.len;
|
|
@@ -487,30 +496,53 @@ exports.UploadJobStatus = async function({libraryId, objectId, writeToken, uploa
|
|
|
487
496
|
|
|
488
497
|
const path = UrlJoin("q", writeToken, "file_jobs", uploadId, "uploads", jobId);
|
|
489
498
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
499
|
+
// This request is sent during file data upload and might fail due to congestion
|
|
500
|
+
let retries = 0;
|
|
501
|
+
do {
|
|
502
|
+
try {
|
|
503
|
+
let jobStatus = this.utils.ResponseToJson(
|
|
504
|
+
this.HttpClient.Request({
|
|
505
|
+
headers: await this.authClient.AuthorizationHeader({libraryId, objectId, update: true}),
|
|
506
|
+
method: "GET",
|
|
507
|
+
path: path,
|
|
508
|
+
failover: false
|
|
509
|
+
})
|
|
510
|
+
);
|
|
511
|
+
return jobStatus;
|
|
512
|
+
} catch(error) {
|
|
513
|
+
this.Log(error, true);
|
|
514
|
+
|
|
515
|
+
retries += 1;
|
|
516
|
+
if(retries >= 5) {
|
|
517
|
+
throw error;
|
|
518
|
+
}
|
|
519
|
+
await new Promise(resolve => setTimeout(resolve, 10 * retries * 1000));
|
|
520
|
+
}
|
|
521
|
+
} while(retries < 5);
|
|
522
|
+
|
|
498
523
|
};
|
|
499
524
|
|
|
500
|
-
exports.UploadFileData = async function({libraryId, objectId, writeToken, uploadId, jobId, fileData}) {
|
|
525
|
+
exports.UploadFileData = async function({libraryId, objectId, writeToken, encryption, uploadId, jobId, filePath, fileData}) {
|
|
501
526
|
ValidateParameters({libraryId, objectId});
|
|
502
527
|
ValidateWriteToken(writeToken);
|
|
503
528
|
|
|
504
529
|
let retries = 0;
|
|
505
530
|
do {
|
|
506
531
|
try {
|
|
532
|
+
|
|
507
533
|
const jobStatus = await this.UploadJobStatus({libraryId, objectId, writeToken, uploadId, jobId});
|
|
508
534
|
|
|
509
|
-
|
|
535
|
+
// Find the status of this file
|
|
536
|
+
let fileStatus = jobStatus.files.find(item => item.path == filePath);
|
|
537
|
+
if(encryption && encryption !== "none") {
|
|
538
|
+
fileStatus = fileStatus.encrypted;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
if(fileStatus.rem === 0) {
|
|
510
542
|
// Job is actually done
|
|
511
543
|
return;
|
|
512
|
-
} else if(
|
|
513
|
-
fileData = fileData.slice(
|
|
544
|
+
} else if(fileStatus.skip) {
|
|
545
|
+
fileData = fileData.slice(fileStatus.skip);
|
|
514
546
|
}
|
|
515
547
|
|
|
516
548
|
let path = UrlJoin("q", writeToken, "file_jobs", uploadId, jobId);
|
|
@@ -616,7 +648,7 @@ exports.DeleteFiles = async function({libraryId, objectId, writeToken, filePaths
|
|
|
616
648
|
* @param {string=} versionHash - Hash of the object version - if not specified, latest version will be used
|
|
617
649
|
* @param {string=} writeToken - Write token for the draft from which to download the file
|
|
618
650
|
* @param {string} filePath - Path to the file to download
|
|
619
|
-
* @param {string=} format="
|
|
651
|
+
* @param {string=} format="arrayBuffer" - Format in which to return the data ("blob" | "arraybuffer" | "buffer")
|
|
620
652
|
* @param {boolean=} chunked=false - If specified, file will be downloaded and decrypted in chunks. The
|
|
621
653
|
* specified callback will be invoked on completion of each chunk. This is recommended for large files.
|
|
622
654
|
* @param {number=} chunkSize=1000000 - Size of file chunks to request for download
|
|
@@ -668,7 +700,7 @@ exports.DownloadFile = async function({
|
|
|
668
700
|
|
|
669
701
|
// If not owner, indicate re-encryption
|
|
670
702
|
const ownerCapKey = `eluv.caps.iusr${this.utils.AddressToHash(this.signer.address)}`;
|
|
671
|
-
const ownerCap = await this.ContentObjectMetadata({libraryId, objectId, metadataSubtree: ownerCapKey});
|
|
703
|
+
const ownerCap = await this.ContentObjectMetadata({libraryId, objectId, versionHash, metadataSubtree: ownerCapKey});
|
|
672
704
|
|
|
673
705
|
if(encrypted && !this.utils.EqualAddress(this.signer.address, await this.ContentObjectOwner({objectId})) && !ownerCap) {
|
|
674
706
|
headers["X-Content-Fabric-Decryption-Mode"] = "reencrypt";
|