@eluvio/elv-client-js 4.0.114 → 4.0.115

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 (129) hide show
  1. package/dist/ElvClient-min.js +67 -0
  2. package/dist/ElvClient-node-min.js +66 -0
  3. package/dist/ElvFrameClient-min.js +60 -0
  4. package/dist/ElvPermissionsClient-min.js +60 -0
  5. package/dist/ElvWalletClient-min.js +67 -0
  6. package/dist/ElvWalletClient-node-min.js +66 -0
  7. package/dist/src/AuthorizationClient.js +2169 -0
  8. package/dist/src/ContentObjectAudit.js +175 -0
  9. package/dist/src/ContentObjectVerification.js +281 -0
  10. package/dist/src/Crypto.js +412 -0
  11. package/dist/src/ElvClient.js +2044 -0
  12. package/dist/src/ElvWallet.js +245 -0
  13. package/dist/src/EthClient.js +1154 -0
  14. package/dist/src/FrameClient.js +485 -0
  15. package/dist/src/HttpClient.js +315 -0
  16. package/dist/src/Id.js +21 -0
  17. package/dist/src/LogMessage.js +25 -0
  18. package/dist/src/PermissionsClient.js +1544 -0
  19. package/dist/src/RemoteSigner.js +385 -0
  20. package/dist/src/UserProfileClient.js +1450 -0
  21. package/dist/src/Utils.js +894 -0
  22. package/dist/src/Validation.js +121 -0
  23. package/dist/src/abr_profiles/abr_profile_live_drm.js +1661 -0
  24. package/dist/src/abr_profiles/abr_profile_live_to_vod.js +1606 -0
  25. package/dist/src/client/ABRPublishing.js +1018 -0
  26. package/dist/src/client/AccessGroups.js +1503 -0
  27. package/dist/src/client/ContentAccess.js +5195 -0
  28. package/dist/src/client/ContentManagement.js +2680 -0
  29. package/dist/src/client/Contracts.js +1520 -0
  30. package/dist/src/client/Files.js +2181 -0
  31. package/dist/src/client/LiveConf.js +569 -0
  32. package/dist/src/client/LiveStream.js +2640 -0
  33. package/dist/src/client/NFT.js +162 -0
  34. package/dist/src/client/NTP.js +581 -0
  35. package/dist/src/contracts/v2/AccessIndexor.js +831 -0
  36. package/dist/src/contracts/v2/Accessible.js +31 -0
  37. package/dist/src/contracts/v2/BaseAccessControlGroup.js +1263 -0
  38. package/dist/src/contracts/v2/BaseAccessWallet.js +1609 -0
  39. package/dist/src/contracts/v2/BaseAccessWalletFactory.js +93 -0
  40. package/dist/src/contracts/v2/BaseContent.js +1076 -0
  41. package/dist/src/contracts/v2/BaseContentFactory.js +219 -0
  42. package/dist/src/contracts/v2/BaseContentSpace.js +1352 -0
  43. package/dist/src/contracts/v2/BaseContentType.js +364 -0
  44. package/dist/src/contracts/v2/BaseFactory.js +107 -0
  45. package/dist/src/contracts/v2/BaseGroupFactory.js +93 -0
  46. package/dist/src/contracts/v2/BaseLibrary.js +1041 -0
  47. package/dist/src/contracts/v2/BaseLibraryFactory.js +96 -0
  48. package/dist/src/contracts/v2/Certifyer.js +86 -0
  49. package/dist/src/contracts/v2/Container.js +540 -0
  50. package/dist/src/contracts/v2/Content.js +443 -0
  51. package/dist/src/contracts/v2/Editable.js +306 -0
  52. package/dist/src/contracts/v2/ExternalUserWallet.js +379 -0
  53. package/dist/src/contracts/v2/IFactorySpace.js +57 -0
  54. package/dist/src/contracts/v2/IKmsSpace.js +52 -0
  55. package/dist/src/contracts/v2/INodeSpace.js +18 -0
  56. package/dist/src/contracts/v2/IUserSpace.js +18 -0
  57. package/dist/src/contracts/v2/LvRecordableStream.js +1037 -0
  58. package/dist/src/contracts/v2/LvRecording.js +627 -0
  59. package/dist/src/contracts/v2/LvStreamRightsHolder.js +562 -0
  60. package/dist/src/contracts/v2/MetaObject.js +119 -0
  61. package/dist/src/contracts/v2/Node.js +167 -0
  62. package/dist/src/contracts/v2/NodeSpace.js +273 -0
  63. package/dist/src/contracts/v2/Ownable.js +87 -0
  64. package/dist/src/contracts/v2/PaymentService.js +627 -0
  65. package/dist/src/contracts/v2/Precompile.js +15 -0
  66. package/dist/src/contracts/v2/Transactable.js +82 -0
  67. package/dist/src/contracts/v2/UserSpace.js +29 -0
  68. package/dist/src/contracts/v2/Utils.js +18 -0
  69. package/dist/src/contracts/v2/Verifier.js +53 -0
  70. package/dist/src/contracts/v2/strings.js +4 -0
  71. package/dist/src/contracts/v3/AccessIndexor.js +774 -0
  72. package/dist/src/contracts/v3/Accessible.js +232 -0
  73. package/dist/src/contracts/v3/Adminable.js +107 -0
  74. package/dist/src/contracts/v3/AvailsDelivery.js +586 -0
  75. package/dist/src/contracts/v3/BaseAccessControlGroup.js +1603 -0
  76. package/dist/src/contracts/v3/BaseAccessWallet.js +1628 -0
  77. package/dist/src/contracts/v3/BaseAccessWalletFactory.js +112 -0
  78. package/dist/src/contracts/v3/BaseContent.js +1312 -0
  79. package/dist/src/contracts/v3/BaseContentFactory.js +183 -0
  80. package/dist/src/contracts/v3/BaseContentFactoryExt.js +175 -0
  81. package/dist/src/contracts/v3/BaseContentSpace.js +1515 -0
  82. package/dist/src/contracts/v3/BaseContentType.js +527 -0
  83. package/dist/src/contracts/v3/BaseFactory.js +126 -0
  84. package/dist/src/contracts/v3/BaseGroupFactory.js +112 -0
  85. package/dist/src/contracts/v3/BaseLibrary.js +1204 -0
  86. package/dist/src/contracts/v3/BaseLibraryFactory.js +115 -0
  87. package/dist/src/contracts/v3/BaseTenantSpace.js +1587 -0
  88. package/dist/src/contracts/v3/Certifyer.js +86 -0
  89. package/dist/src/contracts/v3/Container.js +739 -0
  90. package/dist/src/contracts/v3/Content.js +438 -0
  91. package/dist/src/contracts/v3/CounterObject.js +243 -0
  92. package/dist/src/contracts/v3/Editable.js +519 -0
  93. package/dist/src/contracts/v3/EncToken.js +4 -0
  94. package/dist/src/contracts/v3/ExternalUserWallet.js +587 -0
  95. package/dist/src/contracts/v3/IAdmin.js +18 -0
  96. package/dist/src/contracts/v3/IFactorySpace.js +57 -0
  97. package/dist/src/contracts/v3/IKmsSpace.js +52 -0
  98. package/dist/src/contracts/v3/INodeSpace.js +18 -0
  99. package/dist/src/contracts/v3/IUserSpace.js +32 -0
  100. package/dist/src/contracts/v3/LvRecordableStream.js +1032 -0
  101. package/dist/src/contracts/v3/LvRecording.js +650 -0
  102. package/dist/src/contracts/v3/LvStreamRightsHolder.js +557 -0
  103. package/dist/src/contracts/v3/MetaObject.js +144 -0
  104. package/dist/src/contracts/v3/Node.js +178 -0
  105. package/dist/src/contracts/v3/NodeSpace.js +284 -0
  106. package/dist/src/contracts/v3/Ownable.js +98 -0
  107. package/dist/src/contracts/v3/PaymentService.js +622 -0
  108. package/dist/src/contracts/v3/Precompile.js +26 -0
  109. package/dist/src/contracts/v3/TenantFuncsBase.js +351 -0
  110. package/dist/src/contracts/v3/Transactable.js +82 -0
  111. package/dist/src/contracts/v3/UserSpace.js +43 -0
  112. package/dist/src/contracts/v3/Utils.js +18 -0
  113. package/dist/src/contracts/v3/Verifier.js +53 -0
  114. package/dist/src/contracts/v3/strings.js +4 -0
  115. package/dist/src/contracts/v3b/BaseAccessControlGroup.js +1704 -0
  116. package/dist/src/events/Topics.js +1793 -0
  117. package/dist/src/index.js +8 -0
  118. package/dist/src/walletClient/ClientMethods.js +3102 -0
  119. package/dist/src/walletClient/Configuration.js +38 -0
  120. package/dist/src/walletClient/Notifications.js +168 -0
  121. package/dist/src/walletClient/Profile.js +332 -0
  122. package/dist/src/walletClient/Utils.js +281 -0
  123. package/dist/src/walletClient/index.js +2106 -0
  124. package/package.json +1 -1
  125. package/src/AuthorizationClient.js +24 -16
  126. package/src/ElvClient.js +19 -0
  127. package/src/client/ContentAccess.js +10 -1
  128. package/src/client/LiveConf.js +10 -8
  129. package/src/client/LiveStream.js +6 -4
@@ -0,0 +1,2181 @@
1
+ var _toConsumableArray = require("@babel/runtime/helpers/toConsumableArray");
2
+ var _defineProperty = require("@babel/runtime/helpers/defineProperty");
3
+ var _regeneratorRuntime = require("@babel/runtime/regenerator");
4
+ var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
5
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
+ /**
8
+ * Methods for accessing and managing access groups
9
+ *
10
+ * @module ElvClient/Files+Parts
11
+ */
12
+
13
+ var Utils = require("../Utils");
14
+ var fs;
15
+ if (Utils.Platform() === Utils.PLATFORM_NODE) {
16
+ // Define Response in node
17
+ // eslint-disable-next-line no-global-assign
18
+ globalThis.Response = require("node-fetch").Response;
19
+ fs = require("fs");
20
+ }
21
+ var UrlJoin = require("url-join");
22
+ var _require = require("../Validation"),
23
+ ValidatePresence = _require.ValidatePresence,
24
+ ValidateWriteToken = _require.ValidateWriteToken,
25
+ ValidatePartHash = _require.ValidatePartHash,
26
+ ValidateParameters = _require.ValidateParameters;
27
+
28
+ /* Files */
29
+
30
+ /**
31
+ * List the file information about this object
32
+ *
33
+ * @memberof module:ElvClient/Files+Parts
34
+ * @methodGroup Files
35
+ * @namedParams
36
+ * @param {string=} libraryId - ID of the library
37
+ * @param {string=} objectId - ID of the object
38
+ * @param {string=} path - ID of the object
39
+ * @param {string=} versionHash - Hash of the object version - if not specified, most recent version will be used
40
+ * @param {string=} writeToken - Write token of a draft (incompatible with versionHash)
41
+ */
42
+ exports.ListFiles = /*#__PURE__*/function () {
43
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
44
+ var libraryId, objectId, _ref$path, path, versionHash, writeToken, urlPath;
45
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
46
+ while (1) switch (_context.prev = _context.next) {
47
+ case 0:
48
+ libraryId = _ref.libraryId, objectId = _ref.objectId, _ref$path = _ref.path, path = _ref$path === void 0 ? "" : _ref$path, versionHash = _ref.versionHash, writeToken = _ref.writeToken;
49
+ ValidateParameters({
50
+ libraryId: libraryId,
51
+ objectId: objectId,
52
+ versionHash: versionHash,
53
+ writeToken: writeToken
54
+ });
55
+ if (versionHash) {
56
+ objectId = this.utils.DecodeVersionHash(versionHash).objectId;
57
+ }
58
+ urlPath = UrlJoin("q", writeToken || versionHash || objectId, "files_list", path);
59
+ _context.t0 = this.HttpClient;
60
+ _context.next = 7;
61
+ return this.authClient.AuthorizationHeader({
62
+ libraryId: libraryId,
63
+ objectId: objectId,
64
+ versionHash: versionHash
65
+ });
66
+ case 7:
67
+ _context.t1 = _context.sent;
68
+ _context.t2 = urlPath;
69
+ _context.t3 = {
70
+ headers: _context.t1,
71
+ method: "GET",
72
+ path: _context.t2
73
+ };
74
+ return _context.abrupt("return", _context.t0.RequestJsonBody.call(_context.t0, _context.t3));
75
+ case 11:
76
+ case "end":
77
+ return _context.stop();
78
+ }
79
+ }, _callee, this);
80
+ }));
81
+ return function (_x) {
82
+ return _ref2.apply(this, arguments);
83
+ };
84
+ }();
85
+
86
+ /**
87
+ * Copy/reference files from S3 to a content object.
88
+ *
89
+ * S3 authentication is done by either providing an access key and secret or a presigned URL. The credentials will not be stored (neither in the client nor in the Fabric)
90
+ *
91
+ * NOTE: When providing a presigned URL instead of an access key + secret, the accessKey, secret, region and bucket parameters are not required.
92
+ *
93
+ * Expected format of fileInfo:
94
+ *
95
+ [
96
+ {
97
+ path: string,
98
+ source: string // either a full path e.g. "s3://BUCKET_NAME/path..." or just the path part without "s3://BUCKET_NAME/"
99
+ }
100
+ ]
101
+ *
102
+ * @memberof module:ElvClient/Files+Parts
103
+ * @methodGroup Files
104
+ * @namedParams
105
+ * @param {string} libraryId - ID of the library
106
+ * @param {string} objectId - ID of the object
107
+ * @param {string} writeToken - Write token of the draft
108
+ * @param {string} region - AWS region to use
109
+ * @param {string} bucket - AWS bucket to use
110
+ * @param {Array<Object>} fileInfo - List of files to reference/copy
111
+ * @param {string} accessKey - AWS access key
112
+ * @param {string} secret - AWS secret
113
+ * @param {string=} signedUrl
114
+ * @param {string} encryption="none" - Encryption for uploaded files (copy only) - cgck | none
115
+ * @param {boolean} copy=false - If true, will copy the data from S3 into the fabric. Otherwise, a reference to the content will be made.
116
+ * @param {function=} callback - If specified, will be periodically called with current upload status
117
+ * - Arguments (copy): { done: boolean, uploaded: number, total: number, uploadedFiles: number, totalFiles: number, fileStatus: Object }
118
+ * - Arguments (reference): { done: boolean, uploadedFiles: number, totalFiles: number }
119
+ */
120
+ exports.UploadFilesFromS3 = /*#__PURE__*/function () {
121
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref3) {
122
+ var libraryId, objectId, writeToken, region, bucket, fileInfo, accessKey, secret, signedUrl, _ref3$encryption, encryption, _ref3$copy, copy, callback, s3prefixRegex, i, fileSourcePath, s3prefixMatch, bucketName, encryption_key, conk, cloudCredentials, defaults, ops, _yield$this$CreateFil, id, status, done, progress, _progress;
123
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
124
+ while (1) switch (_context2.prev = _context2.next) {
125
+ case 0:
126
+ libraryId = _ref3.libraryId, objectId = _ref3.objectId, writeToken = _ref3.writeToken, region = _ref3.region, bucket = _ref3.bucket, fileInfo = _ref3.fileInfo, accessKey = _ref3.accessKey, secret = _ref3.secret, signedUrl = _ref3.signedUrl, _ref3$encryption = _ref3.encryption, encryption = _ref3$encryption === void 0 ? "none" : _ref3$encryption, _ref3$copy = _ref3.copy, copy = _ref3$copy === void 0 ? false : _ref3$copy, callback = _ref3.callback;
127
+ ValidateParameters({
128
+ libraryId: libraryId,
129
+ objectId: objectId
130
+ });
131
+ ValidateWriteToken(writeToken);
132
+ s3prefixRegex = /^s3:\/\/([^/]+)\//i; // for matching and extracting bucket name when full s3:// path is specified
133
+ // if fileInfo source paths start with s3://bucketName/, check against bucket arg passed in, and strip
134
+ i = 0;
135
+ case 5:
136
+ if (!(i < fileInfo.length)) {
137
+ _context2.next = 18;
138
+ break;
139
+ }
140
+ fileSourcePath = fileInfo[i].source;
141
+ s3prefixMatch = s3prefixRegex.exec(fileSourcePath);
142
+ if (!s3prefixMatch) {
143
+ _context2.next = 15;
144
+ break;
145
+ }
146
+ bucketName = s3prefixMatch[1];
147
+ if (!(bucketName !== bucket)) {
148
+ _context2.next = 14;
149
+ break;
150
+ }
151
+ throw Error("Full S3 file path \"" + fileSourcePath + "\" specified, but does not match provided bucket name '" + bucket + "'");
152
+ case 14:
153
+ // strip prefix
154
+ fileInfo[i].source = fileSourcePath.replace(s3prefixRegex, "");
155
+ case 15:
156
+ i++;
157
+ _context2.next = 5;
158
+ break;
159
+ case 18:
160
+ if (copy) {
161
+ this.Log("Copying files from S3: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
162
+ } else {
163
+ this.Log("Adding links to files in S3: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
164
+ }
165
+ if (!(encryption === "cgck")) {
166
+ _context2.next = 25;
167
+ break;
168
+ }
169
+ _context2.next = 22;
170
+ return this.EncryptionConk({
171
+ libraryId: libraryId,
172
+ objectId: objectId,
173
+ writeToken: writeToken
174
+ });
175
+ case 22:
176
+ conk = _context2.sent;
177
+ conk = _objectSpread(_objectSpread({}, conk), {}, {
178
+ secret_key: ""
179
+ });
180
+ encryption_key = "kp__".concat(this.utils.B58(Buffer.from(JSON.stringify(conk))));
181
+ case 25:
182
+ cloudCredentials = {
183
+ access_key_id: accessKey,
184
+ secret_access_key: secret
185
+ };
186
+ if (signedUrl) {
187
+ cloudCredentials = {
188
+ signed_url: signedUrl
189
+ };
190
+ }
191
+ defaults = {
192
+ encryption_key: encryption_key,
193
+ access: {
194
+ protocol: "s3",
195
+ platform: "aws",
196
+ path: bucket,
197
+ storage_endpoint: {
198
+ region: region
199
+ },
200
+ cloud_credentials: cloudCredentials
201
+ }
202
+ };
203
+ ops = fileInfo.map(function (info) {
204
+ if (copy) {
205
+ return {
206
+ op: "ingest-copy",
207
+ path: info.path,
208
+ encryption: {
209
+ scheme: encryption === "cgck" ? "cgck" : "none"
210
+ },
211
+ ingest: {
212
+ type: "key",
213
+ path: info.source
214
+ }
215
+ };
216
+ } else {
217
+ return {
218
+ op: "add-reference",
219
+ path: info.path,
220
+ reference: {
221
+ type: "key",
222
+ path: info.source
223
+ }
224
+ };
225
+ }
226
+ }); // eslint-disable-next-line no-unused-vars
227
+ _context2.next = 31;
228
+ return this.CreateFileUploadJob({
229
+ libraryId: libraryId,
230
+ objectId: objectId,
231
+ writeToken: writeToken,
232
+ ops: ops,
233
+ defaults: defaults
234
+ });
235
+ case 31:
236
+ _yield$this$CreateFil = _context2.sent;
237
+ id = _yield$this$CreateFil.id;
238
+ case 33:
239
+ if (!true) {
240
+ _context2.next = 56;
241
+ break;
242
+ }
243
+ _context2.next = 36;
244
+ return new Promise(function (resolve) {
245
+ return setTimeout(resolve, 1000);
246
+ });
247
+ case 36:
248
+ _context2.next = 38;
249
+ return this.UploadStatus({
250
+ libraryId: libraryId,
251
+ objectId: objectId,
252
+ writeToken: writeToken,
253
+ uploadId: id
254
+ });
255
+ case 38:
256
+ status = _context2.sent;
257
+ if (!(status.errors && status.errors.length > 1)) {
258
+ _context2.next = 43;
259
+ break;
260
+ }
261
+ throw status.errors.join("\n");
262
+ case 43:
263
+ if (!status.error) {
264
+ _context2.next = 48;
265
+ break;
266
+ }
267
+ this.Log("S3 file upload failed:\n".concat(JSON.stringify(status, null, 2)));
268
+ throw status.error;
269
+ case 48:
270
+ if (!(status.status.toLowerCase() === "failed")) {
271
+ _context2.next = 50;
272
+ break;
273
+ }
274
+ throw "File upload failed";
275
+ case 50:
276
+ done = false;
277
+ if (copy) {
278
+ done = status.ingest_copy.done;
279
+ if (callback) {
280
+ progress = status.ingest_copy.progress;
281
+ callback({
282
+ done: done,
283
+ uploaded: progress.bytes.completed,
284
+ total: progress.bytes.total,
285
+ uploadedFiles: progress.files.completed,
286
+ totalFiles: progress.files.total,
287
+ fileStatus: progress.files.details
288
+ });
289
+ }
290
+ } else {
291
+ done = status.add_reference.done;
292
+ if (callback) {
293
+ _progress = status.add_reference.progress;
294
+ callback({
295
+ done: done,
296
+ uploadedFiles: _progress.completed,
297
+ totalFiles: _progress.total
298
+ });
299
+ }
300
+ }
301
+ if (!done) {
302
+ _context2.next = 54;
303
+ break;
304
+ }
305
+ return _context2.abrupt("break", 56);
306
+ case 54:
307
+ _context2.next = 33;
308
+ break;
309
+ case 56:
310
+ case "end":
311
+ return _context2.stop();
312
+ }
313
+ }, _callee2, this);
314
+ }));
315
+ return function (_x2) {
316
+ return _ref4.apply(this, arguments);
317
+ };
318
+ }();
319
+
320
+ /**
321
+ * Upload files to a content object.
322
+ *
323
+ * Expected format of fileInfo:
324
+ *
325
+ [
326
+ {
327
+ path: string,
328
+ mime_type: string,
329
+ size: number,
330
+ data: File | ArrayBuffer | Buffer | File Descriptor (Node)
331
+ }
332
+ ]
333
+ *
334
+ *
335
+ * @memberof module:ElvClient/Files+Parts
336
+ * @methodGroup Files
337
+ * @namedParams
338
+ * @param {string} libraryId - ID of the library
339
+ * @param {string} objectId - ID of the object
340
+ * @param {string} writeToken - Write token of the draft
341
+ * @param {Array<object>} fileInfo - List of files to upload, including their size, type, and contents
342
+ * @param {string} encryption="none" - Encryption for uploaded files - cgck | none
343
+ * @param {function=} callback - If specified, will be called after each job segment is finished with the current upload progress
344
+ * - Format: {"filename1": {uploaded: number, total: number}, ...}
345
+ */
346
+ exports.UploadFiles = /*#__PURE__*/function () {
347
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref5) {
348
+ var _this = this;
349
+ var libraryId, objectId, writeToken, fileInfo, _ref5$encryption, encryption, callback, conk, progress, fileDataMap, originalFileInfo, i, entry, _yield$this$CreateFil2, id, jobs, bufferSize, jobSpecs, prepared, uploaded, PrepareJobs, UploadJob, rateTestJobs, rates, j, start, elapsed, size, averageRate, concurrentUploads;
350
+ return _regeneratorRuntime.wrap(function _callee6$(_context7) {
351
+ while (1) switch (_context7.prev = _context7.next) {
352
+ case 0:
353
+ libraryId = _ref5.libraryId, objectId = _ref5.objectId, writeToken = _ref5.writeToken, fileInfo = _ref5.fileInfo, _ref5$encryption = _ref5.encryption, encryption = _ref5$encryption === void 0 ? "none" : _ref5$encryption, callback = _ref5.callback;
354
+ ValidateParameters({
355
+ libraryId: libraryId,
356
+ objectId: objectId
357
+ });
358
+ ValidateWriteToken(writeToken);
359
+ ValidatePresence("fileInfo", fileInfo);
360
+ this.Log("Uploading files: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
361
+ if (!(encryption === "cgck")) {
362
+ _context7.next = 9;
363
+ break;
364
+ }
365
+ _context7.next = 8;
366
+ return this.EncryptionConk({
367
+ libraryId: libraryId,
368
+ objectId: objectId,
369
+ writeToken: writeToken
370
+ });
371
+ case 8:
372
+ conk = _context7.sent;
373
+ case 9:
374
+ // Extract file data into easily accessible hash while removing the data from the fileinfo for upload job creation
375
+ progress = {};
376
+ fileDataMap = {};
377
+ originalFileInfo = fileInfo;
378
+ fileInfo = [];
379
+ for (i = 0; i < originalFileInfo.length; i++) {
380
+ entry = _objectSpread(_objectSpread({}, originalFileInfo[i]), {}, {
381
+ data: undefined
382
+ });
383
+ entry.path = entry.path.replace(/^\/+/, "");
384
+ if (encryption === "cgck") {
385
+ entry.encryption = {
386
+ scheme: "cgck"
387
+ };
388
+ }
389
+ fileDataMap[entry.path] = originalFileInfo[i].data;
390
+ entry.type = "file";
391
+ progress[entry.path] = {
392
+ uploaded: 0,
393
+ total: entry.size
394
+ };
395
+ fileInfo.push(entry);
396
+ }
397
+ this.Log(fileInfo);
398
+ if (callback) {
399
+ callback(progress);
400
+ }
401
+ _context7.next = 18;
402
+ return this.CreateFileUploadJob({
403
+ libraryId: libraryId,
404
+ objectId: objectId,
405
+ writeToken: writeToken,
406
+ ops: fileInfo,
407
+ encryption: encryption
408
+ });
409
+ case 18:
410
+ _yield$this$CreateFil2 = _context7.sent;
411
+ id = _yield$this$CreateFil2.id;
412
+ jobs = _yield$this$CreateFil2.jobs;
413
+ this.Log("Upload ID: ".concat(id));
414
+ this.Log(jobs);
415
+
416
+ // How far encryption can get ahead of upload
417
+ bufferSize = 500 * 1024 * 1024;
418
+ jobSpecs = [];
419
+ prepared = 0;
420
+ uploaded = 0; // Insert the data to upload into the job spec, encrypting if necessary
421
+ PrepareJobs = /*#__PURE__*/function () {
422
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
423
+ var j, jobId, job, f, _fileInfo, data;
424
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
425
+ while (1) switch (_context3.prev = _context3.next) {
426
+ case 0:
427
+ j = 0;
428
+ case 1:
429
+ if (!(j < jobs.length)) {
430
+ _context3.next = 31;
431
+ break;
432
+ }
433
+ case 2:
434
+ if (!(prepared - uploaded > bufferSize)) {
435
+ _context3.next = 7;
436
+ break;
437
+ }
438
+ _context3.next = 5;
439
+ return new Promise(function (resolve) {
440
+ return setTimeout(resolve, 500);
441
+ });
442
+ case 5:
443
+ _context3.next = 2;
444
+ break;
445
+ case 7:
446
+ // Retrieve job info
447
+ jobId = jobs[j];
448
+ _context3.next = 10;
449
+ return _this.UploadJobStatus({
450
+ libraryId: libraryId,
451
+ objectId: objectId,
452
+ writeToken: writeToken,
453
+ uploadId: id,
454
+ jobId: jobId
455
+ });
456
+ case 10:
457
+ job = _context3.sent;
458
+ f = 0;
459
+ case 12:
460
+ if (!(f < job.files.length)) {
461
+ _context3.next = 25;
462
+ break;
463
+ }
464
+ _fileInfo = job.files[f];
465
+ data = void 0;
466
+ if (typeof fileDataMap[_fileInfo.path] === "number") {
467
+ // File descriptor - Read data from file
468
+ data = Buffer.alloc(_fileInfo.len);
469
+ fs.readSync(fileDataMap[_fileInfo.path], data, 0, _fileInfo.len, _fileInfo.off);
470
+ } else {
471
+ // Full data - Slice requested chunk
472
+ data = fileDataMap[_fileInfo.path].slice(_fileInfo.off, _fileInfo.off + _fileInfo.len);
473
+ }
474
+ if (!(encryption === "cgck")) {
475
+ _context3.next = 20;
476
+ break;
477
+ }
478
+ _context3.next = 19;
479
+ return _this.Crypto.Encrypt(conk, data);
480
+ case 19:
481
+ data = _context3.sent;
482
+ case 20:
483
+ job.files[f].data = data;
484
+ prepared += _fileInfo.len;
485
+ case 22:
486
+ f++;
487
+ _context3.next = 12;
488
+ break;
489
+ case 25:
490
+ jobSpecs[j] = job;
491
+
492
+ // Wait for a bit to let upload start
493
+ _context3.next = 28;
494
+ return new Promise(function (resolve) {
495
+ return setTimeout(resolve, 50);
496
+ });
497
+ case 28:
498
+ j++;
499
+ _context3.next = 1;
500
+ break;
501
+ case 31:
502
+ case "end":
503
+ return _context3.stop();
504
+ }
505
+ }, _callee3);
506
+ }));
507
+ return function PrepareJobs() {
508
+ return _ref7.apply(this, arguments);
509
+ };
510
+ }();
511
+ UploadJob = /*#__PURE__*/function () {
512
+ var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(jobId, j) {
513
+ var jobSpec, files, _loop, f;
514
+ return _regeneratorRuntime.wrap(function _callee4$(_context5) {
515
+ while (1) switch (_context5.prev = _context5.next) {
516
+ case 0:
517
+ if (jobSpecs[j]) {
518
+ _context5.next = 5;
519
+ break;
520
+ }
521
+ _context5.next = 3;
522
+ return new Promise(function (resolve) {
523
+ return setTimeout(resolve, 500);
524
+ });
525
+ case 3:
526
+ _context5.next = 0;
527
+ break;
528
+ case 5:
529
+ jobSpec = jobSpecs[j];
530
+ files = jobSpec.files; // Upload each item
531
+ _loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
532
+ var fileInfo, retries, succeeded;
533
+ return _regeneratorRuntime.wrap(function _loop$(_context4) {
534
+ while (1) switch (_context4.prev = _context4.next) {
535
+ case 0:
536
+ fileInfo = files[f];
537
+ retries = 0;
538
+ succeeded = false;
539
+ case 3:
540
+ _context4.prev = 3;
541
+ _context4.next = 6;
542
+ return _this.UploadFileData({
543
+ libraryId: libraryId,
544
+ objectId: objectId,
545
+ writeToken: writeToken,
546
+ uploadId: id,
547
+ jobId: jobId,
548
+ filePath: fileInfo.path,
549
+ fileData: fileInfo.data,
550
+ encryption: encryption
551
+ });
552
+ case 6:
553
+ succeeded = true;
554
+ _context4.next = 17;
555
+ break;
556
+ case 9:
557
+ _context4.prev = 9;
558
+ _context4.t0 = _context4["catch"](3);
559
+ _this.Log(_context4.t0, true);
560
+ retries += 1;
561
+ if (!(retries >= 10)) {
562
+ _context4.next = 15;
563
+ break;
564
+ }
565
+ throw _context4.t0;
566
+ case 15:
567
+ _context4.next = 17;
568
+ return new Promise(function (resolve) {
569
+ return setTimeout(resolve, 10 * retries * 1000);
570
+ });
571
+ case 17:
572
+ if (!succeeded && retries < 10) {
573
+ _context4.next = 3;
574
+ break;
575
+ }
576
+ case 18:
577
+ delete jobSpecs[j].files[f].data;
578
+ uploaded += fileInfo.len;
579
+ if (callback) {
580
+ progress[fileInfo.path] = _objectSpread(_objectSpread({}, progress[fileInfo.path]), {}, {
581
+ uploaded: progress[fileInfo.path].uploaded + fileInfo.len
582
+ });
583
+ callback(progress);
584
+ }
585
+ case 21:
586
+ case "end":
587
+ return _context4.stop();
588
+ }
589
+ }, _loop, null, [[3, 9]]);
590
+ });
591
+ f = 0;
592
+ case 9:
593
+ if (!(f < files.length)) {
594
+ _context5.next = 14;
595
+ break;
596
+ }
597
+ return _context5.delegateYield(_loop(), "t0", 11);
598
+ case 11:
599
+ f++;
600
+ _context5.next = 9;
601
+ break;
602
+ case 14:
603
+ case "end":
604
+ return _context5.stop();
605
+ }
606
+ }, _callee4);
607
+ }));
608
+ return function UploadJob(_x4, _x5) {
609
+ return _ref8.apply(this, arguments);
610
+ };
611
+ }(); // Preparing jobs is done asynchronously
612
+ PrepareJobs()["catch"](function (e) {
613
+ throw e;
614
+ });
615
+
616
+ // Upload the first several chunks in sequence, to determine average upload rate
617
+ rateTestJobs = Math.min(3, jobs.length);
618
+ rates = [];
619
+ j = 0;
620
+ case 33:
621
+ if (!(j < rateTestJobs)) {
622
+ _context7.next = 43;
623
+ break;
624
+ }
625
+ start = new Date().getTime();
626
+ _context7.next = 37;
627
+ return UploadJob(jobs[j], j);
628
+ case 37:
629
+ elapsed = (new Date().getTime() - start) / 1000;
630
+ size = jobSpecs[j].files.map(function (file) {
631
+ return file.len;
632
+ }).reduce(function (length, total) {
633
+ return length + total;
634
+ }, 0);
635
+ rates.push(size / elapsed / (1024 * 1024));
636
+ case 40:
637
+ j++;
638
+ _context7.next = 33;
639
+ break;
640
+ case 43:
641
+ averageRate = rates.reduce(function (mbps, total) {
642
+ return mbps + total;
643
+ }, 0) / rateTestJobs; // Upload remaining jobs in parallel
644
+ concurrentUploads = Math.min(5, Math.ceil(averageRate / 2));
645
+ _context7.next = 47;
646
+ return this.utils.LimitedMap(concurrentUploads, jobs, /*#__PURE__*/function () {
647
+ var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(jobId, j) {
648
+ return _regeneratorRuntime.wrap(function _callee5$(_context6) {
649
+ while (1) switch (_context6.prev = _context6.next) {
650
+ case 0:
651
+ if (!(j < rateTestJobs)) {
652
+ _context6.next = 2;
653
+ break;
654
+ }
655
+ return _context6.abrupt("return");
656
+ case 2:
657
+ _context6.next = 4;
658
+ return UploadJob(jobId, j);
659
+ case 4:
660
+ case "end":
661
+ return _context6.stop();
662
+ }
663
+ }, _callee5);
664
+ }));
665
+ return function (_x6, _x7) {
666
+ return _ref9.apply(this, arguments);
667
+ };
668
+ }());
669
+ case 47:
670
+ case "end":
671
+ return _context7.stop();
672
+ }
673
+ }, _callee6, this);
674
+ }));
675
+ return function (_x3) {
676
+ return _ref6.apply(this, arguments);
677
+ };
678
+ }();
679
+ exports.CreateFileUploadJob = /*#__PURE__*/function () {
680
+ var _ref11 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(_ref10) {
681
+ var libraryId, objectId, writeToken, ops, _ref10$defaults, defaults, _ref10$encryption, encryption, body, path;
682
+ return _regeneratorRuntime.wrap(function _callee7$(_context8) {
683
+ while (1) switch (_context8.prev = _context8.next) {
684
+ case 0:
685
+ libraryId = _ref10.libraryId, objectId = _ref10.objectId, writeToken = _ref10.writeToken, ops = _ref10.ops, _ref10$defaults = _ref10.defaults, defaults = _ref10$defaults === void 0 ? {} : _ref10$defaults, _ref10$encryption = _ref10.encryption, encryption = _ref10$encryption === void 0 ? "none" : _ref10$encryption;
686
+ ValidateParameters({
687
+ libraryId: libraryId,
688
+ objectId: objectId
689
+ });
690
+ ValidateWriteToken(writeToken);
691
+ this.Log("Creating file upload job: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
692
+ this.Log(ops);
693
+ if (encryption === "cgck") {
694
+ defaults.encryption = {
695
+ scheme: "cgck"
696
+ };
697
+ }
698
+ body = {
699
+ seq: 0,
700
+ seq_complete: true,
701
+ defaults: defaults,
702
+ ops: ops
703
+ };
704
+ path = UrlJoin("q", writeToken, "file_jobs");
705
+ _context8.t0 = this.HttpClient;
706
+ _context8.next = 11;
707
+ return this.authClient.AuthorizationHeader({
708
+ libraryId: libraryId,
709
+ objectId: objectId,
710
+ update: true,
711
+ encryption: encryption
712
+ });
713
+ case 11:
714
+ _context8.t1 = _context8.sent;
715
+ _context8.t2 = path;
716
+ _context8.t3 = body;
717
+ _context8.t4 = {
718
+ headers: _context8.t1,
719
+ method: "POST",
720
+ path: _context8.t2,
721
+ body: _context8.t3,
722
+ allowFailover: false
723
+ };
724
+ return _context8.abrupt("return", _context8.t0.RequestJsonBody.call(_context8.t0, _context8.t4));
725
+ case 16:
726
+ case "end":
727
+ return _context8.stop();
728
+ }
729
+ }, _callee7, this);
730
+ }));
731
+ return function (_x8) {
732
+ return _ref11.apply(this, arguments);
733
+ };
734
+ }();
735
+ exports.UploadStatus = /*#__PURE__*/function () {
736
+ var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(_ref12) {
737
+ var libraryId, objectId, writeToken, uploadId, path;
738
+ return _regeneratorRuntime.wrap(function _callee8$(_context9) {
739
+ while (1) switch (_context9.prev = _context9.next) {
740
+ case 0:
741
+ libraryId = _ref12.libraryId, objectId = _ref12.objectId, writeToken = _ref12.writeToken, uploadId = _ref12.uploadId;
742
+ ValidateParameters({
743
+ libraryId: libraryId,
744
+ objectId: objectId
745
+ });
746
+ ValidateWriteToken(writeToken);
747
+ path = UrlJoin("q", writeToken, "file_jobs", uploadId);
748
+ _context9.t0 = this.utils;
749
+ _context9.t1 = this.HttpClient;
750
+ _context9.next = 8;
751
+ return this.authClient.AuthorizationHeader({
752
+ libraryId: libraryId,
753
+ objectId: objectId,
754
+ update: true
755
+ });
756
+ case 8:
757
+ _context9.t2 = _context9.sent;
758
+ _context9.t3 = path;
759
+ _context9.t4 = {
760
+ headers: _context9.t2,
761
+ method: "GET",
762
+ path: _context9.t3,
763
+ allowFailover: false
764
+ };
765
+ _context9.t5 = _context9.t1.Request.call(_context9.t1, _context9.t4);
766
+ return _context9.abrupt("return", _context9.t0.ResponseToJson.call(_context9.t0, _context9.t5));
767
+ case 13:
768
+ case "end":
769
+ return _context9.stop();
770
+ }
771
+ }, _callee8, this);
772
+ }));
773
+ return function (_x9) {
774
+ return _ref13.apply(this, arguments);
775
+ };
776
+ }();
777
+ exports.UploadJobStatus = /*#__PURE__*/function () {
778
+ var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref14) {
779
+ var libraryId, objectId, writeToken, uploadId, jobId, path, response, newResponse;
780
+ return _regeneratorRuntime.wrap(function _callee9$(_context10) {
781
+ while (1) switch (_context10.prev = _context10.next) {
782
+ case 0:
783
+ libraryId = _ref14.libraryId, objectId = _ref14.objectId, writeToken = _ref14.writeToken, uploadId = _ref14.uploadId, jobId = _ref14.jobId;
784
+ ValidateParameters({
785
+ libraryId: libraryId,
786
+ objectId: objectId
787
+ });
788
+ ValidateWriteToken(writeToken);
789
+ path = UrlJoin("q", writeToken, "file_jobs", uploadId, "uploads", jobId);
790
+ _context10.t0 = this.utils;
791
+ _context10.t1 = this.HttpClient;
792
+ _context10.next = 8;
793
+ return this.authClient.AuthorizationHeader({
794
+ libraryId: libraryId,
795
+ objectId: objectId,
796
+ update: true
797
+ });
798
+ case 8:
799
+ _context10.t2 = _context10.sent;
800
+ _context10.t3 = path;
801
+ _context10.t4 = {
802
+ start: 0,
803
+ limit: 10000
804
+ };
805
+ _context10.t5 = {
806
+ headers: _context10.t2,
807
+ method: "GET",
808
+ path: _context10.t3,
809
+ allowFailover: false,
810
+ queryParams: _context10.t4
811
+ };
812
+ _context10.t6 = _context10.t1.Request.call(_context10.t1, _context10.t5);
813
+ _context10.next = 15;
814
+ return _context10.t0.ResponseToJson.call(_context10.t0, _context10.t6);
815
+ case 15:
816
+ response = _context10.sent;
817
+ case 16:
818
+ if (!(response.next !== response.total && response.next >= 0)) {
819
+ _context10.next = 33;
820
+ break;
821
+ }
822
+ _context10.t7 = this.utils;
823
+ _context10.t8 = this.HttpClient;
824
+ _context10.next = 21;
825
+ return this.authClient.AuthorizationHeader({
826
+ libraryId: libraryId,
827
+ objectId: objectId,
828
+ update: true
829
+ });
830
+ case 21:
831
+ _context10.t9 = _context10.sent;
832
+ _context10.t10 = path;
833
+ _context10.t11 = {
834
+ start: response.next
835
+ };
836
+ _context10.t12 = {
837
+ headers: _context10.t9,
838
+ method: "GET",
839
+ path: _context10.t10,
840
+ allowFailover: false,
841
+ queryParams: _context10.t11
842
+ };
843
+ _context10.t13 = _context10.t8.Request.call(_context10.t8, _context10.t12);
844
+ _context10.next = 28;
845
+ return _context10.t7.ResponseToJson.call(_context10.t7, _context10.t13);
846
+ case 28:
847
+ newResponse = _context10.sent;
848
+ response.files = [].concat(_toConsumableArray(response.files), _toConsumableArray(newResponse.files));
849
+ response.next = newResponse.next;
850
+ _context10.next = 16;
851
+ break;
852
+ case 33:
853
+ return _context10.abrupt("return", response);
854
+ case 34:
855
+ case "end":
856
+ return _context10.stop();
857
+ }
858
+ }, _callee9, this);
859
+ }));
860
+ return function (_x10) {
861
+ return _ref15.apply(this, arguments);
862
+ };
863
+ }();
864
+ exports.UploadFileData = /*#__PURE__*/function () {
865
+ var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(_ref16) {
866
+ var libraryId, objectId, writeToken, encryption, uploadId, jobId, filePath, fileData, jobStatus, fileStatus, path;
867
+ return _regeneratorRuntime.wrap(function _callee10$(_context11) {
868
+ while (1) switch (_context11.prev = _context11.next) {
869
+ case 0:
870
+ libraryId = _ref16.libraryId, objectId = _ref16.objectId, writeToken = _ref16.writeToken, encryption = _ref16.encryption, uploadId = _ref16.uploadId, jobId = _ref16.jobId, filePath = _ref16.filePath, fileData = _ref16.fileData;
871
+ ValidateParameters({
872
+ libraryId: libraryId,
873
+ objectId: objectId
874
+ });
875
+ ValidateWriteToken(writeToken);
876
+ _context11.next = 5;
877
+ return this.UploadJobStatus({
878
+ libraryId: libraryId,
879
+ objectId: objectId,
880
+ writeToken: writeToken,
881
+ uploadId: uploadId,
882
+ jobId: jobId
883
+ });
884
+ case 5:
885
+ jobStatus = _context11.sent;
886
+ // Find the status of this file
887
+ fileStatus = jobStatus.files.find(function (item) {
888
+ return item.path === filePath;
889
+ });
890
+ if (encryption && encryption !== "none") {
891
+ fileStatus = fileStatus.encrypted;
892
+ }
893
+ if (!(fileStatus.rem === 0)) {
894
+ _context11.next = 12;
895
+ break;
896
+ }
897
+ return _context11.abrupt("return");
898
+ case 12:
899
+ if (fileStatus.skip) {
900
+ fileData = fileData.slice(fileStatus.skip);
901
+ }
902
+ case 13:
903
+ path = UrlJoin("q", writeToken, "file_jobs", uploadId, jobId);
904
+ _context11.t0 = this.utils;
905
+ _context11.t1 = this.HttpClient;
906
+ _context11.t2 = path;
907
+ _context11.t3 = fileData;
908
+ _context11.t4 = _objectSpread;
909
+ _context11.t5 = {
910
+ "Content-type": "application/octet-stream"
911
+ };
912
+ _context11.next = 22;
913
+ return this.authClient.AuthorizationHeader({
914
+ libraryId: libraryId,
915
+ objectId: objectId,
916
+ update: true
917
+ });
918
+ case 22:
919
+ _context11.t6 = _context11.sent;
920
+ _context11.t7 = (0, _context11.t4)(_context11.t5, _context11.t6);
921
+ _context11.t8 = {
922
+ method: "POST",
923
+ path: _context11.t2,
924
+ body: _context11.t3,
925
+ bodyType: "BINARY",
926
+ headers: _context11.t7,
927
+ allowFailover: false,
928
+ allowRetry: false
929
+ };
930
+ _context11.t9 = _context11.t1.Request.call(_context11.t1, _context11.t8);
931
+ _context11.next = 28;
932
+ return _context11.t0.ResponseToJson.call(_context11.t0, _context11.t9);
933
+ case 28:
934
+ return _context11.abrupt("return", _context11.sent);
935
+ case 29:
936
+ case "end":
937
+ return _context11.stop();
938
+ }
939
+ }, _callee10, this);
940
+ }));
941
+ return function (_x11) {
942
+ return _ref17.apply(this, arguments);
943
+ };
944
+ }();
945
+ exports.FinalizeUploadJob = /*#__PURE__*/function () {
946
+ var _ref19 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(_ref18) {
947
+ var libraryId, objectId, writeToken, path;
948
+ return _regeneratorRuntime.wrap(function _callee11$(_context12) {
949
+ while (1) switch (_context12.prev = _context12.next) {
950
+ case 0:
951
+ libraryId = _ref18.libraryId, objectId = _ref18.objectId, writeToken = _ref18.writeToken;
952
+ ValidateParameters({
953
+ libraryId: libraryId,
954
+ objectId: objectId
955
+ });
956
+ ValidateWriteToken(writeToken);
957
+ this.Log("Finalizing upload job: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
958
+ path = UrlJoin("q", writeToken, "files");
959
+ _context12.t0 = this.HttpClient;
960
+ _context12.t1 = path;
961
+ _context12.next = 9;
962
+ return this.authClient.AuthorizationHeader({
963
+ libraryId: libraryId,
964
+ objectId: objectId,
965
+ update: true
966
+ });
967
+ case 9:
968
+ _context12.t2 = _context12.sent;
969
+ _context12.t3 = {
970
+ method: "POST",
971
+ path: _context12.t1,
972
+ bodyType: "BINARY",
973
+ headers: _context12.t2,
974
+ allowFailover: false
975
+ };
976
+ _context12.next = 13;
977
+ return _context12.t0.Request.call(_context12.t0, _context12.t3);
978
+ case 13:
979
+ case "end":
980
+ return _context12.stop();
981
+ }
982
+ }, _callee11, this);
983
+ }));
984
+ return function (_x12) {
985
+ return _ref19.apply(this, arguments);
986
+ };
987
+ }();
988
+
989
+ /**
990
+ * Create the specified directories on the specified object
991
+ *
992
+ * @memberof module:ElvClient/Files+Parts
993
+ * @methodGroup Files
994
+ * @namedParams
995
+ * @param {string} libraryId - ID of the library
996
+ * @param {string} objectId - ID of the object
997
+ * @param {string} writeToken - Write token of the draft
998
+ * @param {Array<string>} filePaths - List of file paths to create
999
+ */
1000
+ exports.CreateFileDirectories = /*#__PURE__*/function () {
1001
+ var _ref21 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(_ref20) {
1002
+ var libraryId, objectId, writeToken, filePaths, ops;
1003
+ return _regeneratorRuntime.wrap(function _callee12$(_context13) {
1004
+ while (1) switch (_context13.prev = _context13.next) {
1005
+ case 0:
1006
+ libraryId = _ref20.libraryId, objectId = _ref20.objectId, writeToken = _ref20.writeToken, filePaths = _ref20.filePaths;
1007
+ ValidateParameters({
1008
+ libraryId: libraryId,
1009
+ objectId: objectId
1010
+ });
1011
+ ValidateWriteToken(writeToken);
1012
+ this.Log("Creating Directories: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
1013
+ this.Log(filePaths);
1014
+ ops = filePaths.map(function (path) {
1015
+ return {
1016
+ op: "add",
1017
+ type: "directory",
1018
+ path: path
1019
+ };
1020
+ });
1021
+ _context13.next = 8;
1022
+ return this.CreateFileUploadJob({
1023
+ libraryId: libraryId,
1024
+ objectId: objectId,
1025
+ writeToken: writeToken,
1026
+ ops: ops
1027
+ });
1028
+ case 8:
1029
+ case "end":
1030
+ return _context13.stop();
1031
+ }
1032
+ }, _callee12, this);
1033
+ }));
1034
+ return function (_x13) {
1035
+ return _ref21.apply(this, arguments);
1036
+ };
1037
+ }();
1038
+
1039
+ /**
1040
+ * Move or rename the specified list of files/directories
1041
+ *
1042
+ * @memberof module:ElvClient/Files+Parts
1043
+ * @methodGroup Files
1044
+ * @namedParams
1045
+ * @param {string} libraryId - ID of the library
1046
+ * @param {string} objectId - ID of the object
1047
+ * @param {string} writeToken - Write token of the draft
1048
+ * @param {Array<string>} filePaths - List of file paths to move. Format: ```[ { "path": "original/path", to: "new/path" } ]```
1049
+ */
1050
+ exports.MoveFiles = /*#__PURE__*/function () {
1051
+ var _ref23 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(_ref22) {
1052
+ var libraryId, objectId, writeToken, filePaths, ops;
1053
+ return _regeneratorRuntime.wrap(function _callee13$(_context14) {
1054
+ while (1) switch (_context14.prev = _context14.next) {
1055
+ case 0:
1056
+ libraryId = _ref22.libraryId, objectId = _ref22.objectId, writeToken = _ref22.writeToken, filePaths = _ref22.filePaths;
1057
+ ValidateParameters({
1058
+ libraryId: libraryId,
1059
+ objectId: objectId
1060
+ });
1061
+ ValidateWriteToken(writeToken);
1062
+ this.Log("Moving Files: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
1063
+ this.Log(filePaths);
1064
+ ops = filePaths.map(function (_ref24) {
1065
+ var path = _ref24.path,
1066
+ to = _ref24.to;
1067
+ return {
1068
+ op: "move",
1069
+ copy_move_source_path: path,
1070
+ path: to
1071
+ };
1072
+ });
1073
+ _context14.next = 8;
1074
+ return this.CreateFileUploadJob({
1075
+ libraryId: libraryId,
1076
+ objectId: objectId,
1077
+ writeToken: writeToken,
1078
+ ops: ops
1079
+ });
1080
+ case 8:
1081
+ case "end":
1082
+ return _context14.stop();
1083
+ }
1084
+ }, _callee13, this);
1085
+ }));
1086
+ return function (_x14) {
1087
+ return _ref23.apply(this, arguments);
1088
+ };
1089
+ }();
1090
+
1091
+ /**
1092
+ * Delete the specified list of files/directories
1093
+ *
1094
+ * @memberof module:ElvClient/Files+Parts
1095
+ * @methodGroup Files
1096
+ * @namedParams
1097
+ * @param {string} libraryId - ID of the library
1098
+ * @param {string} objectId - ID of the object
1099
+ * @param {string} writeToken - Write token of the draft
1100
+ * @param {Array<string>} filePaths - List of file paths to delete
1101
+ */
1102
+ exports.DeleteFiles = /*#__PURE__*/function () {
1103
+ var _ref26 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(_ref25) {
1104
+ var libraryId, objectId, writeToken, filePaths, ops;
1105
+ return _regeneratorRuntime.wrap(function _callee14$(_context15) {
1106
+ while (1) switch (_context15.prev = _context15.next) {
1107
+ case 0:
1108
+ libraryId = _ref25.libraryId, objectId = _ref25.objectId, writeToken = _ref25.writeToken, filePaths = _ref25.filePaths;
1109
+ ValidateParameters({
1110
+ libraryId: libraryId,
1111
+ objectId: objectId
1112
+ });
1113
+ ValidateWriteToken(writeToken);
1114
+ this.Log("Deleting Files: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
1115
+ this.Log(filePaths);
1116
+ ops = filePaths.map(function (path) {
1117
+ return {
1118
+ op: "del",
1119
+ path: path
1120
+ };
1121
+ });
1122
+ _context15.next = 8;
1123
+ return this.CreateFileUploadJob({
1124
+ libraryId: libraryId,
1125
+ objectId: objectId,
1126
+ writeToken: writeToken,
1127
+ ops: ops
1128
+ });
1129
+ case 8:
1130
+ case "end":
1131
+ return _context15.stop();
1132
+ }
1133
+ }, _callee14, this);
1134
+ }));
1135
+ return function (_x15) {
1136
+ return _ref26.apply(this, arguments);
1137
+ };
1138
+ }();
1139
+
1140
+ /**
1141
+ * Download a file from a content object
1142
+ *
1143
+ * @memberof module:ElvClient/Files+Parts
1144
+ * @methodGroup Files
1145
+ * @namedParams
1146
+ * @param {string=} libraryId - ID of the library
1147
+ * @param {string=} objectId - ID of the object
1148
+ * @param {string=} versionHash - Hash of the object version - if not specified, latest version will be used
1149
+ * @param {string=} writeToken - Write token for the draft from which to download the file
1150
+ * @param {string} filePath - Path to the file to download
1151
+ * @param {string=} format="arrayBuffer" - Format in which to return the data ("blob" | "arraybuffer" | "buffer")
1152
+ * @param {boolean=} chunked=false - If specified, file will be downloaded and decrypted in chunks. The
1153
+ * specified callback will be invoked on completion of each chunk. This is recommended for large files.
1154
+ * @param {number=} chunkSize=1000000 - Size of file chunks to request for download
1155
+ * - NOTE: If the file is encrypted, the size of the chunks returned via the callback function will not be affected by this value
1156
+ * @param {boolean=} clientSideDecryption=false - If specified, decryption of the file (if necessary) will be done by the client
1157
+ * instead of on the fabric node
1158
+ * @param {function=} callback - If specified, will be periodically called with current download status - Required if `chunked` is true
1159
+ * - Signature: ({bytesFinished, bytesTotal}) => {}
1160
+ * - Signature (chunked): ({bytesFinished, bytesTotal, chunk}) => {}
1161
+ *
1162
+ * @returns {Promise<ArrayBuffer> | undefined} - No return if chunked is specified, file data in the requested format otherwise
1163
+ */
1164
+ exports.DownloadFile = /*#__PURE__*/function () {
1165
+ var _ref28 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(_ref27) {
1166
+ var libraryId,
1167
+ objectId,
1168
+ versionHash,
1169
+ writeToken,
1170
+ filePath,
1171
+ _ref27$format,
1172
+ format,
1173
+ _ref27$chunked,
1174
+ chunked,
1175
+ chunkSize,
1176
+ _ref27$clientSideDecr,
1177
+ clientSideDecryption,
1178
+ callback,
1179
+ fileInfo,
1180
+ encrypted,
1181
+ encryption,
1182
+ path,
1183
+ headers,
1184
+ ownerCapKey,
1185
+ ownerCap,
1186
+ bytesTotal,
1187
+ _args16 = arguments;
1188
+ return _regeneratorRuntime.wrap(function _callee15$(_context16) {
1189
+ while (1) switch (_context16.prev = _context16.next) {
1190
+ case 0:
1191
+ libraryId = _ref27.libraryId, objectId = _ref27.objectId, versionHash = _ref27.versionHash, writeToken = _ref27.writeToken, filePath = _ref27.filePath, _ref27$format = _ref27.format, format = _ref27$format === void 0 ? "arrayBuffer" : _ref27$format, _ref27$chunked = _ref27.chunked, chunked = _ref27$chunked === void 0 ? false : _ref27$chunked, chunkSize = _ref27.chunkSize, _ref27$clientSideDecr = _ref27.clientSideDecryption, clientSideDecryption = _ref27$clientSideDecr === void 0 ? false : _ref27$clientSideDecr, callback = _ref27.callback;
1192
+ ValidateParameters({
1193
+ libraryId: libraryId,
1194
+ objectId: objectId,
1195
+ versionHash: versionHash
1196
+ });
1197
+ ValidatePresence("filePath", filePath);
1198
+ if (versionHash) {
1199
+ objectId = this.utils.DecodeVersionHash(versionHash).objectId;
1200
+ }
1201
+ _context16.next = 6;
1202
+ return this.ContentObjectMetadata({
1203
+ libraryId: libraryId,
1204
+ objectId: objectId,
1205
+ versionHash: versionHash,
1206
+ writeToken: writeToken,
1207
+ metadataSubtree: UrlJoin("files", filePath)
1208
+ });
1209
+ case 6:
1210
+ fileInfo = _context16.sent;
1211
+ encrypted = fileInfo && fileInfo["."].encryption && fileInfo["."].encryption.scheme === "cgck";
1212
+ encryption = encrypted ? "cgck" : undefined;
1213
+ path = encrypted && !clientSideDecryption ? UrlJoin("q", writeToken || versionHash || objectId, "rep", "files_download", filePath) : UrlJoin("q", writeToken || versionHash || objectId, "files", filePath);
1214
+ _context16.next = 12;
1215
+ return this.authClient.AuthorizationHeader({
1216
+ libraryId: libraryId,
1217
+ objectId: objectId,
1218
+ versionHash: versionHash,
1219
+ encryption: encryption,
1220
+ makeAccessRequest: encryption === "cgck"
1221
+ });
1222
+ case 12:
1223
+ headers = _context16.sent;
1224
+ headers.Accept = "*/*";
1225
+
1226
+ // If not owner, indicate re-encryption
1227
+ ownerCapKey = "eluv.caps.iusr".concat(this.utils.AddressToHash(this.signer.address));
1228
+ _context16.next = 17;
1229
+ return this.ContentObjectMetadata({
1230
+ libraryId: libraryId,
1231
+ objectId: objectId,
1232
+ versionHash: versionHash,
1233
+ metadataSubtree: ownerCapKey
1234
+ });
1235
+ case 17:
1236
+ ownerCap = _context16.sent;
1237
+ _context16.t1 = encrypted;
1238
+ if (!_context16.t1) {
1239
+ _context16.next = 26;
1240
+ break;
1241
+ }
1242
+ _context16.t2 = this.utils;
1243
+ _context16.t3 = this.signer.address;
1244
+ _context16.next = 24;
1245
+ return this.ContentObjectOwner({
1246
+ objectId: objectId
1247
+ });
1248
+ case 24:
1249
+ _context16.t4 = _context16.sent;
1250
+ _context16.t1 = !_context16.t2.EqualAddress.call(_context16.t2, _context16.t3, _context16.t4);
1251
+ case 26:
1252
+ _context16.t0 = _context16.t1;
1253
+ if (!_context16.t0) {
1254
+ _context16.next = 29;
1255
+ break;
1256
+ }
1257
+ _context16.t0 = !ownerCap;
1258
+ case 29:
1259
+ if (!_context16.t0) {
1260
+ _context16.next = 31;
1261
+ break;
1262
+ }
1263
+ headers["X-Content-Fabric-Decryption-Mode"] = "reencrypt";
1264
+ case 31:
1265
+ // If using server side decryption, specify in header
1266
+ if (encrypted && !clientSideDecryption) {
1267
+ headers["X-Content-Fabric-Decryption-Mode"] = "decrypt";
1268
+ // rep/files_download endpoint doesn't currently support Range header
1269
+ chunkSize = Number.MAX_SAFE_INTEGER;
1270
+ }
1271
+ bytesTotal = fileInfo["."].size;
1272
+ if (!(encrypted && clientSideDecryption)) {
1273
+ _context16.next = 51;
1274
+ break;
1275
+ }
1276
+ _context16.t5 = this;
1277
+ _context16.next = 37;
1278
+ return this.EncryptionConk({
1279
+ libraryId: libraryId,
1280
+ objectId: objectId,
1281
+ versionHash: versionHash,
1282
+ download: true
1283
+ });
1284
+ case 37:
1285
+ _context16.t6 = _context16.sent;
1286
+ _context16.t7 = path;
1287
+ _context16.t8 = bytesTotal;
1288
+ _context16.t9 = headers;
1289
+ _context16.t10 = callback;
1290
+ _context16.t11 = format;
1291
+ _context16.t12 = clientSideDecryption;
1292
+ _context16.t13 = chunked;
1293
+ _context16.t14 = {
1294
+ conk: _context16.t6,
1295
+ downloadPath: _context16.t7,
1296
+ bytesTotal: _context16.t8,
1297
+ headers: _context16.t9,
1298
+ callback: _context16.t10,
1299
+ format: _context16.t11,
1300
+ clientSideDecryption: _context16.t12,
1301
+ chunked: _context16.t13
1302
+ };
1303
+ _context16.next = 48;
1304
+ return _context16.t5.DownloadEncrypted.call(_context16.t5, _context16.t14);
1305
+ case 48:
1306
+ return _context16.abrupt("return", _context16.sent);
1307
+ case 51:
1308
+ if (!chunkSize) {
1309
+ chunkSize = 10000000;
1310
+ }
1311
+ _context16.prev = 52;
1312
+ _context16.next = 55;
1313
+ return this.Download({
1314
+ downloadPath: path,
1315
+ bytesTotal: bytesTotal,
1316
+ headers: headers,
1317
+ callback: callback,
1318
+ format: format,
1319
+ chunked: chunked,
1320
+ chunkSize: chunkSize
1321
+ });
1322
+ case 55:
1323
+ return _context16.abrupt("return", _context16.sent);
1324
+ case 58:
1325
+ _context16.prev = 58;
1326
+ _context16.t15 = _context16["catch"](52);
1327
+ if (!(encrypted && !clientSideDecryption)) {
1328
+ _context16.next = 62;
1329
+ break;
1330
+ }
1331
+ return _context16.abrupt("return", this.DownloadFile(_objectSpread(_objectSpread({}, _args16[0]), {}, {
1332
+ clientSideDecryption: true
1333
+ })));
1334
+ case 62:
1335
+ throw _context16.t15;
1336
+ case 63:
1337
+ case "end":
1338
+ return _context16.stop();
1339
+ }
1340
+ }, _callee15, this, [[52, 58]]);
1341
+ }));
1342
+ return function (_x16) {
1343
+ return _ref28.apply(this, arguments);
1344
+ };
1345
+ }();
1346
+
1347
+ /* Parts */
1348
+
1349
+ /**
1350
+ * List content object parts
1351
+ *
1352
+ * @memberof module:ElvClient/Files+Parts
1353
+ * @methodGroup Parts
1354
+ * @namedParams
1355
+ * @param {string=} libraryId - ID of the library
1356
+ * @param {string=} objectId - ID of the object
1357
+ * @param {string=} versionHash - Hash of the object version - if not specified, latest version will be used
1358
+ *
1359
+ * @returns {Promise<Object>} - Response containing list of parts of the object
1360
+ */
1361
+ exports.ContentParts = /*#__PURE__*/function () {
1362
+ var _ref30 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(_ref29) {
1363
+ var libraryId, objectId, versionHash, path, response;
1364
+ return _regeneratorRuntime.wrap(function _callee16$(_context17) {
1365
+ while (1) switch (_context17.prev = _context17.next) {
1366
+ case 0:
1367
+ libraryId = _ref29.libraryId, objectId = _ref29.objectId, versionHash = _ref29.versionHash;
1368
+ ValidateParameters({
1369
+ libraryId: libraryId,
1370
+ objectId: objectId,
1371
+ versionHash: versionHash
1372
+ });
1373
+ this.Log("Retrieving parts: ".concat(libraryId, " ").concat(objectId || versionHash));
1374
+ if (versionHash) {
1375
+ objectId = this.utils.DecodeVersionHash(versionHash).objectId;
1376
+ }
1377
+ path = UrlJoin("q", versionHash || objectId, "parts");
1378
+ _context17.t0 = this.HttpClient;
1379
+ _context17.next = 8;
1380
+ return this.authClient.AuthorizationHeader({
1381
+ libraryId: libraryId,
1382
+ objectId: objectId,
1383
+ versionHash: versionHash
1384
+ });
1385
+ case 8:
1386
+ _context17.t1 = _context17.sent;
1387
+ _context17.t2 = path;
1388
+ _context17.t3 = {
1389
+ headers: _context17.t1,
1390
+ method: "GET",
1391
+ path: _context17.t2
1392
+ };
1393
+ _context17.next = 13;
1394
+ return _context17.t0.RequestJsonBody.call(_context17.t0, _context17.t3);
1395
+ case 13:
1396
+ response = _context17.sent;
1397
+ return _context17.abrupt("return", response.parts);
1398
+ case 15:
1399
+ case "end":
1400
+ return _context17.stop();
1401
+ }
1402
+ }, _callee16, this);
1403
+ }));
1404
+ return function (_x17) {
1405
+ return _ref30.apply(this, arguments);
1406
+ };
1407
+ }();
1408
+
1409
+ /**
1410
+ * Get information on a specific part
1411
+ *
1412
+ * @memberof module:ElvClient/Files+Parts
1413
+ * @methodGroup Parts
1414
+ * @namedParams
1415
+ * @param {string=} libraryId - ID of the library
1416
+ * @param {string=} objectId - ID of the object
1417
+ * @param {string=} versionHash - Hash of the object version - if not specified, latest version will be used
1418
+ * @param {string} partHash - Hash of the part to retrieve
1419
+ *
1420
+ * @returns {Promise<Object>} - Response containing information about the specified part
1421
+ */
1422
+ exports.ContentPart = /*#__PURE__*/function () {
1423
+ var _ref32 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(_ref31) {
1424
+ var libraryId, objectId, versionHash, partHash, path;
1425
+ return _regeneratorRuntime.wrap(function _callee17$(_context18) {
1426
+ while (1) switch (_context18.prev = _context18.next) {
1427
+ case 0:
1428
+ libraryId = _ref31.libraryId, objectId = _ref31.objectId, versionHash = _ref31.versionHash, partHash = _ref31.partHash;
1429
+ ValidateParameters({
1430
+ libraryId: libraryId,
1431
+ objectId: objectId,
1432
+ versionHash: versionHash
1433
+ });
1434
+ ValidatePartHash(partHash);
1435
+ this.Log("Retrieving part: ".concat(libraryId, " ").concat(objectId || versionHash, " ").concat(partHash));
1436
+ if (versionHash) {
1437
+ objectId = this.utils.DecodeVersionHash(versionHash).objectId;
1438
+ }
1439
+ path = UrlJoin("q", versionHash || objectId, "parts", partHash);
1440
+ _context18.t0 = this.HttpClient;
1441
+ _context18.next = 9;
1442
+ return this.authClient.AuthorizationHeader({
1443
+ libraryId: libraryId,
1444
+ objectId: objectId,
1445
+ versionHash: versionHash
1446
+ });
1447
+ case 9:
1448
+ _context18.t1 = _context18.sent;
1449
+ _context18.t2 = path;
1450
+ _context18.t3 = {
1451
+ headers: _context18.t1,
1452
+ method: "GET",
1453
+ path: _context18.t2
1454
+ };
1455
+ _context18.next = 14;
1456
+ return _context18.t0.RequestJsonBody.call(_context18.t0, _context18.t3);
1457
+ case 14:
1458
+ return _context18.abrupt("return", _context18.sent);
1459
+ case 15:
1460
+ case "end":
1461
+ return _context18.stop();
1462
+ }
1463
+ }, _callee17, this);
1464
+ }));
1465
+ return function (_x18) {
1466
+ return _ref32.apply(this, arguments);
1467
+ };
1468
+ }();
1469
+
1470
+ /**
1471
+ * Download a part from a content object. The fromByte and range parameters can be used to specify a
1472
+ * specific section of the part to download.
1473
+ *
1474
+ * @memberof module:ElvClient/Files+Parts
1475
+ * @methodGroup Parts
1476
+ * @namedParams
1477
+ * @param {string=} libraryId - ID of the library
1478
+ * @param {string=} objectId - ID of the object
1479
+ * @param {string=} versionHash - Hash of the object version - if not specified, latest version will be used
1480
+ * @param {string=} writeToken - Write token for the draft from which to download the part
1481
+ * @param {string} partHash - Hash of the part to download
1482
+ * @param {string=} format="arrayBuffer" - Format in which to return the data ("blob" | "arraybuffer" | "buffer)
1483
+ * @param {boolean=} chunked=false - If specified, part will be downloaded and decrypted in chunks. The
1484
+ * specified callback will be invoked on completion of each chunk. This is recommended for large files,
1485
+ * especially if they are encrypted.
1486
+ * @param {number=} chunkSize=1000000 - Size of file chunks to request for download
1487
+ * - NOTE: If the file is encrypted, the size of the chunks returned via the callback function will not be affected by this value
1488
+ * @param {function=} callback - If specified, will be periodically called with current download status - Required if `chunked` is true
1489
+ * - Signature: ({bytesFinished, bytesTotal}) => {}
1490
+ * - Signature (chunked): ({bytesFinished, bytesTotal, chunk}) => {}
1491
+ *
1492
+ * @returns {Promise<ArrayBuffer> | undefined} - No return if chunked is specified, part data in the requested format otherwise
1493
+ */
1494
+ exports.DownloadPart = /*#__PURE__*/function () {
1495
+ var _ref34 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(_ref33) {
1496
+ var libraryId, objectId, versionHash, writeToken, partHash, _ref33$format, format, _ref33$chunked, chunked, _ref33$chunkSize, chunkSize, callback, encrypted, encryption, path, headers, bytesTotal;
1497
+ return _regeneratorRuntime.wrap(function _callee18$(_context19) {
1498
+ while (1) switch (_context19.prev = _context19.next) {
1499
+ case 0:
1500
+ libraryId = _ref33.libraryId, objectId = _ref33.objectId, versionHash = _ref33.versionHash, writeToken = _ref33.writeToken, partHash = _ref33.partHash, _ref33$format = _ref33.format, format = _ref33$format === void 0 ? "arrayBuffer" : _ref33$format, _ref33$chunked = _ref33.chunked, chunked = _ref33$chunked === void 0 ? false : _ref33$chunked, _ref33$chunkSize = _ref33.chunkSize, chunkSize = _ref33$chunkSize === void 0 ? 10000000 : _ref33$chunkSize, callback = _ref33.callback;
1501
+ ValidateParameters({
1502
+ libraryId: libraryId,
1503
+ objectId: objectId,
1504
+ versionHash: versionHash
1505
+ });
1506
+ ValidatePartHash(partHash);
1507
+ if (versionHash) {
1508
+ objectId = this.utils.DecodeVersionHash(versionHash).objectId;
1509
+ }
1510
+ encrypted = partHash.startsWith("hqpe");
1511
+ encryption = encrypted ? "cgck" : undefined;
1512
+ path = UrlJoin("q", writeToken || versionHash || objectId, "data", partHash);
1513
+ _context19.next = 9;
1514
+ return this.authClient.AuthorizationHeader({
1515
+ libraryId: libraryId,
1516
+ objectId: objectId,
1517
+ versionHash: versionHash,
1518
+ encryption: encryption,
1519
+ makeAccessRequest: true
1520
+ });
1521
+ case 9:
1522
+ headers = _context19.sent;
1523
+ _context19.next = 12;
1524
+ return this.ContentPart({
1525
+ libraryId: libraryId,
1526
+ objectId: objectId,
1527
+ versionHash: versionHash,
1528
+ partHash: partHash
1529
+ });
1530
+ case 12:
1531
+ bytesTotal = _context19.sent.part.size;
1532
+ if (!encrypted) {
1533
+ _context19.next = 37;
1534
+ break;
1535
+ }
1536
+ _context19.t0 = this.utils;
1537
+ _context19.t1 = this.signer.address;
1538
+ _context19.next = 18;
1539
+ return this.ContentObjectOwner({
1540
+ objectId: objectId
1541
+ });
1542
+ case 18:
1543
+ _context19.t2 = _context19.sent;
1544
+ if (_context19.t0.EqualAddress.call(_context19.t0, _context19.t1, _context19.t2)) {
1545
+ _context19.next = 21;
1546
+ break;
1547
+ }
1548
+ headers["X-Content-Fabric-Decryption-Mode"] = "reencrypt";
1549
+ case 21:
1550
+ _context19.t3 = this;
1551
+ _context19.next = 24;
1552
+ return this.EncryptionConk({
1553
+ libraryId: libraryId,
1554
+ objectId: objectId,
1555
+ download: true
1556
+ });
1557
+ case 24:
1558
+ _context19.t4 = _context19.sent;
1559
+ _context19.t5 = path;
1560
+ _context19.t6 = bytesTotal;
1561
+ _context19.t7 = headers;
1562
+ _context19.t8 = callback;
1563
+ _context19.t9 = format;
1564
+ _context19.t10 = chunked;
1565
+ _context19.t11 = {
1566
+ conk: _context19.t4,
1567
+ downloadPath: _context19.t5,
1568
+ bytesTotal: _context19.t6,
1569
+ headers: _context19.t7,
1570
+ callback: _context19.t8,
1571
+ format: _context19.t9,
1572
+ chunked: _context19.t10
1573
+ };
1574
+ _context19.next = 34;
1575
+ return _context19.t3.DownloadEncrypted.call(_context19.t3, _context19.t11);
1576
+ case 34:
1577
+ return _context19.abrupt("return", _context19.sent);
1578
+ case 37:
1579
+ _context19.next = 39;
1580
+ return this.Download({
1581
+ downloadPath: path,
1582
+ bytesTotal: bytesTotal,
1583
+ headers: headers,
1584
+ callback: callback,
1585
+ format: format,
1586
+ chunked: chunked,
1587
+ chunkSize: chunkSize
1588
+ });
1589
+ case 39:
1590
+ return _context19.abrupt("return", _context19.sent);
1591
+ case 40:
1592
+ case "end":
1593
+ return _context19.stop();
1594
+ }
1595
+ }, _callee18, this);
1596
+ }));
1597
+ return function (_x19) {
1598
+ return _ref34.apply(this, arguments);
1599
+ };
1600
+ }();
1601
+ exports.Download = /*#__PURE__*/function () {
1602
+ var _ref36 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(_ref35) {
1603
+ var downloadPath, headers, bytesTotal, _ref35$chunked, chunked, _ref35$chunkSize, chunkSize, callback, _ref35$format, format, outputChunks, bytesFinished, totalChunks, i, response;
1604
+ return _regeneratorRuntime.wrap(function _callee19$(_context20) {
1605
+ while (1) switch (_context20.prev = _context20.next) {
1606
+ case 0:
1607
+ downloadPath = _ref35.downloadPath, headers = _ref35.headers, bytesTotal = _ref35.bytesTotal, _ref35$chunked = _ref35.chunked, chunked = _ref35$chunked === void 0 ? false : _ref35$chunked, _ref35$chunkSize = _ref35.chunkSize, chunkSize = _ref35$chunkSize === void 0 ? 2000000 : _ref35$chunkSize, callback = _ref35.callback, _ref35$format = _ref35.format, format = _ref35$format === void 0 ? "arrayBuffer" : _ref35$format;
1608
+ if (!(chunked && !callback)) {
1609
+ _context20.next = 3;
1610
+ break;
1611
+ }
1612
+ throw Error("No callback specified for chunked download");
1613
+ case 3:
1614
+ if (!chunked) {
1615
+ outputChunks = [];
1616
+ }
1617
+
1618
+ // Download file in chunks
1619
+ bytesFinished = 0;
1620
+ totalChunks = Math.ceil(bytesTotal / chunkSize);
1621
+ i = 0;
1622
+ case 7:
1623
+ if (!(i < totalChunks)) {
1624
+ _context20.next = 35;
1625
+ break;
1626
+ }
1627
+ headers["Range"] = "bytes=".concat(bytesFinished, "-").concat(bytesFinished + chunkSize - 1);
1628
+ _context20.next = 11;
1629
+ return this.HttpClient.Request({
1630
+ path: downloadPath,
1631
+ headers: headers,
1632
+ method: "GET"
1633
+ });
1634
+ case 11:
1635
+ response = _context20.sent;
1636
+ bytesFinished = Math.min(bytesFinished + chunkSize, bytesTotal);
1637
+ if (!chunked) {
1638
+ _context20.next = 24;
1639
+ break;
1640
+ }
1641
+ _context20.t0 = callback;
1642
+ _context20.t1 = bytesFinished;
1643
+ _context20.t2 = bytesTotal;
1644
+ _context20.next = 19;
1645
+ return this.utils.ResponseToFormat(format, response);
1646
+ case 19:
1647
+ _context20.t3 = _context20.sent;
1648
+ _context20.t4 = {
1649
+ bytesFinished: _context20.t1,
1650
+ bytesTotal: _context20.t2,
1651
+ chunk: _context20.t3
1652
+ };
1653
+ (0, _context20.t0)(_context20.t4);
1654
+ _context20.next = 32;
1655
+ break;
1656
+ case 24:
1657
+ _context20.t5 = outputChunks;
1658
+ _context20.t6 = Buffer;
1659
+ _context20.next = 28;
1660
+ return response.arrayBuffer();
1661
+ case 28:
1662
+ _context20.t7 = _context20.sent;
1663
+ _context20.t8 = _context20.t6.from.call(_context20.t6, _context20.t7);
1664
+ _context20.t5.push.call(_context20.t5, _context20.t8);
1665
+ if (callback) {
1666
+ callback({
1667
+ bytesFinished: bytesFinished,
1668
+ bytesTotal: bytesTotal
1669
+ });
1670
+ }
1671
+ case 32:
1672
+ i++;
1673
+ _context20.next = 7;
1674
+ break;
1675
+ case 35:
1676
+ if (chunked) {
1677
+ _context20.next = 39;
1678
+ break;
1679
+ }
1680
+ _context20.next = 38;
1681
+ return this.utils.ResponseToFormat(format, new Response(Buffer.concat(outputChunks)));
1682
+ case 38:
1683
+ return _context20.abrupt("return", _context20.sent);
1684
+ case 39:
1685
+ case "end":
1686
+ return _context20.stop();
1687
+ }
1688
+ }, _callee19, this);
1689
+ }));
1690
+ return function (_x20) {
1691
+ return _ref36.apply(this, arguments);
1692
+ };
1693
+ }();
1694
+ exports.DownloadEncrypted = /*#__PURE__*/function () {
1695
+ var _ref38 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21(_ref37) {
1696
+ var _this2 = this;
1697
+ var conk, downloadPath, bytesTotal, headers, callback, _ref37$format, format, _ref37$chunked, chunked, isReencryption, chunkSize, bytesFinished, outputChunks, stream, totalChunks, i, response;
1698
+ return _regeneratorRuntime.wrap(function _callee21$(_context22) {
1699
+ while (1) switch (_context22.prev = _context22.next) {
1700
+ case 0:
1701
+ conk = _ref37.conk, downloadPath = _ref37.downloadPath, bytesTotal = _ref37.bytesTotal, headers = _ref37.headers, callback = _ref37.callback, _ref37$format = _ref37.format, format = _ref37$format === void 0 ? "arrayBuffer" : _ref37$format, _ref37$chunked = _ref37.chunked, chunked = _ref37$chunked === void 0 ? false : _ref37$chunked;
1702
+ if (!(chunked && !callback)) {
1703
+ _context22.next = 3;
1704
+ break;
1705
+ }
1706
+ throw Error("No callback specified for chunked download");
1707
+ case 3:
1708
+ // Must align chunk size with encryption block size
1709
+ isReencryption = conk.public_key.startsWith("ktpk");
1710
+ chunkSize = this.Crypto.EncryptedBlockSize(1000000, isReencryption);
1711
+ bytesFinished = 0;
1712
+ format = format.toLowerCase();
1713
+ outputChunks = []; // Set up decryption stream
1714
+ _context22.next = 10;
1715
+ return this.Crypto.OpenDecryptionStream(conk);
1716
+ case 10:
1717
+ stream = _context22.sent;
1718
+ stream.on("data", /*#__PURE__*/function () {
1719
+ var _ref39 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20(chunk) {
1720
+ var arrayBuffer;
1721
+ return _regeneratorRuntime.wrap(function _callee20$(_context21) {
1722
+ while (1) switch (_context21.prev = _context21.next) {
1723
+ case 0:
1724
+ if (!chunked) {
1725
+ _context21.next = 13;
1726
+ break;
1727
+ }
1728
+ if (!(format !== "buffer")) {
1729
+ _context21.next = 10;
1730
+ break;
1731
+ }
1732
+ arrayBuffer = chunk.buffer.slice(chunk.byteOffset, chunk.byteOffset + chunk.byteLength);
1733
+ if (!(format === "arraybuffer")) {
1734
+ _context21.next = 7;
1735
+ break;
1736
+ }
1737
+ chunk = arrayBuffer;
1738
+ _context21.next = 10;
1739
+ break;
1740
+ case 7:
1741
+ _context21.next = 9;
1742
+ return _this2.utils.ResponseToFormat(format, new Response(arrayBuffer));
1743
+ case 9:
1744
+ chunk = _context21.sent;
1745
+ case 10:
1746
+ callback({
1747
+ bytesFinished: bytesFinished,
1748
+ bytesTotal: bytesTotal,
1749
+ chunk: chunk
1750
+ });
1751
+ _context21.next = 15;
1752
+ break;
1753
+ case 13:
1754
+ if (callback) {
1755
+ callback({
1756
+ bytesFinished: bytesFinished,
1757
+ bytesTotal: bytesTotal
1758
+ });
1759
+ }
1760
+ outputChunks.push(chunk);
1761
+ case 15:
1762
+ case "end":
1763
+ return _context21.stop();
1764
+ }
1765
+ }, _callee20);
1766
+ }));
1767
+ return function (_x22) {
1768
+ return _ref39.apply(this, arguments);
1769
+ };
1770
+ }());
1771
+ totalChunks = Math.ceil(bytesTotal / chunkSize);
1772
+ i = 0;
1773
+ case 14:
1774
+ if (!(i < totalChunks)) {
1775
+ _context22.next = 30;
1776
+ break;
1777
+ }
1778
+ headers["Range"] = "bytes=".concat(bytesFinished, "-").concat(bytesFinished + chunkSize - 1);
1779
+ _context22.next = 18;
1780
+ return this.HttpClient.Request({
1781
+ headers: headers,
1782
+ method: "GET",
1783
+ path: downloadPath
1784
+ });
1785
+ case 18:
1786
+ response = _context22.sent;
1787
+ bytesFinished = Math.min(bytesFinished + chunkSize, bytesTotal);
1788
+ _context22.t0 = stream;
1789
+ _context22.t1 = Uint8Array;
1790
+ _context22.next = 24;
1791
+ return response.arrayBuffer();
1792
+ case 24:
1793
+ _context22.t2 = _context22.sent;
1794
+ _context22.t3 = new _context22.t1(_context22.t2);
1795
+ _context22.t0.write.call(_context22.t0, _context22.t3);
1796
+ case 27:
1797
+ i++;
1798
+ _context22.next = 14;
1799
+ break;
1800
+ case 30:
1801
+ // Wait for decryption to complete
1802
+ stream.end();
1803
+ _context22.next = 33;
1804
+ return new Promise(function (resolve) {
1805
+ return stream.on("finish", function () {
1806
+ resolve();
1807
+ });
1808
+ });
1809
+ case 33:
1810
+ if (chunked) {
1811
+ _context22.next = 37;
1812
+ break;
1813
+ }
1814
+ _context22.next = 36;
1815
+ return this.utils.ResponseToFormat(format, new Response(Buffer.concat(outputChunks)));
1816
+ case 36:
1817
+ return _context22.abrupt("return", _context22.sent);
1818
+ case 37:
1819
+ case "end":
1820
+ return _context22.stop();
1821
+ }
1822
+ }, _callee21, this);
1823
+ }));
1824
+ return function (_x21) {
1825
+ return _ref38.apply(this, arguments);
1826
+ };
1827
+ }();
1828
+
1829
+ /**
1830
+ * Create a part upload draft
1831
+ *
1832
+ * @memberof module:ElvClient/Files+Parts
1833
+ * @methodGroup Parts
1834
+ * @namedParams
1835
+ * @param {string} libraryId - ID of the library
1836
+ * @param {string} objectId - ID of the object
1837
+ * @param {string} writeToken - Write token of the content object draft
1838
+ * @param {string=} encryption=none - Desired encryption scheme. Options: 'none' (default), 'cgck'
1839
+ *
1840
+ * @returns {Promise<string>} - The part write token for the part draft
1841
+ */
1842
+ exports.CreatePart = /*#__PURE__*/function () {
1843
+ var _ref41 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22(_ref40) {
1844
+ var libraryId, objectId, writeToken, encryption, path, openResponse;
1845
+ return _regeneratorRuntime.wrap(function _callee22$(_context23) {
1846
+ while (1) switch (_context23.prev = _context23.next) {
1847
+ case 0:
1848
+ libraryId = _ref40.libraryId, objectId = _ref40.objectId, writeToken = _ref40.writeToken, encryption = _ref40.encryption;
1849
+ ValidateParameters({
1850
+ libraryId: libraryId,
1851
+ objectId: objectId
1852
+ });
1853
+ ValidateWriteToken(writeToken);
1854
+ path = UrlJoin("q", writeToken, "parts");
1855
+ _context23.t0 = this.HttpClient;
1856
+ _context23.next = 7;
1857
+ return this.authClient.AuthorizationHeader({
1858
+ libraryId: libraryId,
1859
+ objectId: objectId,
1860
+ update: true,
1861
+ encryption: encryption
1862
+ });
1863
+ case 7:
1864
+ _context23.t1 = _context23.sent;
1865
+ _context23.t2 = path;
1866
+ _context23.t3 = {
1867
+ headers: _context23.t1,
1868
+ method: "POST",
1869
+ path: _context23.t2,
1870
+ bodyType: "BINARY",
1871
+ body: "",
1872
+ allowFailover: false
1873
+ };
1874
+ _context23.next = 12;
1875
+ return _context23.t0.RequestJsonBody.call(_context23.t0, _context23.t3);
1876
+ case 12:
1877
+ openResponse = _context23.sent;
1878
+ return _context23.abrupt("return", openResponse.part.write_token);
1879
+ case 14:
1880
+ case "end":
1881
+ return _context23.stop();
1882
+ }
1883
+ }, _callee22, this);
1884
+ }));
1885
+ return function (_x23) {
1886
+ return _ref41.apply(this, arguments);
1887
+ };
1888
+ }();
1889
+
1890
+ /**
1891
+ * Upload data to an open part draft
1892
+ *
1893
+ * @memberof module:ElvClient/Files+Parts
1894
+ * @methodGroup Parts
1895
+ * @namedParams
1896
+ * @param {string} libraryId - ID of the library
1897
+ * @param {string} objectId - ID of the object
1898
+ * @param {string} writeToken - Write token of the content object draft
1899
+ * @param {string} partWriteToken - Write token of the part
1900
+ * @param {(ArrayBuffer | Buffer)} chunk - Data to upload
1901
+ * @param {string=} encryption=none - Desired encryption scheme. Options: 'none' (default), 'cgck'
1902
+ *
1903
+ * @returns {Promise<string>} - The part write token for the part draft
1904
+ */
1905
+ exports.UploadPartChunk = /*#__PURE__*/function () {
1906
+ var _ref43 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee23(_ref42) {
1907
+ var libraryId, objectId, writeToken, partWriteToken, chunk, encryption, conk, path;
1908
+ return _regeneratorRuntime.wrap(function _callee23$(_context24) {
1909
+ while (1) switch (_context24.prev = _context24.next) {
1910
+ case 0:
1911
+ libraryId = _ref42.libraryId, objectId = _ref42.objectId, writeToken = _ref42.writeToken, partWriteToken = _ref42.partWriteToken, chunk = _ref42.chunk, encryption = _ref42.encryption;
1912
+ ValidateParameters({
1913
+ libraryId: libraryId,
1914
+ objectId: objectId
1915
+ });
1916
+ ValidateWriteToken(writeToken);
1917
+ if (!(encryption && encryption !== "none")) {
1918
+ _context24.next = 10;
1919
+ break;
1920
+ }
1921
+ _context24.next = 6;
1922
+ return this.EncryptionConk({
1923
+ libraryId: libraryId,
1924
+ objectId: objectId,
1925
+ writeToken: writeToken
1926
+ });
1927
+ case 6:
1928
+ conk = _context24.sent;
1929
+ _context24.next = 9;
1930
+ return this.Crypto.Encrypt(conk, chunk);
1931
+ case 9:
1932
+ chunk = _context24.sent;
1933
+ case 10:
1934
+ path = UrlJoin("q", writeToken, "parts");
1935
+ _context24.t0 = this.utils;
1936
+ _context24.t1 = this.HttpClient;
1937
+ _context24.next = 15;
1938
+ return this.authClient.AuthorizationHeader({
1939
+ libraryId: libraryId,
1940
+ objectId: objectId,
1941
+ update: true,
1942
+ encryption: encryption
1943
+ });
1944
+ case 15:
1945
+ _context24.t2 = _context24.sent;
1946
+ _context24.t3 = UrlJoin(path, partWriteToken);
1947
+ _context24.t4 = chunk;
1948
+ _context24.t5 = {
1949
+ headers: _context24.t2,
1950
+ method: "POST",
1951
+ path: _context24.t3,
1952
+ body: _context24.t4,
1953
+ bodyType: "BINARY",
1954
+ allowFailover: false
1955
+ };
1956
+ _context24.t6 = _context24.t1.Request.call(_context24.t1, _context24.t5);
1957
+ _context24.next = 22;
1958
+ return _context24.t0.ResponseToJson.call(_context24.t0, _context24.t6);
1959
+ case 22:
1960
+ case "end":
1961
+ return _context24.stop();
1962
+ }
1963
+ }, _callee23, this);
1964
+ }));
1965
+ return function (_x24) {
1966
+ return _ref43.apply(this, arguments);
1967
+ };
1968
+ }();
1969
+
1970
+ /**
1971
+ * Finalize an open part draft
1972
+ *
1973
+ * @memberof module:ElvClient/Files+Parts
1974
+ * @methodGroup Parts
1975
+ * @namedParams
1976
+ * @param {string} libraryId - ID of the library
1977
+ * @param {string} objectId - ID of the object
1978
+ * @param {string} writeToken - Write token of the content object draft
1979
+ * @param {string} partWriteToken - Write token of the part
1980
+ * @param {string=} encryption=none - Desired encryption scheme. Options: 'none' (default), 'cgck'
1981
+ *
1982
+ * @returns {Promise<object>} - The finalize response for the new part
1983
+ */
1984
+ exports.FinalizePart = /*#__PURE__*/function () {
1985
+ var _ref45 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee24(_ref44) {
1986
+ var libraryId, objectId, writeToken, partWriteToken, encryption, path;
1987
+ return _regeneratorRuntime.wrap(function _callee24$(_context25) {
1988
+ while (1) switch (_context25.prev = _context25.next) {
1989
+ case 0:
1990
+ libraryId = _ref44.libraryId, objectId = _ref44.objectId, writeToken = _ref44.writeToken, partWriteToken = _ref44.partWriteToken, encryption = _ref44.encryption;
1991
+ ValidateParameters({
1992
+ libraryId: libraryId,
1993
+ objectId: objectId
1994
+ });
1995
+ ValidateWriteToken(writeToken);
1996
+ path = UrlJoin("q", writeToken, "parts");
1997
+ _context25.t0 = this.HttpClient;
1998
+ _context25.next = 7;
1999
+ return this.authClient.AuthorizationHeader({
2000
+ libraryId: libraryId,
2001
+ objectId: objectId,
2002
+ update: true,
2003
+ encryption: encryption
2004
+ });
2005
+ case 7:
2006
+ _context25.t1 = _context25.sent;
2007
+ _context25.t2 = UrlJoin(path, partWriteToken);
2008
+ _context25.t3 = {
2009
+ headers: _context25.t1,
2010
+ method: "POST",
2011
+ path: _context25.t2,
2012
+ bodyType: "BINARY",
2013
+ body: "",
2014
+ allowFailover: false
2015
+ };
2016
+ _context25.next = 12;
2017
+ return _context25.t0.RequestJsonBody.call(_context25.t0, _context25.t3);
2018
+ case 12:
2019
+ return _context25.abrupt("return", _context25.sent);
2020
+ case 13:
2021
+ case "end":
2022
+ return _context25.stop();
2023
+ }
2024
+ }, _callee24, this);
2025
+ }));
2026
+ return function (_x25) {
2027
+ return _ref45.apply(this, arguments);
2028
+ };
2029
+ }();
2030
+
2031
+ /**
2032
+ * Upload part to an object draft
2033
+ *
2034
+ * Note: If uploading a large file (especially with an HTML file and/or when using the FrameClient) it is
2035
+ * recommended to use the CreatePart + UploadPartChunk + FinalizePart flow to upload the file in
2036
+ * smaller chunks.
2037
+ *
2038
+ * @memberof module:ElvClient/Files+Parts
2039
+ * @methodGroup Parts
2040
+ * @namedParams
2041
+ * @param {string} libraryId - ID of the library
2042
+ * @param {string} objectId - ID of the object
2043
+ * @param {string} writeToken - Write token of the content object draft
2044
+ * @param {(File | ArrayBuffer | Buffer)} data - Data to upload
2045
+ * @param {number=} chunkSize=1000000 (1MB) - Chunk size, in bytes
2046
+ * @param {string=} encryption=none - Desired encryption scheme. Options: 'none' (default), 'cgck'
2047
+ * @param {function=} callback - If specified, will be periodically called with current upload status
2048
+ * - Signature: ({bytesFinished, bytesTotal}) => {}
2049
+ *
2050
+ * @returns {Promise<Object>} - Response containing information about the uploaded part
2051
+ */
2052
+ exports.UploadPart = /*#__PURE__*/function () {
2053
+ var _ref47 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee25(_ref46) {
2054
+ var libraryId, objectId, writeToken, data, _ref46$encryption, encryption, _ref46$chunkSize, chunkSize, callback, partWriteToken, size, i, chunk;
2055
+ return _regeneratorRuntime.wrap(function _callee25$(_context26) {
2056
+ while (1) switch (_context26.prev = _context26.next) {
2057
+ case 0:
2058
+ libraryId = _ref46.libraryId, objectId = _ref46.objectId, writeToken = _ref46.writeToken, data = _ref46.data, _ref46$encryption = _ref46.encryption, encryption = _ref46$encryption === void 0 ? "none" : _ref46$encryption, _ref46$chunkSize = _ref46.chunkSize, chunkSize = _ref46$chunkSize === void 0 ? 10000000 : _ref46$chunkSize, callback = _ref46.callback;
2059
+ ValidateParameters({
2060
+ libraryId: libraryId,
2061
+ objectId: objectId
2062
+ });
2063
+ ValidateWriteToken(writeToken);
2064
+ _context26.next = 5;
2065
+ return this.CreatePart({
2066
+ libraryId: libraryId,
2067
+ objectId: objectId,
2068
+ writeToken: writeToken,
2069
+ encryption: encryption
2070
+ });
2071
+ case 5:
2072
+ partWriteToken = _context26.sent;
2073
+ size = data.length || data.byteLength || data.size;
2074
+ if (callback) {
2075
+ callback({
2076
+ bytesFinished: 0,
2077
+ bytesTotal: size
2078
+ });
2079
+ }
2080
+ i = 0;
2081
+ case 9:
2082
+ if (!(i < size)) {
2083
+ _context26.next = 17;
2084
+ break;
2085
+ }
2086
+ chunk = data.slice(i, i + chunkSize);
2087
+ _context26.next = 13;
2088
+ return this.UploadPartChunk({
2089
+ libraryId: libraryId,
2090
+ objectId: objectId,
2091
+ writeToken: writeToken,
2092
+ partWriteToken: partWriteToken,
2093
+ chunk: chunk,
2094
+ encryption: encryption
2095
+ });
2096
+ case 13:
2097
+ if (callback) {
2098
+ callback({
2099
+ bytesFinished: Math.min(i + chunkSize, size),
2100
+ bytesTotal: size
2101
+ });
2102
+ }
2103
+ case 14:
2104
+ i += chunkSize;
2105
+ _context26.next = 9;
2106
+ break;
2107
+ case 17:
2108
+ _context26.next = 19;
2109
+ return this.FinalizePart({
2110
+ libraryId: libraryId,
2111
+ objectId: objectId,
2112
+ writeToken: writeToken,
2113
+ partWriteToken: partWriteToken,
2114
+ encryption: encryption
2115
+ });
2116
+ case 19:
2117
+ return _context26.abrupt("return", _context26.sent);
2118
+ case 20:
2119
+ case "end":
2120
+ return _context26.stop();
2121
+ }
2122
+ }, _callee25, this);
2123
+ }));
2124
+ return function (_x26) {
2125
+ return _ref47.apply(this, arguments);
2126
+ };
2127
+ }();
2128
+
2129
+ /**
2130
+ * Delete the specified part from a content draft
2131
+ *
2132
+ * @memberof module:ElvClient/Files+Parts
2133
+ * @methodGroup Parts
2134
+ * @namedParams
2135
+ * @param {string} libraryId - ID of the library
2136
+ * @param {string} objectId - ID of the object
2137
+ * @param {string} writeToken - Write token of the content object draft
2138
+ * @param {string} partHash - Hash of the part to delete
2139
+ */
2140
+ exports.DeletePart = /*#__PURE__*/function () {
2141
+ var _ref49 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee26(_ref48) {
2142
+ var libraryId, objectId, writeToken, partHash, path;
2143
+ return _regeneratorRuntime.wrap(function _callee26$(_context27) {
2144
+ while (1) switch (_context27.prev = _context27.next) {
2145
+ case 0:
2146
+ libraryId = _ref48.libraryId, objectId = _ref48.objectId, writeToken = _ref48.writeToken, partHash = _ref48.partHash;
2147
+ ValidateParameters({
2148
+ libraryId: libraryId,
2149
+ objectId: objectId
2150
+ });
2151
+ ValidateWriteToken(writeToken);
2152
+ ValidatePartHash(partHash);
2153
+ path = UrlJoin("q", writeToken, "parts", partHash);
2154
+ _context27.t0 = this.HttpClient;
2155
+ _context27.next = 8;
2156
+ return this.authClient.AuthorizationHeader({
2157
+ libraryId: libraryId,
2158
+ objectId: objectId,
2159
+ update: true
2160
+ });
2161
+ case 8:
2162
+ _context27.t1 = _context27.sent;
2163
+ _context27.t2 = path;
2164
+ _context27.t3 = {
2165
+ headers: _context27.t1,
2166
+ method: "DELETE",
2167
+ path: _context27.t2,
2168
+ allowFailover: false
2169
+ };
2170
+ _context27.next = 13;
2171
+ return _context27.t0.Request.call(_context27.t0, _context27.t3);
2172
+ case 13:
2173
+ case "end":
2174
+ return _context27.stop();
2175
+ }
2176
+ }, _callee26, this);
2177
+ }));
2178
+ return function (_x27) {
2179
+ return _ref49.apply(this, arguments);
2180
+ };
2181
+ }();