@eluvio/elv-client-js 4.2.27 → 4.2.30

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.
@@ -1,7 +1,11 @@
1
+ var _slicedToArray = require("@babel/runtime/helpers/slicedToArray");
1
2
  var _toConsumableArray = require("@babel/runtime/helpers/toConsumableArray");
2
3
  var _defineProperty = require("@babel/runtime/helpers/defineProperty");
3
4
  var _regeneratorRuntime = require("@babel/runtime/regenerator");
4
5
  var _asyncToGenerator = require("@babel/runtime/helpers/asyncToGenerator");
6
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
7
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
8
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
5
9
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
10
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
11
  /**
@@ -24,6 +28,12 @@ var _require = require("../Validation"),
24
28
  ValidateWriteToken = _require.ValidateWriteToken,
25
29
  ValidatePartHash = _require.ValidatePartHash,
26
30
  ValidateParameters = _require.ValidateParameters;
31
+ var JobStatus = Object.freeze({
32
+ STOPPED: "STOPPED",
33
+ FAILED: "FAILED",
34
+ IN_PROGRESS: "IN_PROGRESS",
35
+ COMPLETED: "COMPLETED"
36
+ });
27
37
 
28
38
  /* Files */
29
39
 
@@ -84,7 +94,7 @@ exports.ListFiles = /*#__PURE__*/function () {
84
94
  }();
85
95
 
86
96
  /**
87
- * Copy/reference files from S3 to a content object.
97
+ * Upload or resume copy/reference files from S3 to a content object
88
98
  *
89
99
  * 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
100
  *
@@ -92,12 +102,12 @@ exports.ListFiles = /*#__PURE__*/function () {
92
102
  *
93
103
  * Expected format of fileInfo:
94
104
  *
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
- ]
105
+ [
106
+ {
107
+ path: string,
108
+ source: string // either a full path e.g. "s3://BUCKET_NAME/path..." or just the path part without "s3://BUCKET_NAME/"
109
+ }
110
+ ]
101
111
  *
102
112
  * @memberof module:ElvClient/Files+Parts
103
113
  * @methodGroup Files
@@ -105,25 +115,27 @@ exports.ListFiles = /*#__PURE__*/function () {
105
115
  * @param {string} libraryId - ID of the library
106
116
  * @param {string} objectId - ID of the object
107
117
  * @param {string} writeToken - Write token of the draft
108
- * @param {string} region - AWS region to use
109
- * @param {string} bucket - AWS bucket to use
118
+ * @param {string=} region - AWS region to use
119
+ * @param {string=} bucket - AWS bucket to use
110
120
  * @param {Array<Object>} fileInfo - List of files to reference/copy
111
- * @param {string} accessKey - AWS access key
112
- * @param {string} secret - AWS secret
121
+ * @param {string=} accessKey - AWS access key
122
+ * @param {string=} secret - AWS secret
113
123
  * @param {string=} signedUrl
114
124
  * @param {string} encryption="none" - Encryption for uploaded files (copy only) - cgck | none
115
125
  * @param {boolean} copy=false - If true, will copy the data from S3 into the fabric. Otherwise, a reference to the content will be made.
126
+ * @param {boolean} resume=false - If true, will resume the file jobs stopped
116
127
  * @param {function=} callback - If specified, will be periodically called with current upload status
117
128
  * - Arguments (copy): { done: boolean, uploaded: number, total: number, uploadedFiles: number, totalFiles: number, fileStatus: Object }
118
129
  * - Arguments (reference): { done: boolean, uploadedFiles: number, totalFiles: number }
119
130
  */
120
131
  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) {
132
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref3) {
133
+ var _this = this;
134
+ var libraryId, objectId, writeToken, region, bucket, fileInfo, accessKey, secret, signedUrl, _ref3$encryption, encryption, _ref3$copy, copy, _ref3$resume, resume, callback, s3prefixRegex, i, fileSourcePath, s3prefixMatch, bucketName, encryption_key, conk, cloudCredentials, remoteAccess, defaults, ops, trackUploadStatus, jobIds, jobsByStatus, resumeAndTrack, _i, _arr, status, trackOnlyEntries, _yield$this$CreateFil, uploadId;
135
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
136
+ while (1) switch (_context6.prev = _context6.next) {
125
137
  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;
138
+ 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, _ref3$resume = _ref3.resume, resume = _ref3$resume === void 0 ? false : _ref3$resume, callback = _ref3.callback;
127
139
  ValidateParameters({
128
140
  libraryId: libraryId,
129
141
  objectId: objectId
@@ -134,71 +146,65 @@ exports.UploadFilesFromS3 = /*#__PURE__*/function () {
134
146
  i = 0;
135
147
  case 5:
136
148
  if (!(i < fileInfo.length)) {
137
- _context2.next = 18;
149
+ _context6.next = 16;
138
150
  break;
139
151
  }
140
152
  fileSourcePath = fileInfo[i].source;
141
153
  s3prefixMatch = s3prefixRegex.exec(fileSourcePath);
142
154
  if (!s3prefixMatch) {
143
- _context2.next = 15;
155
+ _context6.next = 13;
144
156
  break;
145
157
  }
146
158
  bucketName = s3prefixMatch[1];
147
159
  if (!(bucketName !== bucket)) {
148
- _context2.next = 14;
160
+ _context6.next = 12;
149
161
  break;
150
162
  }
151
163
  throw Error("Full S3 file path \"" + fileSourcePath + "\" specified, but does not match provided bucket name '" + bucket + "'");
152
- case 14:
164
+ case 12:
153
165
  // strip prefix
154
166
  fileInfo[i].source = fileSourcePath.replace(s3prefixRegex, "");
155
- case 15:
167
+ case 13:
156
168
  i++;
157
- _context2.next = 5;
169
+ _context6.next = 5;
158
170
  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
- }
171
+ case 16:
172
+ this.Log("".concat(resume ? "Resuming" : copy ? "Copying" : "Referencing", " files from S3: ").concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
165
173
  if (!(encryption === "cgck")) {
166
- _context2.next = 25;
174
+ _context6.next = 23;
167
175
  break;
168
176
  }
169
- _context2.next = 22;
177
+ _context6.next = 20;
170
178
  return this.EncryptionConk({
171
179
  libraryId: libraryId,
172
180
  objectId: objectId,
173
181
  writeToken: writeToken
174
182
  });
175
- case 22:
176
- conk = _context2.sent;
183
+ case 20:
184
+ conk = _context6.sent;
177
185
  conk = _objectSpread(_objectSpread({}, conk), {}, {
178
186
  secret_key: ""
179
187
  });
180
188
  encryption_key = "kp__".concat(this.utils.B58(Buffer.from(JSON.stringify(conk))));
181
- case 25:
182
- cloudCredentials = {
189
+ case 23:
190
+ cloudCredentials = signedUrl ? {
191
+ signed_url: signedUrl
192
+ } : {
183
193
  access_key_id: accessKey,
184
194
  secret_access_key: secret
185
195
  };
186
- if (signedUrl) {
187
- cloudCredentials = {
188
- signed_url: signedUrl
189
- };
190
- }
196
+ remoteAccess = {
197
+ protocol: "s3",
198
+ platform: "aws",
199
+ cloud_credentials: cloudCredentials
200
+ };
201
+ if (bucket) remoteAccess.path = bucket;
202
+ if (region) remoteAccess.storage_endpoint = {
203
+ region: region
204
+ };
191
205
  defaults = {
192
206
  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
- }
207
+ access: remoteAccess
202
208
  };
203
209
  ops = fileInfo.map(function (info) {
204
210
  if (copy) {
@@ -223,94 +229,242 @@ exports.UploadFilesFromS3 = /*#__PURE__*/function () {
223
229
  }
224
230
  };
225
231
  }
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
232
  });
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;
233
+ trackUploadStatus = /*#__PURE__*/function () {
234
+ var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_ref5) {
235
+ var uploadId, status, done, progress, _progress;
236
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
237
+ while (1) switch (_context2.prev = _context2.next) {
238
+ case 0:
239
+ uploadId = _ref5.uploadId;
240
+ case 1:
241
+ if (!true) {
242
+ _context2.next = 24;
243
+ break;
244
+ }
245
+ _context2.next = 4;
246
+ return new Promise(function (resolve) {
247
+ return setTimeout(resolve, 1000);
248
+ });
249
+ case 4:
250
+ _context2.next = 6;
251
+ return _this.UploadStatus({
252
+ libraryId: libraryId,
253
+ objectId: objectId,
254
+ writeToken: writeToken,
255
+ uploadId: uploadId
256
+ });
257
+ case 6:
258
+ status = _context2.sent;
259
+ if (!(status.errors && status.errors.length >= 1)) {
260
+ _context2.next = 11;
261
+ break;
262
+ }
263
+ throw new Error(status.errors.join("\n"));
264
+ case 11:
265
+ if (!status.error) {
266
+ _context2.next = 16;
267
+ break;
268
+ }
269
+ _this.Log("S3 file upload failed:\n".concat(JSON.stringify(status, null, 2)));
270
+ throw new Error(status.error);
271
+ case 16:
272
+ if (!(status.status.toLowerCase() === "failed")) {
273
+ _context2.next = 18;
274
+ break;
275
+ }
276
+ throw new Error("File upload failed");
277
+ case 18:
278
+ done = false;
279
+ if (copy) {
280
+ done = status.ingest_copy.done;
281
+ if (callback) {
282
+ progress = status.ingest_copy.progress;
283
+ callback({
284
+ done: done,
285
+ uploaded: progress.bytes.completed,
286
+ total: progress.bytes.total,
287
+ uploadedFiles: progress.files.completed,
288
+ totalFiles: progress.files.total,
289
+ fileStatus: progress.files.details
290
+ });
291
+ }
292
+ } else {
293
+ done = status.add_reference.done;
294
+ if (callback) {
295
+ _progress = status.add_reference.progress;
296
+ callback({
297
+ done: done,
298
+ uploadedFiles: _progress.completed,
299
+ totalFiles: _progress.total
300
+ });
301
+ }
302
+ }
303
+ if (!done) {
304
+ _context2.next = 22;
305
+ break;
306
+ }
307
+ return _context2.abrupt("break", 24);
308
+ case 22:
309
+ _context2.next = 1;
310
+ break;
311
+ case 24:
312
+ case "end":
313
+ return _context2.stop();
314
+ }
315
+ }, _callee2);
316
+ }));
317
+ return function trackUploadStatus(_x3) {
318
+ return _ref6.apply(this, arguments);
319
+ };
320
+ }();
321
+ if (!resume) {
322
+ _context6.next = 50;
241
323
  break;
242
324
  }
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({
325
+ _context6.next = 33;
326
+ return this.ListFilesJob({
250
327
  libraryId: libraryId,
251
328
  objectId: objectId,
252
329
  writeToken: writeToken,
253
- uploadId: id
330
+ encryption: encryption
254
331
  });
255
- case 38:
256
- status = _context2.sent;
257
- if (!(status.errors && status.errors.length > 1)) {
258
- _context2.next = 43;
332
+ case 33:
333
+ jobIds = _context6.sent;
334
+ jobsByStatus = jobIds.reduce(function (acc, job) {
335
+ acc[job.status] = acc[job.status] || new Map();
336
+ acc[job.status].set(job.id, true);
337
+ return acc;
338
+ }, {});
339
+ resumeAndTrack = /*#__PURE__*/function () {
340
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(jobIds) {
341
+ var responses;
342
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
343
+ while (1) switch (_context4.prev = _context4.next) {
344
+ case 0:
345
+ _context4.next = 2;
346
+ return _this.ResumeFileUploadJob({
347
+ libraryId: libraryId,
348
+ objectId: objectId,
349
+ writeToken: writeToken,
350
+ ops: ops,
351
+ defaults: defaults,
352
+ encryption: encryption,
353
+ stoppedOrFailedJobIds: jobIds
354
+ });
355
+ case 2:
356
+ responses = _context4.sent;
357
+ _context4.next = 5;
358
+ return _this.utils.LimitedMap(5, responses, /*#__PURE__*/function () {
359
+ var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(res) {
360
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
361
+ while (1) switch (_context3.prev = _context3.next) {
362
+ case 0:
363
+ _this.Log("Tracking resumed job id: ".concat(res.id));
364
+ _context3.next = 3;
365
+ return trackUploadStatus({
366
+ uploadId: res.id
367
+ });
368
+ case 3:
369
+ case "end":
370
+ return _context3.stop();
371
+ }
372
+ }, _callee3);
373
+ }));
374
+ return function (_x5) {
375
+ return _ref8.apply(this, arguments);
376
+ };
377
+ }());
378
+ case 5:
379
+ case "end":
380
+ return _context4.stop();
381
+ }
382
+ }, _callee4);
383
+ }));
384
+ return function resumeAndTrack(_x4) {
385
+ return _ref7.apply(this, arguments);
386
+ };
387
+ }();
388
+ _i = 0, _arr = [JobStatus.STOPPED, JobStatus.FAILED];
389
+ case 37:
390
+ if (!(_i < _arr.length)) {
391
+ _context6.next = 45;
259
392
  break;
260
393
  }
261
- throw status.errors.join("\n");
262
- case 43:
263
- if (!status.error) {
264
- _context2.next = 48;
394
+ status = _arr[_i];
395
+ if (!jobsByStatus[status]) {
396
+ _context6.next = 42;
265
397
  break;
266
398
  }
267
- this.Log("S3 file upload failed:\n".concat(JSON.stringify(status, null, 2)));
268
- throw status.error;
399
+ _context6.next = 42;
400
+ return resumeAndTrack(_toConsumableArray(jobsByStatus[status].keys()));
401
+ case 42:
402
+ _i++;
403
+ _context6.next = 37;
404
+ break;
405
+ case 45:
406
+ trackOnlyEntries = Object.entries(jobsByStatus).filter(function (_ref9) {
407
+ var _ref10 = _slicedToArray(_ref9, 1),
408
+ status = _ref10[0];
409
+ return [JobStatus.IN_PROGRESS, JobStatus.COMPLETED].includes(status);
410
+ }).flatMap(function (_ref11) {
411
+ var _ref12 = _slicedToArray(_ref11, 2),
412
+ status = _ref12[0],
413
+ jobs = _ref12[1];
414
+ return _toConsumableArray(jobs.keys()).map(function (jobId) {
415
+ return {
416
+ status: status,
417
+ jobId: jobId
418
+ };
419
+ });
420
+ });
421
+ _context6.next = 48;
422
+ return this.utils.LimitedMap(5, trackOnlyEntries, /*#__PURE__*/function () {
423
+ var _ref14 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref13) {
424
+ var status, jobId;
425
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
426
+ while (1) switch (_context5.prev = _context5.next) {
427
+ case 0:
428
+ status = _ref13.status, jobId = _ref13.jobId;
429
+ _this.Log("Tracking ".concat(status.toLowerCase(), " job id: ").concat(jobId));
430
+ _context5.next = 4;
431
+ return trackUploadStatus({
432
+ uploadId: jobId
433
+ });
434
+ case 4:
435
+ case "end":
436
+ return _context5.stop();
437
+ }
438
+ }, _callee5);
439
+ }));
440
+ return function (_x6) {
441
+ return _ref14.apply(this, arguments);
442
+ };
443
+ }());
269
444
  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;
445
+ _context6.next = 56;
308
446
  break;
447
+ case 50:
448
+ _context6.next = 52;
449
+ return this.CreateFileUploadJob({
450
+ libraryId: libraryId,
451
+ objectId: objectId,
452
+ writeToken: writeToken,
453
+ ops: ops,
454
+ defaults: defaults
455
+ });
456
+ case 52:
457
+ _yield$this$CreateFil = _context6.sent;
458
+ uploadId = _yield$this$CreateFil.id;
459
+ _context6.next = 56;
460
+ return trackUploadStatus({
461
+ uploadId: uploadId
462
+ });
309
463
  case 56:
310
464
  case "end":
311
- return _context2.stop();
465
+ return _context6.stop();
312
466
  }
313
- }, _callee2, this);
467
+ }, _callee6, this);
314
468
  }));
315
469
  return function (_x2) {
316
470
  return _ref4.apply(this, arguments);
@@ -322,14 +476,14 @@ exports.UploadFilesFromS3 = /*#__PURE__*/function () {
322
476
  *
323
477
  * Expected format of fileInfo:
324
478
  *
325
- [
326
- {
327
- path: string,
328
- mime_type: string,
329
- size: number,
330
- data: File | ArrayBuffer | Buffer | File Descriptor (Node)
331
- }
332
- ]
479
+ [
480
+ {
481
+ path: string,
482
+ mime_type: string,
483
+ size: number,
484
+ data: File | ArrayBuffer | Buffer | File Descriptor (Node)
485
+ }
486
+ ]
333
487
  *
334
488
  *
335
489
  * @memberof module:ElvClient/Files+Parts
@@ -339,18 +493,19 @@ exports.UploadFilesFromS3 = /*#__PURE__*/function () {
339
493
  * @param {string} objectId - ID of the object
340
494
  * @param {string} writeToken - Write token of the draft
341
495
  * @param {Array<object>} fileInfo - List of files to upload, including their size, type, and contents
496
+ * @param {string} resume - Resume the upload jobs
342
497
  * @param {string} encryption="none" - Encryption for uploaded files - cgck | none
343
498
  * @param {function=} callback - If specified, will be called after each job segment is finished with the current upload progress
344
499
  * - Format: {"filename1": {uploaded: number, total: number}, ...}
345
500
  */
346
501
  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) {
502
+ var _ref16 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(_ref15) {
503
+ var _this2 = this;
504
+ var libraryId, objectId, writeToken, fileInfo, _ref15$resume, resume, _ref15$encryption, encryption, callback, conk, progress, fileDataMap, originalFileInfo, i, entry, idJobMap, ids, jobsByStatus, stoppedJobIds, failedJobIds, inProgressJobIds, resumeJobIds, resumeJobs, _i2, _arr2, jobsToResume, uploadJobsResults, jobResponse, bufferSize, _iterator, _step, _loop;
505
+ return _regeneratorRuntime.wrap(function _callee13$(_context15) {
506
+ while (1) switch (_context15.prev = _context15.next) {
352
507
  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;
508
+ libraryId = _ref15.libraryId, objectId = _ref15.objectId, writeToken = _ref15.writeToken, fileInfo = _ref15.fileInfo, _ref15$resume = _ref15.resume, resume = _ref15$resume === void 0 ? false : _ref15$resume, _ref15$encryption = _ref15.encryption, encryption = _ref15$encryption === void 0 ? "none" : _ref15$encryption, callback = _ref15.callback;
354
509
  ValidateParameters({
355
510
  libraryId: libraryId,
356
511
  objectId: objectId
@@ -359,17 +514,17 @@ exports.UploadFiles = /*#__PURE__*/function () {
359
514
  ValidatePresence("fileInfo", fileInfo);
360
515
  this.Log("Uploading files: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
361
516
  if (!(encryption === "cgck")) {
362
- _context7.next = 9;
517
+ _context15.next = 9;
363
518
  break;
364
519
  }
365
- _context7.next = 8;
520
+ _context15.next = 8;
366
521
  return this.EncryptionConk({
367
522
  libraryId: libraryId,
368
523
  objectId: objectId,
369
524
  writeToken: writeToken
370
525
  });
371
526
  case 8:
372
- conk = _context7.sent;
527
+ conk = _context15.sent;
373
528
  case 9:
374
529
  // Extract file data into easily accessible hash while removing the data from the fileinfo for upload job creation
375
530
  progress = {};
@@ -395,294 +550,507 @@ exports.UploadFiles = /*#__PURE__*/function () {
395
550
  fileInfo.push(entry);
396
551
  }
397
552
  this.Log(fileInfo);
398
- if (callback) {
553
+
554
+ // On a fresh upload nothing has happened yet, so 0% is accurate. On resume, the real starting
555
+ // point isn't known until job status is fetched below, so skip this to avoid a misleading
556
+ // initial 0% line ahead of the actual (possibly much higher) baseline.
557
+ if (callback && !resume) {
399
558
  callback(progress);
400
559
  }
401
- _context7.next = 18;
402
- return this.CreateFileUploadJob({
560
+ idJobMap = new Map();
561
+ if (!resume) {
562
+ _context15.next = 45;
563
+ break;
564
+ }
565
+ _context15.next = 20;
566
+ return this.ListFilesJob({
403
567
  libraryId: libraryId,
404
568
  objectId: objectId,
405
569
  writeToken: writeToken,
406
- ops: fileInfo,
407
570
  encryption: encryption
408
571
  });
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) {
572
+ case 20:
573
+ ids = _context15.sent;
574
+ jobsByStatus = ids.reduce(function (acc, job) {
575
+ acc[job.status] = acc[job.status] || [];
576
+ acc[job.status].push(job.id);
577
+ return acc;
578
+ }, {});
579
+ stoppedJobIds = jobsByStatus.STOPPED || [];
580
+ failedJobIds = jobsByStatus.FAILED || [];
581
+ inProgressJobIds = jobsByStatus.IN_PROGRESS || [];
582
+ resumeJobIds = [].concat(_toConsumableArray(stoppedJobIds), _toConsumableArray(failedJobIds), _toConsumableArray(inProgressJobIds));
583
+ if (!(resumeJobIds.length === 0)) {
584
+ _context15.next = 29;
585
+ break;
586
+ }
587
+ this.Log("No job Ids to resume");
588
+ return _context15.abrupt("return");
589
+ case 29:
590
+ resumeJobs = /*#__PURE__*/function () {
591
+ var _ref17 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(jobs) {
592
+ return _regeneratorRuntime.wrap(function _callee7$(_context7) {
593
+ while (1) switch (_context7.prev = _context7.next) {
426
594
  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({
595
+ _context7.next = 2;
596
+ return _this2.ResumeFileUploadJob({
450
597
  libraryId: libraryId,
451
598
  objectId: objectId,
452
599
  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);
600
+ ops: fileInfo,
601
+ encryption: encryption,
602
+ stoppedOrFailedJobIds: jobs
496
603
  });
497
- case 28:
498
- j++;
499
- _context3.next = 1;
500
- break;
501
- case 31:
604
+ case 2:
502
605
  case "end":
503
- return _context3.stop();
606
+ return _context7.stop();
504
607
  }
505
- }, _callee3);
608
+ }, _callee7);
506
609
  }));
507
- return function PrepareJobs() {
508
- return _ref7.apply(this, arguments);
610
+ return function resumeJobs(_x8) {
611
+ return _ref17.apply(this, arguments);
509
612
  };
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) {
613
+ }(); // resume stopped and failed jobs
614
+ _i2 = 0, _arr2 = [stoppedJobIds, failedJobIds];
615
+ case 31:
616
+ if (!(_i2 < _arr2.length)) {
617
+ _context15.next = 39;
618
+ break;
619
+ }
620
+ jobsToResume = _arr2[_i2];
621
+ if (!(jobsToResume.length > 0)) {
622
+ _context15.next = 36;
623
+ break;
624
+ }
625
+ _context15.next = 36;
626
+ return resumeJobs(jobsToResume);
627
+ case 36:
628
+ _i2++;
629
+ _context15.next = 31;
630
+ break;
631
+ case 39:
632
+ _context15.next = 41;
633
+ return this.utils.LimitedMap(5, resumeJobIds, /*#__PURE__*/function () {
634
+ var _ref18 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(uploadId) {
635
+ var result;
636
+ return _regeneratorRuntime.wrap(function _callee8$(_context8) {
637
+ while (1) switch (_context8.prev = _context8.next) {
516
638
  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);
639
+ _context8.next = 2;
640
+ return _this2.ListFilesUploadJobs({
641
+ libraryId: libraryId,
642
+ objectId: objectId,
643
+ writeToken: writeToken,
644
+ jobId: uploadId,
645
+ encryption: encryption
524
646
  });
525
- case 3:
526
- _context5.next = 0;
647
+ case 2:
648
+ result = _context8.sent;
649
+ return _context8.abrupt("return", result.jobs);
650
+ case 4:
651
+ case "end":
652
+ return _context8.stop();
653
+ }
654
+ }, _callee8);
655
+ }));
656
+ return function (_x9) {
657
+ return _ref18.apply(this, arguments);
658
+ };
659
+ }());
660
+ case 41:
661
+ uploadJobsResults = _context15.sent;
662
+ resumeJobIds.forEach(function (uploadId, i) {
663
+ return idJobMap.set(uploadId, uploadJobsResults[i]);
664
+ });
665
+ _context15.next = 49;
666
+ break;
667
+ case 45:
668
+ _context15.next = 47;
669
+ return this.CreateFileUploadJob({
670
+ libraryId: libraryId,
671
+ objectId: objectId,
672
+ writeToken: writeToken,
673
+ ops: fileInfo,
674
+ encryption: encryption
675
+ });
676
+ case 47:
677
+ jobResponse = _context15.sent;
678
+ idJobMap.set(jobResponse.id, jobResponse.jobs);
679
+ case 49:
680
+ // How far encryption can get ahead of upload (500 MB)
681
+ bufferSize = 500 * 1024 * 1024; // Process each uploadId and its jobs
682
+ _iterator = _createForOfIteratorHelper(idJobMap.entries());
683
+ _context15.prev = 51;
684
+ _loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
685
+ var _step$value, uploadId, jobs, prepared, uploaded, jobSpecs, alreadyCreditedKeys, PrepareJobs, UploadJob, rateTestJobs, rates, j, start, elapsed, size, averageRate, concurrentUploads;
686
+ return _regeneratorRuntime.wrap(function _loop$(_context14) {
687
+ while (1) switch (_context14.prev = _context14.next) {
688
+ case 0:
689
+ _step$value = _slicedToArray(_step.value, 2), uploadId = _step$value[0], jobs = _step$value[1];
690
+ _this2.Log("Upload ID: ".concat(uploadId));
691
+ _this2.Log(jobs.length);
692
+
693
+ // Each upload ID gets its own counters
694
+ prepared = 0;
695
+ uploaded = 0;
696
+ jobSpecs = []; // `${jobId}:${path}` pairs already reflected in progress by the resume baseline scan below,
697
+ // so the normal per-chunk completion credit further down doesn't double-count them
698
+ // It stores the jobId whose remaining bytes = 0
699
+ alreadyCreditedKeys = new Set();
700
+ if (!(resume && callback)) {
701
+ _context14.next = 11;
527
702
  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) {
703
+ }
704
+ _context14.next = 10;
705
+ return _this2.utils.LimitedMap(5, jobs, /*#__PURE__*/function () {
706
+ var _ref19 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(jobId) {
707
+ var job, _iterator2, _step2, _fileInfo, fileStatus;
708
+ return _regeneratorRuntime.wrap(function _callee9$(_context9) {
709
+ while (1) switch (_context9.prev = _context9.next) {
535
710
  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({
711
+ _context9.next = 2;
712
+ return _this2.UploadJobStatus({
543
713
  libraryId: libraryId,
544
714
  objectId: objectId,
545
715
  writeToken: writeToken,
546
- uploadId: id,
547
- jobId: jobId,
548
- filePath: fileInfo.path,
549
- fileData: fileInfo.data,
550
- encryption: encryption
716
+ uploadId: uploadId,
717
+ jobId: jobId
551
718
  });
552
- case 6:
553
- succeeded = true;
554
- _context4.next = 17;
719
+ case 2:
720
+ job = _context9.sent;
721
+ _iterator2 = _createForOfIteratorHelper(job.files);
722
+ try {
723
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
724
+ _fileInfo = _step2.value;
725
+ // When encrypted, the top-level rem/skip are sentinel (-1) - the real, already-received
726
+ // byte counts for this chunk are under `encrypted` (same lookup UploadFileData uses)
727
+ fileStatus = encryption && encryption !== "none" ? _fileInfo.encrypted : _fileInfo;
728
+ if (fileStatus.rem === 0) {
729
+ alreadyCreditedKeys.add("".concat(jobId, ":").concat(_fileInfo.path));
730
+ progress[_fileInfo.path] = _objectSpread(_objectSpread({}, progress[_fileInfo.path]), {}, {
731
+ uploaded: progress[_fileInfo.path].uploaded + _fileInfo.len
732
+ });
733
+ }
734
+ }
735
+ } catch (err) {
736
+ _iterator2.e(err);
737
+ } finally {
738
+ _iterator2.f();
739
+ }
740
+ case 5:
741
+ case "end":
742
+ return _context9.stop();
743
+ }
744
+ }, _callee9);
745
+ }));
746
+ return function (_x10) {
747
+ return _ref19.apply(this, arguments);
748
+ };
749
+ }());
750
+ case 10:
751
+ callback(progress);
752
+ case 11:
753
+ // Insert the data to upload into the job spec, encrypting if necessary
754
+ PrepareJobs = /*#__PURE__*/function () {
755
+ var _ref20 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10() {
756
+ var j, jobId, job, f, _fileInfo2, data;
757
+ return _regeneratorRuntime.wrap(function _callee10$(_context10) {
758
+ while (1) switch (_context10.prev = _context10.next) {
759
+ case 0:
760
+ j = 0;
761
+ case 1:
762
+ if (!(j < jobs.length)) {
763
+ _context10.next = 31;
764
+ break;
765
+ }
766
+ case 2:
767
+ if (!(prepared - uploaded > bufferSize)) {
768
+ _context10.next = 7;
769
+ break;
770
+ }
771
+ _context10.next = 5;
772
+ return new Promise(function (resolve) {
773
+ return setTimeout(resolve, 500);
774
+ });
775
+ case 5:
776
+ _context10.next = 2;
555
777
  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;
778
+ case 7:
779
+ // Retrieve job info
780
+ jobId = jobs[j];
781
+ _context10.next = 10;
782
+ return _this2.UploadJobStatus({
783
+ libraryId: libraryId,
784
+ objectId: objectId,
785
+ writeToken: writeToken,
786
+ uploadId: uploadId,
787
+ jobId: jobId
788
+ });
789
+ case 10:
790
+ job = _context10.sent;
791
+ f = 0;
792
+ case 12:
793
+ if (!(f < job.files.length)) {
794
+ _context10.next = 25;
795
+ break;
796
+ }
797
+ _fileInfo2 = job.files[f];
798
+ data = void 0;
799
+ if (typeof fileDataMap[_fileInfo2.path] === "number") {
800
+ // File descriptor - Read data from file
801
+ data = Buffer.alloc(_fileInfo2.len);
802
+ fs.readSync(fileDataMap[_fileInfo2.path], data, 0, _fileInfo2.len, _fileInfo2.off);
803
+ } else {
804
+ // Full data - Slice requested chunk
805
+ data = fileDataMap[_fileInfo2.path].slice(_fileInfo2.off, _fileInfo2.off + _fileInfo2.len);
806
+ }
807
+ if (!(encryption === "cgck")) {
808
+ _context10.next = 20;
563
809
  break;
564
810
  }
565
- throw _context4.t0;
566
- case 15:
567
- _context4.next = 17;
811
+ _context10.next = 19;
812
+ return _this2.Crypto.Encrypt(conk, data);
813
+ case 19:
814
+ data = _context10.sent;
815
+ case 20:
816
+ job.files[f].data = data;
817
+ prepared += _fileInfo2.len;
818
+ case 22:
819
+ f++;
820
+ _context10.next = 12;
821
+ break;
822
+ case 25:
823
+ jobSpecs[j] = job;
824
+
825
+ // Wait for a bit to let upload start
826
+ _context10.next = 28;
568
827
  return new Promise(function (resolve) {
569
- return setTimeout(resolve, 10 * retries * 1000);
828
+ return setTimeout(resolve, 50);
570
829
  });
571
- case 17:
572
- if (!succeeded && retries < 10) {
573
- _context4.next = 3;
830
+ case 28:
831
+ j++;
832
+ _context10.next = 1;
833
+ break;
834
+ case 31:
835
+ case "end":
836
+ return _context10.stop();
837
+ }
838
+ }, _callee10);
839
+ }));
840
+ return function PrepareJobs() {
841
+ return _ref20.apply(this, arguments);
842
+ };
843
+ }();
844
+ UploadJob = /*#__PURE__*/function () {
845
+ var _ref21 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(jobId, j) {
846
+ var jobSpec, files, _loop2, f;
847
+ return _regeneratorRuntime.wrap(function _callee11$(_context12) {
848
+ while (1) switch (_context12.prev = _context12.next) {
849
+ case 0:
850
+ if (jobSpecs[j]) {
851
+ _context12.next = 5;
574
852
  break;
575
853
  }
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);
854
+ _context12.next = 3;
855
+ return new Promise(function (resolve) {
856
+ return setTimeout(resolve, 500);
857
+ });
858
+ case 3:
859
+ _context12.next = 0;
860
+ break;
861
+ case 5:
862
+ jobSpec = jobSpecs[j];
863
+ files = jobSpec.files; // Upload each item
864
+ _loop2 = /*#__PURE__*/_regeneratorRuntime.mark(function _loop2() {
865
+ var fileInfo, retries, succeeded;
866
+ return _regeneratorRuntime.wrap(function _loop2$(_context11) {
867
+ while (1) switch (_context11.prev = _context11.next) {
868
+ case 0:
869
+ fileInfo = files[f];
870
+ retries = 0;
871
+ succeeded = false;
872
+ case 3:
873
+ _context11.prev = 3;
874
+ _context11.next = 6;
875
+ return _this2.UploadFileData({
876
+ libraryId: libraryId,
877
+ objectId: objectId,
878
+ writeToken: writeToken,
879
+ uploadId: uploadId,
880
+ jobId: jobId,
881
+ filePath: fileInfo.path,
882
+ fileData: fileInfo.data,
883
+ encryption: encryption
884
+ });
885
+ case 6:
886
+ succeeded = true;
887
+ _context11.next = 17;
888
+ break;
889
+ case 9:
890
+ _context11.prev = 9;
891
+ _context11.t0 = _context11["catch"](3);
892
+ _this2.Log(_context11.t0, true);
893
+ retries += 1;
894
+ if (!(retries >= 10)) {
895
+ _context11.next = 15;
896
+ break;
897
+ }
898
+ throw _context11.t0;
899
+ case 15:
900
+ _context11.next = 17;
901
+ return new Promise(function (resolve) {
902
+ return setTimeout(resolve, 10 * retries * 1000);
903
+ });
904
+ case 17:
905
+ if (!succeeded && retries < 10) {
906
+ _context11.next = 3;
907
+ break;
908
+ }
909
+ case 18:
910
+ delete jobSpecs[j].files[f].data;
911
+ uploaded += fileInfo.len;
912
+ if (callback && !alreadyCreditedKeys.has("".concat(jobId, ":").concat(fileInfo.path))) {
913
+ progress[fileInfo.path] = _objectSpread(_objectSpread({}, progress[fileInfo.path]), {}, {
914
+ uploaded: progress[fileInfo.path].uploaded + fileInfo.len
915
+ });
916
+ callback(progress);
917
+ }
918
+ case 21:
919
+ case "end":
920
+ return _context11.stop();
921
+ }
922
+ }, _loop2, null, [[3, 9]]);
923
+ });
924
+ f = 0;
925
+ case 9:
926
+ if (!(f < files.length)) {
927
+ _context12.next = 14;
928
+ break;
584
929
  }
585
- case 21:
930
+ return _context12.delegateYield(_loop2(), "t0", 11);
931
+ case 11:
932
+ f++;
933
+ _context12.next = 9;
934
+ break;
935
+ case 14:
586
936
  case "end":
587
- return _context4.stop();
937
+ return _context12.stop();
588
938
  }
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
- });
939
+ }, _callee11);
940
+ }));
941
+ return function UploadJob(_x11, _x12) {
942
+ return _ref21.apply(this, arguments);
943
+ };
944
+ }(); // Preparing jobs is done asynchronously
945
+ PrepareJobs()["catch"](function (e) {
946
+ throw e;
947
+ });
615
948
 
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;
949
+ // Upload the first several chunks in sequence, to determine average upload rate
950
+ rateTestJobs = Math.min(3, jobs.length);
951
+ rates = [];
952
+ j = 0;
953
+ case 17:
954
+ if (!(j < rateTestJobs)) {
955
+ _context14.next = 27;
956
+ break;
957
+ }
958
+ start = new Date().getTime();
959
+ _context14.next = 21;
960
+ return UploadJob(jobs[j], j);
961
+ case 21:
962
+ elapsed = (new Date().getTime() - start) / 1000;
963
+ size = jobSpecs[j].files.map(function (file) {
964
+ return file.len;
965
+ }).reduce(function (length, total) {
966
+ return length + total;
967
+ }, 0);
968
+ rates.push(size / elapsed / (1024 * 1024));
969
+ case 24:
970
+ j++;
971
+ _context14.next = 17;
972
+ break;
973
+ case 27:
974
+ averageRate = rates.reduce(function (mbps, total) {
975
+ return mbps + total;
976
+ }, 0) / rateTestJobs; // Upload remaining jobs in parallel
977
+ concurrentUploads = Math.min(5, Math.ceil(averageRate / 2));
978
+ _context14.next = 31;
979
+ return _this2.utils.LimitedMap(concurrentUploads, jobs, /*#__PURE__*/function () {
980
+ var _ref22 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(jobId, j) {
981
+ return _regeneratorRuntime.wrap(function _callee12$(_context13) {
982
+ while (1) switch (_context13.prev = _context13.next) {
983
+ case 0:
984
+ if (!(j < rateTestJobs)) {
985
+ _context13.next = 2;
986
+ break;
987
+ }
988
+ return _context13.abrupt("return");
989
+ case 2:
990
+ _context13.prev = 2;
991
+ _context13.next = 5;
992
+ return UploadJob(jobId, j);
993
+ case 5:
994
+ _context13.next = 10;
995
+ break;
996
+ case 7:
997
+ _context13.prev = 7;
998
+ _context13.t0 = _context13["catch"](2);
999
+ throw Error("Failed upload for job ".concat(jobId, ": ").concat(_context13.t0));
1000
+ case 10:
1001
+ case "end":
1002
+ return _context13.stop();
1003
+ }
1004
+ }, _callee12, null, [[2, 7]]);
1005
+ }));
1006
+ return function (_x13, _x14) {
1007
+ return _ref22.apply(this, arguments);
1008
+ };
1009
+ }());
1010
+ case 31:
1011
+ case "end":
1012
+ return _context14.stop();
1013
+ }
1014
+ }, _loop);
1015
+ });
1016
+ _iterator.s();
1017
+ case 54:
1018
+ if ((_step = _iterator.n()).done) {
1019
+ _context15.next = 58;
623
1020
  break;
624
1021
  }
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;
1022
+ return _context15.delegateYield(_loop(), "t0", 56);
1023
+ case 56:
1024
+ _context15.next = 54;
639
1025
  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:
1026
+ case 58:
1027
+ _context15.next = 63;
1028
+ break;
1029
+ case 60:
1030
+ _context15.prev = 60;
1031
+ _context15.t1 = _context15["catch"](51);
1032
+ _iterator.e(_context15.t1);
1033
+ case 63:
1034
+ _context15.prev = 63;
1035
+ _iterator.f();
1036
+ return _context15.finish(63);
1037
+ case 66:
670
1038
  case "end":
671
- return _context7.stop();
1039
+ return _context15.stop();
672
1040
  }
673
- }, _callee6, this);
1041
+ }, _callee13, this, [[51, 60, 63, 66]]);
674
1042
  }));
675
- return function (_x3) {
676
- return _ref6.apply(this, arguments);
1043
+ return function (_x7) {
1044
+ return _ref16.apply(this, arguments);
677
1045
  };
678
1046
  }();
679
1047
  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) {
1048
+ var _ref24 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(_ref23) {
1049
+ var libraryId, objectId, writeToken, ops, _ref23$defaults, defaults, _ref23$encryption, encryption, body, path;
1050
+ return _regeneratorRuntime.wrap(function _callee14$(_context16) {
1051
+ while (1) switch (_context16.prev = _context16.next) {
684
1052
  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;
1053
+ libraryId = _ref23.libraryId, objectId = _ref23.objectId, writeToken = _ref23.writeToken, ops = _ref23.ops, _ref23$defaults = _ref23.defaults, defaults = _ref23$defaults === void 0 ? {} : _ref23$defaults, _ref23$encryption = _ref23.encryption, encryption = _ref23$encryption === void 0 ? "none" : _ref23$encryption;
686
1054
  ValidateParameters({
687
1055
  libraryId: libraryId,
688
1056
  objectId: objectId
@@ -702,8 +1070,8 @@ exports.CreateFileUploadJob = /*#__PURE__*/function () {
702
1070
  ops: ops
703
1071
  };
704
1072
  path = UrlJoin("q", writeToken, "file_jobs");
705
- _context8.t0 = this.HttpClient;
706
- _context8.next = 11;
1073
+ _context16.t0 = this.HttpClient;
1074
+ _context16.next = 11;
707
1075
  return this.authClient.AuthorizationHeader({
708
1076
  libraryId: libraryId,
709
1077
  objectId: objectId,
@@ -711,169 +1079,350 @@ exports.CreateFileUploadJob = /*#__PURE__*/function () {
711
1079
  encryption: encryption
712
1080
  });
713
1081
  case 11:
714
- _context8.t1 = _context8.sent;
715
- _context8.t2 = path;
716
- _context8.t3 = body;
717
- _context8.t4 = {
718
- headers: _context8.t1,
1082
+ _context16.t1 = _context16.sent;
1083
+ _context16.t2 = path;
1084
+ _context16.t3 = body;
1085
+ _context16.t4 = {
1086
+ headers: _context16.t1,
719
1087
  method: "POST",
720
- path: _context8.t2,
721
- body: _context8.t3,
1088
+ path: _context16.t2,
1089
+ body: _context16.t3,
722
1090
  allowFailover: false
723
1091
  };
724
- return _context8.abrupt("return", _context8.t0.RequestJsonBody.call(_context8.t0, _context8.t4));
1092
+ return _context16.abrupt("return", _context16.t0.RequestJsonBody.call(_context16.t0, _context16.t4));
725
1093
  case 16:
726
1094
  case "end":
727
- return _context8.stop();
1095
+ return _context16.stop();
1096
+ }
1097
+ }, _callee14, this);
1098
+ }));
1099
+ return function (_x15) {
1100
+ return _ref24.apply(this, arguments);
1101
+ };
1102
+ }();
1103
+ exports.ListFilesJob = /*#__PURE__*/function () {
1104
+ var _ref26 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(_ref25) {
1105
+ var libraryId, objectId, writeToken, _ref25$encryption, encryption, path;
1106
+ return _regeneratorRuntime.wrap(function _callee15$(_context17) {
1107
+ while (1) switch (_context17.prev = _context17.next) {
1108
+ case 0:
1109
+ libraryId = _ref25.libraryId, objectId = _ref25.objectId, writeToken = _ref25.writeToken, _ref25$encryption = _ref25.encryption, encryption = _ref25$encryption === void 0 ? "none" : _ref25$encryption;
1110
+ ValidateParameters({
1111
+ libraryId: libraryId,
1112
+ objectId: objectId
1113
+ });
1114
+ ValidateWriteToken(writeToken);
1115
+ this.Log("List file jobs: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
1116
+ path = UrlJoin("q", writeToken, "file_jobs");
1117
+ _context17.t0 = this.HttpClient;
1118
+ _context17.next = 8;
1119
+ return this.authClient.AuthorizationHeader({
1120
+ libraryId: libraryId,
1121
+ objectId: objectId,
1122
+ update: true,
1123
+ encryption: encryption
1124
+ });
1125
+ case 8:
1126
+ _context17.t1 = _context17.sent;
1127
+ _context17.t2 = path;
1128
+ _context17.t3 = {
1129
+ headers: _context17.t1,
1130
+ method: "GET",
1131
+ path: _context17.t2,
1132
+ allowFailover: false
1133
+ };
1134
+ return _context17.abrupt("return", _context17.t0.RequestJsonBody.call(_context17.t0, _context17.t3));
1135
+ case 12:
1136
+ case "end":
1137
+ return _context17.stop();
1138
+ }
1139
+ }, _callee15, this);
1140
+ }));
1141
+ return function (_x16) {
1142
+ return _ref26.apply(this, arguments);
1143
+ };
1144
+ }();
1145
+ exports.ListFilesUploadJobs = /*#__PURE__*/function () {
1146
+ var _ref28 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(_ref27) {
1147
+ var libraryId, objectId, writeToken, jobId, _ref27$encryption, encryption, path;
1148
+ return _regeneratorRuntime.wrap(function _callee16$(_context18) {
1149
+ while (1) switch (_context18.prev = _context18.next) {
1150
+ case 0:
1151
+ libraryId = _ref27.libraryId, objectId = _ref27.objectId, writeToken = _ref27.writeToken, jobId = _ref27.jobId, _ref27$encryption = _ref27.encryption, encryption = _ref27$encryption === void 0 ? "none" : _ref27$encryption;
1152
+ ValidateParameters({
1153
+ libraryId: libraryId,
1154
+ objectId: objectId
1155
+ });
1156
+ ValidateWriteToken(writeToken);
1157
+ this.Log("List file upload jobs: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
1158
+ path = UrlJoin("qlibs", libraryId, "q", writeToken, "file_jobs", jobId, "uploads");
1159
+ _context18.t0 = this.HttpClient;
1160
+ _context18.next = 8;
1161
+ return this.authClient.AuthorizationHeader({
1162
+ libraryId: libraryId,
1163
+ objectId: objectId,
1164
+ update: true,
1165
+ encryption: encryption
1166
+ });
1167
+ case 8:
1168
+ _context18.t1 = _context18.sent;
1169
+ _context18.t2 = path;
1170
+ _context18.t3 = {
1171
+ headers: _context18.t1,
1172
+ method: "GET",
1173
+ path: _context18.t2,
1174
+ allowFailover: false
1175
+ };
1176
+ return _context18.abrupt("return", _context18.t0.RequestJsonBody.call(_context18.t0, _context18.t3));
1177
+ case 12:
1178
+ case "end":
1179
+ return _context18.stop();
1180
+ }
1181
+ }, _callee16, this);
1182
+ }));
1183
+ return function (_x17) {
1184
+ return _ref28.apply(this, arguments);
1185
+ };
1186
+ }();
1187
+ exports.ResumeFileUploadJob = /*#__PURE__*/function () {
1188
+ var _ref30 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(_ref29) {
1189
+ var libraryId, objectId, writeToken, ops, _ref29$defaults, defaults, _ref29$encryption, encryption, _ref29$stoppedOrFaile, stoppedOrFailedJobIds, body, responses, _iterator3, _step3, jobId, path, res;
1190
+ return _regeneratorRuntime.wrap(function _callee17$(_context19) {
1191
+ while (1) switch (_context19.prev = _context19.next) {
1192
+ case 0:
1193
+ libraryId = _ref29.libraryId, objectId = _ref29.objectId, writeToken = _ref29.writeToken, ops = _ref29.ops, _ref29$defaults = _ref29.defaults, defaults = _ref29$defaults === void 0 ? {} : _ref29$defaults, _ref29$encryption = _ref29.encryption, encryption = _ref29$encryption === void 0 ? "none" : _ref29$encryption, _ref29$stoppedOrFaile = _ref29.stoppedOrFailedJobIds, stoppedOrFailedJobIds = _ref29$stoppedOrFaile === void 0 ? [] : _ref29$stoppedOrFaile;
1194
+ ValidateParameters({
1195
+ libraryId: libraryId,
1196
+ objectId: objectId
1197
+ });
1198
+ ValidateWriteToken(writeToken);
1199
+ if (!(stoppedOrFailedJobIds.length === 0)) {
1200
+ _context19.next = 6;
1201
+ break;
1202
+ }
1203
+ this.Log("No stopped/failed jobs found");
1204
+ throw new Error("No STOPPED/FAILED jobs found");
1205
+ case 6:
1206
+ this.Log("Resuming file upload job: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
1207
+ if (encryption === "cgck") {
1208
+ defaults.encryption = {
1209
+ scheme: "cgck"
1210
+ };
1211
+ }
1212
+ body = {
1213
+ seq: 0,
1214
+ seq_complete: true,
1215
+ clear_resolve: true,
1216
+ defaults: defaults,
1217
+ ops: ops
1218
+ }; // resume and change jobId status from 'STOPPED' to 'IN_PROGRESS'
1219
+ responses = [];
1220
+ this.Log("Stopped or Failed job IDs: ".concat(stoppedOrFailedJobIds.join(",")));
1221
+ _iterator3 = _createForOfIteratorHelper(stoppedOrFailedJobIds);
1222
+ _context19.prev = 12;
1223
+ _iterator3.s();
1224
+ case 14:
1225
+ if ((_step3 = _iterator3.n()).done) {
1226
+ _context19.next = 30;
1227
+ break;
1228
+ }
1229
+ jobId = _step3.value;
1230
+ path = UrlJoin("q", writeToken, "file_jobs", jobId, "resume");
1231
+ _context19.t0 = this.HttpClient;
1232
+ _context19.next = 20;
1233
+ return this.authClient.AuthorizationHeader({
1234
+ libraryId: libraryId,
1235
+ objectId: objectId,
1236
+ update: true,
1237
+ encryption: encryption
1238
+ });
1239
+ case 20:
1240
+ _context19.t1 = _context19.sent;
1241
+ _context19.t2 = path;
1242
+ _context19.t3 = body;
1243
+ _context19.t4 = {
1244
+ headers: _context19.t1,
1245
+ method: "PUT",
1246
+ path: _context19.t2,
1247
+ body: _context19.t3,
1248
+ allowFailover: false
1249
+ };
1250
+ _context19.next = 26;
1251
+ return _context19.t0.RequestJsonBody.call(_context19.t0, _context19.t4);
1252
+ case 26:
1253
+ res = _context19.sent;
1254
+ responses.push({
1255
+ message: res,
1256
+ id: jobId
1257
+ });
1258
+ case 28:
1259
+ _context19.next = 14;
1260
+ break;
1261
+ case 30:
1262
+ _context19.next = 35;
1263
+ break;
1264
+ case 32:
1265
+ _context19.prev = 32;
1266
+ _context19.t5 = _context19["catch"](12);
1267
+ _iterator3.e(_context19.t5);
1268
+ case 35:
1269
+ _context19.prev = 35;
1270
+ _iterator3.f();
1271
+ return _context19.finish(35);
1272
+ case 38:
1273
+ return _context19.abrupt("return", responses);
1274
+ case 39:
1275
+ case "end":
1276
+ return _context19.stop();
728
1277
  }
729
- }, _callee7, this);
1278
+ }, _callee17, this, [[12, 32, 35, 38]]);
730
1279
  }));
731
- return function (_x8) {
732
- return _ref11.apply(this, arguments);
1280
+ return function (_x18) {
1281
+ return _ref30.apply(this, arguments);
733
1282
  };
734
1283
  }();
735
1284
  exports.UploadStatus = /*#__PURE__*/function () {
736
- var _ref13 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(_ref12) {
1285
+ var _ref32 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee18(_ref31) {
737
1286
  var libraryId, objectId, writeToken, uploadId, path;
738
- return _regeneratorRuntime.wrap(function _callee8$(_context9) {
739
- while (1) switch (_context9.prev = _context9.next) {
1287
+ return _regeneratorRuntime.wrap(function _callee18$(_context20) {
1288
+ while (1) switch (_context20.prev = _context20.next) {
740
1289
  case 0:
741
- libraryId = _ref12.libraryId, objectId = _ref12.objectId, writeToken = _ref12.writeToken, uploadId = _ref12.uploadId;
1290
+ libraryId = _ref31.libraryId, objectId = _ref31.objectId, writeToken = _ref31.writeToken, uploadId = _ref31.uploadId;
742
1291
  ValidateParameters({
743
1292
  libraryId: libraryId,
744
1293
  objectId: objectId
745
1294
  });
746
1295
  ValidateWriteToken(writeToken);
747
1296
  path = UrlJoin("q", writeToken, "file_jobs", uploadId);
748
- _context9.t0 = this.utils;
749
- _context9.t1 = this.HttpClient;
750
- _context9.next = 8;
1297
+ _context20.t0 = this.utils;
1298
+ _context20.t1 = this.HttpClient;
1299
+ _context20.next = 8;
751
1300
  return this.authClient.AuthorizationHeader({
752
1301
  libraryId: libraryId,
753
1302
  objectId: objectId,
754
1303
  update: true
755
1304
  });
756
1305
  case 8:
757
- _context9.t2 = _context9.sent;
758
- _context9.t3 = path;
759
- _context9.t4 = {
760
- headers: _context9.t2,
1306
+ _context20.t2 = _context20.sent;
1307
+ _context20.t3 = path;
1308
+ _context20.t4 = {
1309
+ headers: _context20.t2,
761
1310
  method: "GET",
762
- path: _context9.t3,
1311
+ path: _context20.t3,
763
1312
  allowFailover: false
764
1313
  };
765
- _context9.t5 = _context9.t1.Request.call(_context9.t1, _context9.t4);
766
- return _context9.abrupt("return", _context9.t0.ResponseToJson.call(_context9.t0, _context9.t5));
1314
+ _context20.t5 = _context20.t1.Request.call(_context20.t1, _context20.t4);
1315
+ return _context20.abrupt("return", _context20.t0.ResponseToJson.call(_context20.t0, _context20.t5));
767
1316
  case 13:
768
1317
  case "end":
769
- return _context9.stop();
1318
+ return _context20.stop();
770
1319
  }
771
- }, _callee8, this);
1320
+ }, _callee18, this);
772
1321
  }));
773
- return function (_x9) {
774
- return _ref13.apply(this, arguments);
1322
+ return function (_x19) {
1323
+ return _ref32.apply(this, arguments);
775
1324
  };
776
1325
  }();
777
1326
  exports.UploadJobStatus = /*#__PURE__*/function () {
778
- var _ref15 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(_ref14) {
1327
+ var _ref34 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee19(_ref33) {
779
1328
  var libraryId, objectId, writeToken, uploadId, jobId, path, response, newResponse;
780
- return _regeneratorRuntime.wrap(function _callee9$(_context10) {
781
- while (1) switch (_context10.prev = _context10.next) {
1329
+ return _regeneratorRuntime.wrap(function _callee19$(_context21) {
1330
+ while (1) switch (_context21.prev = _context21.next) {
782
1331
  case 0:
783
- libraryId = _ref14.libraryId, objectId = _ref14.objectId, writeToken = _ref14.writeToken, uploadId = _ref14.uploadId, jobId = _ref14.jobId;
1332
+ libraryId = _ref33.libraryId, objectId = _ref33.objectId, writeToken = _ref33.writeToken, uploadId = _ref33.uploadId, jobId = _ref33.jobId;
784
1333
  ValidateParameters({
785
1334
  libraryId: libraryId,
786
1335
  objectId: objectId
787
1336
  });
788
1337
  ValidateWriteToken(writeToken);
789
1338
  path = UrlJoin("q", writeToken, "file_jobs", uploadId, "uploads", jobId);
790
- _context10.t0 = this.utils;
791
- _context10.t1 = this.HttpClient;
792
- _context10.next = 8;
1339
+ _context21.t0 = this.utils;
1340
+ _context21.t1 = this.HttpClient;
1341
+ _context21.next = 8;
793
1342
  return this.authClient.AuthorizationHeader({
794
1343
  libraryId: libraryId,
795
1344
  objectId: objectId,
796
1345
  update: true
797
1346
  });
798
1347
  case 8:
799
- _context10.t2 = _context10.sent;
800
- _context10.t3 = path;
801
- _context10.t4 = {
1348
+ _context21.t2 = _context21.sent;
1349
+ _context21.t3 = path;
1350
+ _context21.t4 = {
802
1351
  start: 0,
803
1352
  limit: 10000
804
1353
  };
805
- _context10.t5 = {
806
- headers: _context10.t2,
1354
+ _context21.t5 = {
1355
+ headers: _context21.t2,
807
1356
  method: "GET",
808
- path: _context10.t3,
1357
+ path: _context21.t3,
809
1358
  allowFailover: false,
810
- queryParams: _context10.t4
1359
+ queryParams: _context21.t4
811
1360
  };
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);
1361
+ _context21.t6 = _context21.t1.Request.call(_context21.t1, _context21.t5);
1362
+ _context21.next = 15;
1363
+ return _context21.t0.ResponseToJson.call(_context21.t0, _context21.t6);
815
1364
  case 15:
816
- response = _context10.sent;
1365
+ response = _context21.sent;
817
1366
  case 16:
818
1367
  if (!(response.next !== response.total && response.next >= 0)) {
819
- _context10.next = 33;
1368
+ _context21.next = 33;
820
1369
  break;
821
1370
  }
822
- _context10.t7 = this.utils;
823
- _context10.t8 = this.HttpClient;
824
- _context10.next = 21;
1371
+ _context21.t7 = this.utils;
1372
+ _context21.t8 = this.HttpClient;
1373
+ _context21.next = 21;
825
1374
  return this.authClient.AuthorizationHeader({
826
1375
  libraryId: libraryId,
827
1376
  objectId: objectId,
828
1377
  update: true
829
1378
  });
830
1379
  case 21:
831
- _context10.t9 = _context10.sent;
832
- _context10.t10 = path;
833
- _context10.t11 = {
1380
+ _context21.t9 = _context21.sent;
1381
+ _context21.t10 = path;
1382
+ _context21.t11 = {
834
1383
  start: response.next
835
1384
  };
836
- _context10.t12 = {
837
- headers: _context10.t9,
1385
+ _context21.t12 = {
1386
+ headers: _context21.t9,
838
1387
  method: "GET",
839
- path: _context10.t10,
1388
+ path: _context21.t10,
840
1389
  allowFailover: false,
841
- queryParams: _context10.t11
1390
+ queryParams: _context21.t11
842
1391
  };
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);
1392
+ _context21.t13 = _context21.t8.Request.call(_context21.t8, _context21.t12);
1393
+ _context21.next = 28;
1394
+ return _context21.t7.ResponseToJson.call(_context21.t7, _context21.t13);
846
1395
  case 28:
847
- newResponse = _context10.sent;
1396
+ newResponse = _context21.sent;
848
1397
  response.files = [].concat(_toConsumableArray(response.files), _toConsumableArray(newResponse.files));
849
1398
  response.next = newResponse.next;
850
- _context10.next = 16;
1399
+ _context21.next = 16;
851
1400
  break;
852
1401
  case 33:
853
- return _context10.abrupt("return", response);
1402
+ return _context21.abrupt("return", response);
854
1403
  case 34:
855
1404
  case "end":
856
- return _context10.stop();
1405
+ return _context21.stop();
857
1406
  }
858
- }, _callee9, this);
1407
+ }, _callee19, this);
859
1408
  }));
860
- return function (_x10) {
861
- return _ref15.apply(this, arguments);
1409
+ return function (_x20) {
1410
+ return _ref34.apply(this, arguments);
862
1411
  };
863
1412
  }();
864
1413
  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) {
1414
+ var _ref36 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20(_ref35) {
1415
+ var libraryId, objectId, writeToken, encryption, uploadId, jobId, filePath, fileData, jobStatus, fileStatus, path, response;
1416
+ return _regeneratorRuntime.wrap(function _callee20$(_context22) {
1417
+ while (1) switch (_context22.prev = _context22.next) {
869
1418
  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;
1419
+ libraryId = _ref35.libraryId, objectId = _ref35.objectId, writeToken = _ref35.writeToken, encryption = _ref35.encryption, uploadId = _ref35.uploadId, jobId = _ref35.jobId, filePath = _ref35.filePath, fileData = _ref35.fileData;
871
1420
  ValidateParameters({
872
1421
  libraryId: libraryId,
873
1422
  objectId: objectId
874
1423
  });
875
1424
  ValidateWriteToken(writeToken);
876
- _context11.next = 5;
1425
+ _context22.next = 5;
877
1426
  return this.UploadJobStatus({
878
1427
  libraryId: libraryId,
879
1428
  objectId: objectId,
@@ -882,7 +1431,7 @@ exports.UploadFileData = /*#__PURE__*/function () {
882
1431
  jobId: jobId
883
1432
  });
884
1433
  case 5:
885
- jobStatus = _context11.sent;
1434
+ jobStatus = _context22.sent;
886
1435
  // Find the status of this file
887
1436
  fileStatus = jobStatus.files.find(function (item) {
888
1437
  return item.path === filePath;
@@ -891,64 +1440,71 @@ exports.UploadFileData = /*#__PURE__*/function () {
891
1440
  fileStatus = fileStatus.encrypted;
892
1441
  }
893
1442
  if (!(fileStatus.rem === 0)) {
894
- _context11.next = 12;
1443
+ _context22.next = 12;
895
1444
  break;
896
1445
  }
897
- return _context11.abrupt("return");
1446
+ return _context22.abrupt("return");
898
1447
  case 12:
899
1448
  if (fileStatus.skip) {
900
1449
  fileData = fileData.slice(fileStatus.skip);
901
1450
  }
902
1451
  case 13:
903
1452
  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 = {
1453
+ _context22.t0 = this.utils;
1454
+ _context22.t1 = this.HttpClient;
1455
+ _context22.t2 = path;
1456
+ _context22.t3 = fileData;
1457
+ _context22.t4 = _objectSpread;
1458
+ _context22.t5 = {
910
1459
  "Content-type": "application/octet-stream"
911
1460
  };
912
- _context11.next = 22;
1461
+ _context22.next = 22;
913
1462
  return this.authClient.AuthorizationHeader({
914
1463
  libraryId: libraryId,
915
1464
  objectId: objectId,
916
1465
  update: true
917
1466
  });
918
1467
  case 22:
919
- _context11.t6 = _context11.sent;
920
- _context11.t7 = (0, _context11.t4)(_context11.t5, _context11.t6);
921
- _context11.t8 = {
1468
+ _context22.t6 = _context22.sent;
1469
+ _context22.t7 = (0, _context22.t4)(_context22.t5, _context22.t6);
1470
+ _context22.t8 = {
922
1471
  method: "POST",
923
- path: _context11.t2,
924
- body: _context11.t3,
1472
+ path: _context22.t2,
1473
+ body: _context22.t3,
925
1474
  bodyType: "BINARY",
926
- headers: _context11.t7,
1475
+ headers: _context22.t7,
927
1476
  allowFailover: false,
928
1477
  allowRetry: false
929
1478
  };
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);
1479
+ _context22.t9 = _context22.t1.Request.call(_context22.t1, _context22.t8);
1480
+ _context22.next = 28;
1481
+ return _context22.t0.ResponseToJson.call(_context22.t0, _context22.t9);
933
1482
  case 28:
934
- return _context11.abrupt("return", _context11.sent);
935
- case 29:
1483
+ response = _context22.sent;
1484
+ if (!(response && response.part && !response.part.hash)) {
1485
+ _context22.next = 31;
1486
+ break;
1487
+ }
1488
+ throw new Error("Upload did not finalize part for ".concat(filePath, " (job ").concat(jobId, ")"));
1489
+ case 31:
1490
+ return _context22.abrupt("return", response);
1491
+ case 32:
936
1492
  case "end":
937
- return _context11.stop();
1493
+ return _context22.stop();
938
1494
  }
939
- }, _callee10, this);
1495
+ }, _callee20, this);
940
1496
  }));
941
- return function (_x11) {
942
- return _ref17.apply(this, arguments);
1497
+ return function (_x21) {
1498
+ return _ref36.apply(this, arguments);
943
1499
  };
944
1500
  }();
945
1501
  exports.FinalizeUploadJob = /*#__PURE__*/function () {
946
- var _ref19 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(_ref18) {
1502
+ var _ref38 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee21(_ref37) {
947
1503
  var libraryId, objectId, writeToken, path;
948
- return _regeneratorRuntime.wrap(function _callee11$(_context12) {
949
- while (1) switch (_context12.prev = _context12.next) {
1504
+ return _regeneratorRuntime.wrap(function _callee21$(_context23) {
1505
+ while (1) switch (_context23.prev = _context23.next) {
950
1506
  case 0:
951
- libraryId = _ref18.libraryId, objectId = _ref18.objectId, writeToken = _ref18.writeToken;
1507
+ libraryId = _ref37.libraryId, objectId = _ref37.objectId, writeToken = _ref37.writeToken;
952
1508
  ValidateParameters({
953
1509
  libraryId: libraryId,
954
1510
  objectId: objectId
@@ -956,33 +1512,33 @@ exports.FinalizeUploadJob = /*#__PURE__*/function () {
956
1512
  ValidateWriteToken(writeToken);
957
1513
  this.Log("Finalizing upload job: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
958
1514
  path = UrlJoin("q", writeToken, "files");
959
- _context12.t0 = this.HttpClient;
960
- _context12.t1 = path;
961
- _context12.next = 9;
1515
+ _context23.t0 = this.HttpClient;
1516
+ _context23.t1 = path;
1517
+ _context23.next = 9;
962
1518
  return this.authClient.AuthorizationHeader({
963
1519
  libraryId: libraryId,
964
1520
  objectId: objectId,
965
1521
  update: true
966
1522
  });
967
1523
  case 9:
968
- _context12.t2 = _context12.sent;
969
- _context12.t3 = {
1524
+ _context23.t2 = _context23.sent;
1525
+ _context23.t3 = {
970
1526
  method: "POST",
971
- path: _context12.t1,
1527
+ path: _context23.t1,
972
1528
  bodyType: "BINARY",
973
- headers: _context12.t2,
1529
+ headers: _context23.t2,
974
1530
  allowFailover: false
975
1531
  };
976
- _context12.next = 13;
977
- return _context12.t0.Request.call(_context12.t0, _context12.t3);
1532
+ _context23.next = 13;
1533
+ return _context23.t0.Request.call(_context23.t0, _context23.t3);
978
1534
  case 13:
979
1535
  case "end":
980
- return _context12.stop();
1536
+ return _context23.stop();
981
1537
  }
982
- }, _callee11, this);
1538
+ }, _callee21, this);
983
1539
  }));
984
- return function (_x12) {
985
- return _ref19.apply(this, arguments);
1540
+ return function (_x22) {
1541
+ return _ref38.apply(this, arguments);
986
1542
  };
987
1543
  }();
988
1544
 
@@ -998,12 +1554,12 @@ exports.FinalizeUploadJob = /*#__PURE__*/function () {
998
1554
  * @param {Array<string>} filePaths - List of file paths to create
999
1555
  */
1000
1556
  exports.CreateFileDirectories = /*#__PURE__*/function () {
1001
- var _ref21 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(_ref20) {
1557
+ var _ref40 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22(_ref39) {
1002
1558
  var libraryId, objectId, writeToken, filePaths, ops;
1003
- return _regeneratorRuntime.wrap(function _callee12$(_context13) {
1004
- while (1) switch (_context13.prev = _context13.next) {
1559
+ return _regeneratorRuntime.wrap(function _callee22$(_context24) {
1560
+ while (1) switch (_context24.prev = _context24.next) {
1005
1561
  case 0:
1006
- libraryId = _ref20.libraryId, objectId = _ref20.objectId, writeToken = _ref20.writeToken, filePaths = _ref20.filePaths;
1562
+ libraryId = _ref39.libraryId, objectId = _ref39.objectId, writeToken = _ref39.writeToken, filePaths = _ref39.filePaths;
1007
1563
  ValidateParameters({
1008
1564
  libraryId: libraryId,
1009
1565
  objectId: objectId
@@ -1018,7 +1574,7 @@ exports.CreateFileDirectories = /*#__PURE__*/function () {
1018
1574
  path: path
1019
1575
  };
1020
1576
  });
1021
- _context13.next = 8;
1577
+ _context24.next = 8;
1022
1578
  return this.CreateFileUploadJob({
1023
1579
  libraryId: libraryId,
1024
1580
  objectId: objectId,
@@ -1027,12 +1583,12 @@ exports.CreateFileDirectories = /*#__PURE__*/function () {
1027
1583
  });
1028
1584
  case 8:
1029
1585
  case "end":
1030
- return _context13.stop();
1586
+ return _context24.stop();
1031
1587
  }
1032
- }, _callee12, this);
1588
+ }, _callee22, this);
1033
1589
  }));
1034
- return function (_x13) {
1035
- return _ref21.apply(this, arguments);
1590
+ return function (_x23) {
1591
+ return _ref40.apply(this, arguments);
1036
1592
  };
1037
1593
  }();
1038
1594
 
@@ -1048,12 +1604,12 @@ exports.CreateFileDirectories = /*#__PURE__*/function () {
1048
1604
  * @param {Array<string>} filePaths - List of file paths to move. Format: ```[ { "path": "original/path", to: "new/path" } ]```
1049
1605
  */
1050
1606
  exports.MoveFiles = /*#__PURE__*/function () {
1051
- var _ref23 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(_ref22) {
1607
+ var _ref42 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee23(_ref41) {
1052
1608
  var libraryId, objectId, writeToken, filePaths, ops;
1053
- return _regeneratorRuntime.wrap(function _callee13$(_context14) {
1054
- while (1) switch (_context14.prev = _context14.next) {
1609
+ return _regeneratorRuntime.wrap(function _callee23$(_context25) {
1610
+ while (1) switch (_context25.prev = _context25.next) {
1055
1611
  case 0:
1056
- libraryId = _ref22.libraryId, objectId = _ref22.objectId, writeToken = _ref22.writeToken, filePaths = _ref22.filePaths;
1612
+ libraryId = _ref41.libraryId, objectId = _ref41.objectId, writeToken = _ref41.writeToken, filePaths = _ref41.filePaths;
1057
1613
  ValidateParameters({
1058
1614
  libraryId: libraryId,
1059
1615
  objectId: objectId
@@ -1061,16 +1617,16 @@ exports.MoveFiles = /*#__PURE__*/function () {
1061
1617
  ValidateWriteToken(writeToken);
1062
1618
  this.Log("Moving Files: ".concat(libraryId, " ").concat(objectId, " ").concat(writeToken));
1063
1619
  this.Log(filePaths);
1064
- ops = filePaths.map(function (_ref24) {
1065
- var path = _ref24.path,
1066
- to = _ref24.to;
1620
+ ops = filePaths.map(function (_ref43) {
1621
+ var path = _ref43.path,
1622
+ to = _ref43.to;
1067
1623
  return {
1068
1624
  op: "move",
1069
1625
  copy_move_source_path: path,
1070
1626
  path: to
1071
1627
  };
1072
1628
  });
1073
- _context14.next = 8;
1629
+ _context25.next = 8;
1074
1630
  return this.CreateFileUploadJob({
1075
1631
  libraryId: libraryId,
1076
1632
  objectId: objectId,
@@ -1079,12 +1635,12 @@ exports.MoveFiles = /*#__PURE__*/function () {
1079
1635
  });
1080
1636
  case 8:
1081
1637
  case "end":
1082
- return _context14.stop();
1638
+ return _context25.stop();
1083
1639
  }
1084
- }, _callee13, this);
1640
+ }, _callee23, this);
1085
1641
  }));
1086
- return function (_x14) {
1087
- return _ref23.apply(this, arguments);
1642
+ return function (_x24) {
1643
+ return _ref42.apply(this, arguments);
1088
1644
  };
1089
1645
  }();
1090
1646
 
@@ -1100,12 +1656,12 @@ exports.MoveFiles = /*#__PURE__*/function () {
1100
1656
  * @param {Array<string>} filePaths - List of file paths to delete
1101
1657
  */
1102
1658
  exports.DeleteFiles = /*#__PURE__*/function () {
1103
- var _ref26 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(_ref25) {
1659
+ var _ref45 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee24(_ref44) {
1104
1660
  var libraryId, objectId, writeToken, filePaths, ops;
1105
- return _regeneratorRuntime.wrap(function _callee14$(_context15) {
1106
- while (1) switch (_context15.prev = _context15.next) {
1661
+ return _regeneratorRuntime.wrap(function _callee24$(_context26) {
1662
+ while (1) switch (_context26.prev = _context26.next) {
1107
1663
  case 0:
1108
- libraryId = _ref25.libraryId, objectId = _ref25.objectId, writeToken = _ref25.writeToken, filePaths = _ref25.filePaths;
1664
+ libraryId = _ref44.libraryId, objectId = _ref44.objectId, writeToken = _ref44.writeToken, filePaths = _ref44.filePaths;
1109
1665
  ValidateParameters({
1110
1666
  libraryId: libraryId,
1111
1667
  objectId: objectId
@@ -1119,7 +1675,7 @@ exports.DeleteFiles = /*#__PURE__*/function () {
1119
1675
  path: path
1120
1676
  };
1121
1677
  });
1122
- _context15.next = 8;
1678
+ _context26.next = 8;
1123
1679
  return this.CreateFileUploadJob({
1124
1680
  libraryId: libraryId,
1125
1681
  objectId: objectId,
@@ -1128,12 +1684,12 @@ exports.DeleteFiles = /*#__PURE__*/function () {
1128
1684
  });
1129
1685
  case 8:
1130
1686
  case "end":
1131
- return _context15.stop();
1687
+ return _context26.stop();
1132
1688
  }
1133
- }, _callee14, this);
1689
+ }, _callee24, this);
1134
1690
  }));
1135
- return function (_x15) {
1136
- return _ref26.apply(this, arguments);
1691
+ return function (_x25) {
1692
+ return _ref45.apply(this, arguments);
1137
1693
  };
1138
1694
  }();
1139
1695
 
@@ -1162,18 +1718,18 @@ exports.DeleteFiles = /*#__PURE__*/function () {
1162
1718
  * @returns {Promise<ArrayBuffer> | undefined} - No return if chunked is specified, file data in the requested format otherwise
1163
1719
  */
1164
1720
  exports.DownloadFile = /*#__PURE__*/function () {
1165
- var _ref28 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15(_ref27) {
1721
+ var _ref47 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee25(_ref46) {
1166
1722
  var libraryId,
1167
1723
  objectId,
1168
1724
  versionHash,
1169
1725
  writeToken,
1170
1726
  filePath,
1171
- _ref27$format,
1727
+ _ref46$format,
1172
1728
  format,
1173
- _ref27$chunked,
1729
+ _ref46$chunked,
1174
1730
  chunked,
1175
1731
  chunkSize,
1176
- _ref27$clientSideDecr,
1732
+ _ref46$clientSideDecr,
1177
1733
  clientSideDecryption,
1178
1734
  callback,
1179
1735
  fileInfo,
@@ -1184,11 +1740,11 @@ exports.DownloadFile = /*#__PURE__*/function () {
1184
1740
  ownerCapKey,
1185
1741
  ownerCap,
1186
1742
  bytesTotal,
1187
- _args16 = arguments;
1188
- return _regeneratorRuntime.wrap(function _callee15$(_context16) {
1189
- while (1) switch (_context16.prev = _context16.next) {
1743
+ _args27 = arguments;
1744
+ return _regeneratorRuntime.wrap(function _callee25$(_context27) {
1745
+ while (1) switch (_context27.prev = _context27.next) {
1190
1746
  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;
1747
+ libraryId = _ref46.libraryId, objectId = _ref46.objectId, versionHash = _ref46.versionHash, writeToken = _ref46.writeToken, filePath = _ref46.filePath, _ref46$format = _ref46.format, format = _ref46$format === void 0 ? "arrayBuffer" : _ref46$format, _ref46$chunked = _ref46.chunked, chunked = _ref46$chunked === void 0 ? false : _ref46$chunked, chunkSize = _ref46.chunkSize, _ref46$clientSideDecr = _ref46.clientSideDecryption, clientSideDecryption = _ref46$clientSideDecr === void 0 ? false : _ref46$clientSideDecr, callback = _ref46.callback;
1192
1748
  ValidateParameters({
1193
1749
  libraryId: libraryId,
1194
1750
  objectId: objectId,
@@ -1198,7 +1754,7 @@ exports.DownloadFile = /*#__PURE__*/function () {
1198
1754
  if (versionHash) {
1199
1755
  objectId = this.utils.DecodeVersionHash(versionHash).objectId;
1200
1756
  }
1201
- _context16.next = 6;
1757
+ _context27.next = 6;
1202
1758
  return this.ContentObjectMetadata({
1203
1759
  libraryId: libraryId,
1204
1760
  objectId: objectId,
@@ -1207,11 +1763,11 @@ exports.DownloadFile = /*#__PURE__*/function () {
1207
1763
  metadataSubtree: UrlJoin("files", filePath)
1208
1764
  });
1209
1765
  case 6:
1210
- fileInfo = _context16.sent;
1766
+ fileInfo = _context27.sent;
1211
1767
  encrypted = fileInfo && fileInfo["."].encryption && fileInfo["."].encryption.scheme === "cgck";
1212
1768
  encryption = encrypted ? "cgck" : undefined;
1213
1769
  path = encrypted && !clientSideDecryption ? UrlJoin("q", writeToken || versionHash || objectId, "rep", "files_download", filePath) : UrlJoin("q", writeToken || versionHash || objectId, "files", filePath);
1214
- _context16.next = 12;
1770
+ _context27.next = 12;
1215
1771
  return this.authClient.AuthorizationHeader({
1216
1772
  libraryId: libraryId,
1217
1773
  objectId: objectId,
@@ -1220,12 +1776,12 @@ exports.DownloadFile = /*#__PURE__*/function () {
1220
1776
  makeAccessRequest: encryption === "cgck"
1221
1777
  });
1222
1778
  case 12:
1223
- headers = _context16.sent;
1779
+ headers = _context27.sent;
1224
1780
  headers.Accept = "*/*";
1225
1781
 
1226
1782
  // If not owner, indicate re-encryption
1227
1783
  ownerCapKey = "eluv.caps.iusr".concat(this.utils.AddressToHash(this.signer.address));
1228
- _context16.next = 17;
1784
+ _context27.next = 17;
1229
1785
  return this.ContentObjectMetadata({
1230
1786
  libraryId: libraryId,
1231
1787
  objectId: objectId,
@@ -1233,31 +1789,31 @@ exports.DownloadFile = /*#__PURE__*/function () {
1233
1789
  metadataSubtree: ownerCapKey
1234
1790
  });
1235
1791
  case 17:
1236
- ownerCap = _context16.sent;
1237
- _context16.t1 = encrypted;
1238
- if (!_context16.t1) {
1239
- _context16.next = 26;
1792
+ ownerCap = _context27.sent;
1793
+ _context27.t1 = encrypted;
1794
+ if (!_context27.t1) {
1795
+ _context27.next = 26;
1240
1796
  break;
1241
1797
  }
1242
- _context16.t2 = this.utils;
1243
- _context16.t3 = this.signer.address;
1244
- _context16.next = 24;
1798
+ _context27.t2 = this.utils;
1799
+ _context27.t3 = this.signer.address;
1800
+ _context27.next = 24;
1245
1801
  return this.ContentObjectOwner({
1246
1802
  objectId: objectId
1247
1803
  });
1248
1804
  case 24:
1249
- _context16.t4 = _context16.sent;
1250
- _context16.t1 = !_context16.t2.EqualAddress.call(_context16.t2, _context16.t3, _context16.t4);
1805
+ _context27.t4 = _context27.sent;
1806
+ _context27.t1 = !_context27.t2.EqualAddress.call(_context27.t2, _context27.t3, _context27.t4);
1251
1807
  case 26:
1252
- _context16.t0 = _context16.t1;
1253
- if (!_context16.t0) {
1254
- _context16.next = 29;
1808
+ _context27.t0 = _context27.t1;
1809
+ if (!_context27.t0) {
1810
+ _context27.next = 29;
1255
1811
  break;
1256
1812
  }
1257
- _context16.t0 = !ownerCap;
1813
+ _context27.t0 = !ownerCap;
1258
1814
  case 29:
1259
- if (!_context16.t0) {
1260
- _context16.next = 31;
1815
+ if (!_context27.t0) {
1816
+ _context27.next = 31;
1261
1817
  break;
1262
1818
  }
1263
1819
  headers["X-Content-Fabric-Decryption-Mode"] = "reencrypt";
@@ -1270,11 +1826,11 @@ exports.DownloadFile = /*#__PURE__*/function () {
1270
1826
  }
1271
1827
  bytesTotal = fileInfo["."].size;
1272
1828
  if (!(encrypted && clientSideDecryption)) {
1273
- _context16.next = 51;
1829
+ _context27.next = 51;
1274
1830
  break;
1275
1831
  }
1276
- _context16.t5 = this;
1277
- _context16.next = 37;
1832
+ _context27.t5 = this;
1833
+ _context27.next = 37;
1278
1834
  return this.EncryptionConk({
1279
1835
  libraryId: libraryId,
1280
1836
  objectId: objectId,
@@ -1282,34 +1838,34 @@ exports.DownloadFile = /*#__PURE__*/function () {
1282
1838
  download: true
1283
1839
  });
1284
1840
  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
1841
+ _context27.t6 = _context27.sent;
1842
+ _context27.t7 = path;
1843
+ _context27.t8 = bytesTotal;
1844
+ _context27.t9 = headers;
1845
+ _context27.t10 = callback;
1846
+ _context27.t11 = format;
1847
+ _context27.t12 = clientSideDecryption;
1848
+ _context27.t13 = chunked;
1849
+ _context27.t14 = {
1850
+ conk: _context27.t6,
1851
+ downloadPath: _context27.t7,
1852
+ bytesTotal: _context27.t8,
1853
+ headers: _context27.t9,
1854
+ callback: _context27.t10,
1855
+ format: _context27.t11,
1856
+ clientSideDecryption: _context27.t12,
1857
+ chunked: _context27.t13
1302
1858
  };
1303
- _context16.next = 48;
1304
- return _context16.t5.DownloadEncrypted.call(_context16.t5, _context16.t14);
1859
+ _context27.next = 48;
1860
+ return _context27.t5.DownloadEncrypted.call(_context27.t5, _context27.t14);
1305
1861
  case 48:
1306
- return _context16.abrupt("return", _context16.sent);
1862
+ return _context27.abrupt("return", _context27.sent);
1307
1863
  case 51:
1308
1864
  if (!chunkSize) {
1309
1865
  chunkSize = 10000000;
1310
1866
  }
1311
- _context16.prev = 52;
1312
- _context16.next = 55;
1867
+ _context27.prev = 52;
1868
+ _context27.next = 55;
1313
1869
  return this.Download({
1314
1870
  downloadPath: path,
1315
1871
  bytesTotal: bytesTotal,
@@ -1320,27 +1876,27 @@ exports.DownloadFile = /*#__PURE__*/function () {
1320
1876
  chunkSize: chunkSize
1321
1877
  });
1322
1878
  case 55:
1323
- return _context16.abrupt("return", _context16.sent);
1879
+ return _context27.abrupt("return", _context27.sent);
1324
1880
  case 58:
1325
- _context16.prev = 58;
1326
- _context16.t15 = _context16["catch"](52);
1881
+ _context27.prev = 58;
1882
+ _context27.t15 = _context27["catch"](52);
1327
1883
  if (!(encrypted && !clientSideDecryption)) {
1328
- _context16.next = 62;
1884
+ _context27.next = 62;
1329
1885
  break;
1330
1886
  }
1331
- return _context16.abrupt("return", this.DownloadFile(_objectSpread(_objectSpread({}, _args16[0]), {}, {
1887
+ return _context27.abrupt("return", this.DownloadFile(_objectSpread(_objectSpread({}, _args27[0]), {}, {
1332
1888
  clientSideDecryption: true
1333
1889
  })));
1334
1890
  case 62:
1335
- throw _context16.t15;
1891
+ throw _context27.t15;
1336
1892
  case 63:
1337
1893
  case "end":
1338
- return _context16.stop();
1894
+ return _context27.stop();
1339
1895
  }
1340
- }, _callee15, this, [[52, 58]]);
1896
+ }, _callee25, this, [[52, 58]]);
1341
1897
  }));
1342
- return function (_x16) {
1343
- return _ref28.apply(this, arguments);
1898
+ return function (_x26) {
1899
+ return _ref47.apply(this, arguments);
1344
1900
  };
1345
1901
  }();
1346
1902
 
@@ -1359,12 +1915,12 @@ exports.DownloadFile = /*#__PURE__*/function () {
1359
1915
  * @returns {Promise<Object>} - Response containing list of parts of the object
1360
1916
  */
1361
1917
  exports.ContentParts = /*#__PURE__*/function () {
1362
- var _ref30 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16(_ref29) {
1918
+ var _ref49 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee26(_ref48) {
1363
1919
  var libraryId, objectId, versionHash, path, response;
1364
- return _regeneratorRuntime.wrap(function _callee16$(_context17) {
1365
- while (1) switch (_context17.prev = _context17.next) {
1920
+ return _regeneratorRuntime.wrap(function _callee26$(_context28) {
1921
+ while (1) switch (_context28.prev = _context28.next) {
1366
1922
  case 0:
1367
- libraryId = _ref29.libraryId, objectId = _ref29.objectId, versionHash = _ref29.versionHash;
1923
+ libraryId = _ref48.libraryId, objectId = _ref48.objectId, versionHash = _ref48.versionHash;
1368
1924
  ValidateParameters({
1369
1925
  libraryId: libraryId,
1370
1926
  objectId: objectId,
@@ -1375,34 +1931,34 @@ exports.ContentParts = /*#__PURE__*/function () {
1375
1931
  objectId = this.utils.DecodeVersionHash(versionHash).objectId;
1376
1932
  }
1377
1933
  path = UrlJoin("q", versionHash || objectId, "parts");
1378
- _context17.t0 = this.HttpClient;
1379
- _context17.next = 8;
1934
+ _context28.t0 = this.HttpClient;
1935
+ _context28.next = 8;
1380
1936
  return this.authClient.AuthorizationHeader({
1381
1937
  libraryId: libraryId,
1382
1938
  objectId: objectId,
1383
1939
  versionHash: versionHash
1384
1940
  });
1385
1941
  case 8:
1386
- _context17.t1 = _context17.sent;
1387
- _context17.t2 = path;
1388
- _context17.t3 = {
1389
- headers: _context17.t1,
1942
+ _context28.t1 = _context28.sent;
1943
+ _context28.t2 = path;
1944
+ _context28.t3 = {
1945
+ headers: _context28.t1,
1390
1946
  method: "GET",
1391
- path: _context17.t2
1947
+ path: _context28.t2
1392
1948
  };
1393
- _context17.next = 13;
1394
- return _context17.t0.RequestJsonBody.call(_context17.t0, _context17.t3);
1949
+ _context28.next = 13;
1950
+ return _context28.t0.RequestJsonBody.call(_context28.t0, _context28.t3);
1395
1951
  case 13:
1396
- response = _context17.sent;
1397
- return _context17.abrupt("return", response.parts);
1952
+ response = _context28.sent;
1953
+ return _context28.abrupt("return", response.parts);
1398
1954
  case 15:
1399
1955
  case "end":
1400
- return _context17.stop();
1956
+ return _context28.stop();
1401
1957
  }
1402
- }, _callee16, this);
1958
+ }, _callee26, this);
1403
1959
  }));
1404
- return function (_x17) {
1405
- return _ref30.apply(this, arguments);
1960
+ return function (_x27) {
1961
+ return _ref49.apply(this, arguments);
1406
1962
  };
1407
1963
  }();
1408
1964
 
@@ -1420,12 +1976,12 @@ exports.ContentParts = /*#__PURE__*/function () {
1420
1976
  * @returns {Promise<Object>} - Response containing information about the specified part
1421
1977
  */
1422
1978
  exports.ContentPart = /*#__PURE__*/function () {
1423
- var _ref32 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee17(_ref31) {
1979
+ var _ref51 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee27(_ref50) {
1424
1980
  var libraryId, objectId, versionHash, partHash, path;
1425
- return _regeneratorRuntime.wrap(function _callee17$(_context18) {
1426
- while (1) switch (_context18.prev = _context18.next) {
1981
+ return _regeneratorRuntime.wrap(function _callee27$(_context29) {
1982
+ while (1) switch (_context29.prev = _context29.next) {
1427
1983
  case 0:
1428
- libraryId = _ref31.libraryId, objectId = _ref31.objectId, versionHash = _ref31.versionHash, partHash = _ref31.partHash;
1984
+ libraryId = _ref50.libraryId, objectId = _ref50.objectId, versionHash = _ref50.versionHash, partHash = _ref50.partHash;
1429
1985
  ValidateParameters({
1430
1986
  libraryId: libraryId,
1431
1987
  objectId: objectId,
@@ -1437,33 +1993,33 @@ exports.ContentPart = /*#__PURE__*/function () {
1437
1993
  objectId = this.utils.DecodeVersionHash(versionHash).objectId;
1438
1994
  }
1439
1995
  path = UrlJoin("q", versionHash || objectId, "parts", partHash);
1440
- _context18.t0 = this.HttpClient;
1441
- _context18.next = 9;
1996
+ _context29.t0 = this.HttpClient;
1997
+ _context29.next = 9;
1442
1998
  return this.authClient.AuthorizationHeader({
1443
1999
  libraryId: libraryId,
1444
2000
  objectId: objectId,
1445
2001
  versionHash: versionHash
1446
2002
  });
1447
2003
  case 9:
1448
- _context18.t1 = _context18.sent;
1449
- _context18.t2 = path;
1450
- _context18.t3 = {
1451
- headers: _context18.t1,
2004
+ _context29.t1 = _context29.sent;
2005
+ _context29.t2 = path;
2006
+ _context29.t3 = {
2007
+ headers: _context29.t1,
1452
2008
  method: "GET",
1453
- path: _context18.t2
2009
+ path: _context29.t2
1454
2010
  };
1455
- _context18.next = 14;
1456
- return _context18.t0.RequestJsonBody.call(_context18.t0, _context18.t3);
2011
+ _context29.next = 14;
2012
+ return _context29.t0.RequestJsonBody.call(_context29.t0, _context29.t3);
1457
2013
  case 14:
1458
- return _context18.abrupt("return", _context18.sent);
2014
+ return _context29.abrupt("return", _context29.sent);
1459
2015
  case 15:
1460
2016
  case "end":
1461
- return _context18.stop();
2017
+ return _context29.stop();
1462
2018
  }
1463
- }, _callee17, this);
2019
+ }, _callee27, this);
1464
2020
  }));
1465
- return function (_x18) {
1466
- return _ref32.apply(this, arguments);
2021
+ return function (_x28) {
2022
+ return _ref51.apply(this, arguments);
1467
2023
  };
1468
2024
  }();
1469
2025
 
@@ -1492,12 +2048,12 @@ exports.ContentPart = /*#__PURE__*/function () {
1492
2048
  * @returns {Promise<ArrayBuffer> | undefined} - No return if chunked is specified, part data in the requested format otherwise
1493
2049
  */
1494
2050
  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) {
2051
+ var _ref53 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee28(_ref52) {
2052
+ var libraryId, objectId, versionHash, writeToken, partHash, _ref52$format, format, _ref52$chunked, chunked, _ref52$chunkSize, chunkSize, callback, encrypted, encryption, path, headers, bytesTotal;
2053
+ return _regeneratorRuntime.wrap(function _callee28$(_context30) {
2054
+ while (1) switch (_context30.prev = _context30.next) {
1499
2055
  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;
2056
+ libraryId = _ref52.libraryId, objectId = _ref52.objectId, versionHash = _ref52.versionHash, writeToken = _ref52.writeToken, partHash = _ref52.partHash, _ref52$format = _ref52.format, format = _ref52$format === void 0 ? "arrayBuffer" : _ref52$format, _ref52$chunked = _ref52.chunked, chunked = _ref52$chunked === void 0 ? false : _ref52$chunked, _ref52$chunkSize = _ref52.chunkSize, chunkSize = _ref52$chunkSize === void 0 ? 10000000 : _ref52$chunkSize, callback = _ref52.callback;
1501
2057
  ValidateParameters({
1502
2058
  libraryId: libraryId,
1503
2059
  objectId: objectId,
@@ -1510,7 +2066,7 @@ exports.DownloadPart = /*#__PURE__*/function () {
1510
2066
  encrypted = partHash.startsWith("hqpe");
1511
2067
  encryption = encrypted ? "cgck" : undefined;
1512
2068
  path = UrlJoin("q", writeToken || versionHash || objectId, "data", partHash);
1513
- _context19.next = 9;
2069
+ _context30.next = 9;
1514
2070
  return this.authClient.AuthorizationHeader({
1515
2071
  libraryId: libraryId,
1516
2072
  objectId: objectId,
@@ -1519,8 +2075,8 @@ exports.DownloadPart = /*#__PURE__*/function () {
1519
2075
  makeAccessRequest: true
1520
2076
  });
1521
2077
  case 9:
1522
- headers = _context19.sent;
1523
- _context19.next = 12;
2078
+ headers = _context30.sent;
2079
+ _context30.next = 12;
1524
2080
  return this.ContentPart({
1525
2081
  libraryId: libraryId,
1526
2082
  objectId: objectId,
@@ -1528,55 +2084,55 @@ exports.DownloadPart = /*#__PURE__*/function () {
1528
2084
  partHash: partHash
1529
2085
  });
1530
2086
  case 12:
1531
- bytesTotal = _context19.sent.part.size;
2087
+ bytesTotal = _context30.sent.part.size;
1532
2088
  if (!encrypted) {
1533
- _context19.next = 37;
2089
+ _context30.next = 37;
1534
2090
  break;
1535
2091
  }
1536
- _context19.t0 = this.utils;
1537
- _context19.t1 = this.signer.address;
1538
- _context19.next = 18;
2092
+ _context30.t0 = this.utils;
2093
+ _context30.t1 = this.signer.address;
2094
+ _context30.next = 18;
1539
2095
  return this.ContentObjectOwner({
1540
2096
  objectId: objectId
1541
2097
  });
1542
2098
  case 18:
1543
- _context19.t2 = _context19.sent;
1544
- if (_context19.t0.EqualAddress.call(_context19.t0, _context19.t1, _context19.t2)) {
1545
- _context19.next = 21;
2099
+ _context30.t2 = _context30.sent;
2100
+ if (_context30.t0.EqualAddress.call(_context30.t0, _context30.t1, _context30.t2)) {
2101
+ _context30.next = 21;
1546
2102
  break;
1547
2103
  }
1548
2104
  headers["X-Content-Fabric-Decryption-Mode"] = "reencrypt";
1549
2105
  case 21:
1550
- _context19.t3 = this;
1551
- _context19.next = 24;
2106
+ _context30.t3 = this;
2107
+ _context30.next = 24;
1552
2108
  return this.EncryptionConk({
1553
2109
  libraryId: libraryId,
1554
2110
  objectId: objectId,
1555
2111
  download: true
1556
2112
  });
1557
2113
  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
2114
+ _context30.t4 = _context30.sent;
2115
+ _context30.t5 = path;
2116
+ _context30.t6 = bytesTotal;
2117
+ _context30.t7 = headers;
2118
+ _context30.t8 = callback;
2119
+ _context30.t9 = format;
2120
+ _context30.t10 = chunked;
2121
+ _context30.t11 = {
2122
+ conk: _context30.t4,
2123
+ downloadPath: _context30.t5,
2124
+ bytesTotal: _context30.t6,
2125
+ headers: _context30.t7,
2126
+ callback: _context30.t8,
2127
+ format: _context30.t9,
2128
+ chunked: _context30.t10
1573
2129
  };
1574
- _context19.next = 34;
1575
- return _context19.t3.DownloadEncrypted.call(_context19.t3, _context19.t11);
2130
+ _context30.next = 34;
2131
+ return _context30.t3.DownloadEncrypted.call(_context30.t3, _context30.t11);
1576
2132
  case 34:
1577
- return _context19.abrupt("return", _context19.sent);
2133
+ return _context30.abrupt("return", _context30.sent);
1578
2134
  case 37:
1579
- _context19.next = 39;
2135
+ _context30.next = 39;
1580
2136
  return this.Download({
1581
2137
  downloadPath: path,
1582
2138
  bytesTotal: bytesTotal,
@@ -1587,26 +2143,26 @@ exports.DownloadPart = /*#__PURE__*/function () {
1587
2143
  chunkSize: chunkSize
1588
2144
  });
1589
2145
  case 39:
1590
- return _context19.abrupt("return", _context19.sent);
2146
+ return _context30.abrupt("return", _context30.sent);
1591
2147
  case 40:
1592
2148
  case "end":
1593
- return _context19.stop();
2149
+ return _context30.stop();
1594
2150
  }
1595
- }, _callee18, this);
2151
+ }, _callee28, this);
1596
2152
  }));
1597
- return function (_x19) {
1598
- return _ref34.apply(this, arguments);
2153
+ return function (_x29) {
2154
+ return _ref53.apply(this, arguments);
1599
2155
  };
1600
2156
  }();
1601
2157
  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) {
2158
+ var _ref55 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee29(_ref54) {
2159
+ var downloadPath, headers, bytesTotal, _ref54$chunked, chunked, _ref54$chunkSize, chunkSize, callback, _ref54$format, format, outputChunks, bytesFinished, totalChunks, i, response;
2160
+ return _regeneratorRuntime.wrap(function _callee29$(_context31) {
2161
+ while (1) switch (_context31.prev = _context31.next) {
1606
2162
  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;
2163
+ downloadPath = _ref54.downloadPath, headers = _ref54.headers, bytesTotal = _ref54.bytesTotal, _ref54$chunked = _ref54.chunked, chunked = _ref54$chunked === void 0 ? false : _ref54$chunked, _ref54$chunkSize = _ref54.chunkSize, chunkSize = _ref54$chunkSize === void 0 ? 2000000 : _ref54$chunkSize, callback = _ref54.callback, _ref54$format = _ref54.format, format = _ref54$format === void 0 ? "arrayBuffer" : _ref54$format;
1608
2164
  if (!(chunked && !callback)) {
1609
- _context20.next = 3;
2165
+ _context31.next = 3;
1610
2166
  break;
1611
2167
  }
1612
2168
  throw Error("No callback specified for chunked download");
@@ -1621,47 +2177,47 @@ exports.Download = /*#__PURE__*/function () {
1621
2177
  i = 0;
1622
2178
  case 7:
1623
2179
  if (!(i < totalChunks)) {
1624
- _context20.next = 35;
2180
+ _context31.next = 35;
1625
2181
  break;
1626
2182
  }
1627
2183
  headers["Range"] = "bytes=".concat(bytesFinished, "-").concat(bytesFinished + chunkSize - 1);
1628
- _context20.next = 11;
2184
+ _context31.next = 11;
1629
2185
  return this.HttpClient.Request({
1630
2186
  path: downloadPath,
1631
2187
  headers: headers,
1632
2188
  method: "GET"
1633
2189
  });
1634
2190
  case 11:
1635
- response = _context20.sent;
2191
+ response = _context31.sent;
1636
2192
  bytesFinished = Math.min(bytesFinished + chunkSize, bytesTotal);
1637
2193
  if (!chunked) {
1638
- _context20.next = 24;
2194
+ _context31.next = 24;
1639
2195
  break;
1640
2196
  }
1641
- _context20.t0 = callback;
1642
- _context20.t1 = bytesFinished;
1643
- _context20.t2 = bytesTotal;
1644
- _context20.next = 19;
2197
+ _context31.t0 = callback;
2198
+ _context31.t1 = bytesFinished;
2199
+ _context31.t2 = bytesTotal;
2200
+ _context31.next = 19;
1645
2201
  return this.utils.ResponseToFormat(format, response);
1646
2202
  case 19:
1647
- _context20.t3 = _context20.sent;
1648
- _context20.t4 = {
1649
- bytesFinished: _context20.t1,
1650
- bytesTotal: _context20.t2,
1651
- chunk: _context20.t3
2203
+ _context31.t3 = _context31.sent;
2204
+ _context31.t4 = {
2205
+ bytesFinished: _context31.t1,
2206
+ bytesTotal: _context31.t2,
2207
+ chunk: _context31.t3
1652
2208
  };
1653
- (0, _context20.t0)(_context20.t4);
1654
- _context20.next = 32;
2209
+ (0, _context31.t0)(_context31.t4);
2210
+ _context31.next = 32;
1655
2211
  break;
1656
2212
  case 24:
1657
- _context20.t5 = outputChunks;
1658
- _context20.t6 = Buffer;
1659
- _context20.next = 28;
2213
+ _context31.t5 = outputChunks;
2214
+ _context31.t6 = Buffer;
2215
+ _context31.next = 28;
1660
2216
  return response.arrayBuffer();
1661
2217
  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);
2218
+ _context31.t7 = _context31.sent;
2219
+ _context31.t8 = _context31.t6.from.call(_context31.t6, _context31.t7);
2220
+ _context31.t5.push.call(_context31.t5, _context31.t8);
1665
2221
  if (callback) {
1666
2222
  callback({
1667
2223
  bytesFinished: bytesFinished,
@@ -1670,37 +2226,37 @@ exports.Download = /*#__PURE__*/function () {
1670
2226
  }
1671
2227
  case 32:
1672
2228
  i++;
1673
- _context20.next = 7;
2229
+ _context31.next = 7;
1674
2230
  break;
1675
2231
  case 35:
1676
2232
  if (chunked) {
1677
- _context20.next = 39;
2233
+ _context31.next = 39;
1678
2234
  break;
1679
2235
  }
1680
- _context20.next = 38;
2236
+ _context31.next = 38;
1681
2237
  return this.utils.ResponseToFormat(format, new Response(Buffer.concat(outputChunks)));
1682
2238
  case 38:
1683
- return _context20.abrupt("return", _context20.sent);
2239
+ return _context31.abrupt("return", _context31.sent);
1684
2240
  case 39:
1685
2241
  case "end":
1686
- return _context20.stop();
2242
+ return _context31.stop();
1687
2243
  }
1688
- }, _callee19, this);
2244
+ }, _callee29, this);
1689
2245
  }));
1690
- return function (_x20) {
1691
- return _ref36.apply(this, arguments);
2246
+ return function (_x30) {
2247
+ return _ref55.apply(this, arguments);
1692
2248
  };
1693
2249
  }();
1694
2250
  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) {
2251
+ var _ref57 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee31(_ref56) {
2252
+ var _this3 = this;
2253
+ var conk, downloadPath, bytesTotal, headers, callback, _ref56$format, format, _ref56$chunked, chunked, isReencryption, chunkSize, bytesFinished, outputChunks, stream, totalChunks, i, response;
2254
+ return _regeneratorRuntime.wrap(function _callee31$(_context33) {
2255
+ while (1) switch (_context33.prev = _context33.next) {
1700
2256
  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;
2257
+ conk = _ref56.conk, downloadPath = _ref56.downloadPath, bytesTotal = _ref56.bytesTotal, headers = _ref56.headers, callback = _ref56.callback, _ref56$format = _ref56.format, format = _ref56$format === void 0 ? "arrayBuffer" : _ref56$format, _ref56$chunked = _ref56.chunked, chunked = _ref56$chunked === void 0 ? false : _ref56$chunked;
1702
2258
  if (!(chunked && !callback)) {
1703
- _context22.next = 3;
2259
+ _context33.next = 3;
1704
2260
  break;
1705
2261
  }
1706
2262
  throw Error("No callback specified for chunked download");
@@ -1711,44 +2267,44 @@ exports.DownloadEncrypted = /*#__PURE__*/function () {
1711
2267
  bytesFinished = 0;
1712
2268
  format = format.toLowerCase();
1713
2269
  outputChunks = []; // Set up decryption stream
1714
- _context22.next = 10;
2270
+ _context33.next = 10;
1715
2271
  return this.Crypto.OpenDecryptionStream(conk);
1716
2272
  case 10:
1717
- stream = _context22.sent;
2273
+ stream = _context33.sent;
1718
2274
  stream.on("data", /*#__PURE__*/function () {
1719
- var _ref39 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee20(chunk) {
2275
+ var _ref58 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee30(chunk) {
1720
2276
  var arrayBuffer;
1721
- return _regeneratorRuntime.wrap(function _callee20$(_context21) {
1722
- while (1) switch (_context21.prev = _context21.next) {
2277
+ return _regeneratorRuntime.wrap(function _callee30$(_context32) {
2278
+ while (1) switch (_context32.prev = _context32.next) {
1723
2279
  case 0:
1724
2280
  if (!chunked) {
1725
- _context21.next = 13;
2281
+ _context32.next = 13;
1726
2282
  break;
1727
2283
  }
1728
2284
  if (!(format !== "buffer")) {
1729
- _context21.next = 10;
2285
+ _context32.next = 10;
1730
2286
  break;
1731
2287
  }
1732
2288
  arrayBuffer = chunk.buffer.slice(chunk.byteOffset, chunk.byteOffset + chunk.byteLength);
1733
2289
  if (!(format === "arraybuffer")) {
1734
- _context21.next = 7;
2290
+ _context32.next = 7;
1735
2291
  break;
1736
2292
  }
1737
2293
  chunk = arrayBuffer;
1738
- _context21.next = 10;
2294
+ _context32.next = 10;
1739
2295
  break;
1740
2296
  case 7:
1741
- _context21.next = 9;
1742
- return _this2.utils.ResponseToFormat(format, new Response(arrayBuffer));
2297
+ _context32.next = 9;
2298
+ return _this3.utils.ResponseToFormat(format, new Response(arrayBuffer));
1743
2299
  case 9:
1744
- chunk = _context21.sent;
2300
+ chunk = _context32.sent;
1745
2301
  case 10:
1746
2302
  callback({
1747
2303
  bytesFinished: bytesFinished,
1748
2304
  bytesTotal: bytesTotal,
1749
2305
  chunk: chunk
1750
2306
  });
1751
- _context21.next = 15;
2307
+ _context32.next = 15;
1752
2308
  break;
1753
2309
  case 13:
1754
2310
  if (callback) {
@@ -1760,47 +2316,47 @@ exports.DownloadEncrypted = /*#__PURE__*/function () {
1760
2316
  outputChunks.push(chunk);
1761
2317
  case 15:
1762
2318
  case "end":
1763
- return _context21.stop();
2319
+ return _context32.stop();
1764
2320
  }
1765
- }, _callee20);
2321
+ }, _callee30);
1766
2322
  }));
1767
- return function (_x22) {
1768
- return _ref39.apply(this, arguments);
2323
+ return function (_x32) {
2324
+ return _ref58.apply(this, arguments);
1769
2325
  };
1770
2326
  }());
1771
2327
  totalChunks = Math.ceil(bytesTotal / chunkSize);
1772
2328
  i = 0;
1773
2329
  case 14:
1774
2330
  if (!(i < totalChunks)) {
1775
- _context22.next = 30;
2331
+ _context33.next = 30;
1776
2332
  break;
1777
2333
  }
1778
2334
  headers["Range"] = "bytes=".concat(bytesFinished, "-").concat(bytesFinished + chunkSize - 1);
1779
- _context22.next = 18;
2335
+ _context33.next = 18;
1780
2336
  return this.HttpClient.Request({
1781
2337
  headers: headers,
1782
2338
  method: "GET",
1783
2339
  path: downloadPath
1784
2340
  });
1785
2341
  case 18:
1786
- response = _context22.sent;
2342
+ response = _context33.sent;
1787
2343
  bytesFinished = Math.min(bytesFinished + chunkSize, bytesTotal);
1788
- _context22.t0 = stream;
1789
- _context22.t1 = Uint8Array;
1790
- _context22.next = 24;
2344
+ _context33.t0 = stream;
2345
+ _context33.t1 = Uint8Array;
2346
+ _context33.next = 24;
1791
2347
  return response.arrayBuffer();
1792
2348
  case 24:
1793
- _context22.t2 = _context22.sent;
1794
- _context22.t3 = new _context22.t1(_context22.t2);
1795
- _context22.t0.write.call(_context22.t0, _context22.t3);
2349
+ _context33.t2 = _context33.sent;
2350
+ _context33.t3 = new _context33.t1(_context33.t2);
2351
+ _context33.t0.write.call(_context33.t0, _context33.t3);
1796
2352
  case 27:
1797
2353
  i++;
1798
- _context22.next = 14;
2354
+ _context33.next = 14;
1799
2355
  break;
1800
2356
  case 30:
1801
2357
  // Wait for decryption to complete
1802
2358
  stream.end();
1803
- _context22.next = 33;
2359
+ _context33.next = 33;
1804
2360
  return new Promise(function (resolve) {
1805
2361
  return stream.on("finish", function () {
1806
2362
  resolve();
@@ -1808,21 +2364,21 @@ exports.DownloadEncrypted = /*#__PURE__*/function () {
1808
2364
  });
1809
2365
  case 33:
1810
2366
  if (chunked) {
1811
- _context22.next = 37;
2367
+ _context33.next = 37;
1812
2368
  break;
1813
2369
  }
1814
- _context22.next = 36;
2370
+ _context33.next = 36;
1815
2371
  return this.utils.ResponseToFormat(format, new Response(Buffer.concat(outputChunks)));
1816
2372
  case 36:
1817
- return _context22.abrupt("return", _context22.sent);
2373
+ return _context33.abrupt("return", _context33.sent);
1818
2374
  case 37:
1819
2375
  case "end":
1820
- return _context22.stop();
2376
+ return _context33.stop();
1821
2377
  }
1822
- }, _callee21, this);
2378
+ }, _callee31, this);
1823
2379
  }));
1824
- return function (_x21) {
1825
- return _ref38.apply(this, arguments);
2380
+ return function (_x31) {
2381
+ return _ref57.apply(this, arguments);
1826
2382
  };
1827
2383
  }();
1828
2384
 
@@ -1840,20 +2396,20 @@ exports.DownloadEncrypted = /*#__PURE__*/function () {
1840
2396
  * @returns {Promise<string>} - The part write token for the part draft
1841
2397
  */
1842
2398
  exports.CreatePart = /*#__PURE__*/function () {
1843
- var _ref41 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee22(_ref40) {
2399
+ var _ref60 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee32(_ref59) {
1844
2400
  var libraryId, objectId, writeToken, encryption, path, openResponse;
1845
- return _regeneratorRuntime.wrap(function _callee22$(_context23) {
1846
- while (1) switch (_context23.prev = _context23.next) {
2401
+ return _regeneratorRuntime.wrap(function _callee32$(_context34) {
2402
+ while (1) switch (_context34.prev = _context34.next) {
1847
2403
  case 0:
1848
- libraryId = _ref40.libraryId, objectId = _ref40.objectId, writeToken = _ref40.writeToken, encryption = _ref40.encryption;
2404
+ libraryId = _ref59.libraryId, objectId = _ref59.objectId, writeToken = _ref59.writeToken, encryption = _ref59.encryption;
1849
2405
  ValidateParameters({
1850
2406
  libraryId: libraryId,
1851
2407
  objectId: objectId
1852
2408
  });
1853
2409
  ValidateWriteToken(writeToken);
1854
2410
  path = UrlJoin("q", writeToken, "parts");
1855
- _context23.t0 = this.HttpClient;
1856
- _context23.next = 7;
2411
+ _context34.t0 = this.HttpClient;
2412
+ _context34.next = 7;
1857
2413
  return this.authClient.AuthorizationHeader({
1858
2414
  libraryId: libraryId,
1859
2415
  objectId: objectId,
@@ -1861,29 +2417,29 @@ exports.CreatePart = /*#__PURE__*/function () {
1861
2417
  encryption: encryption
1862
2418
  });
1863
2419
  case 7:
1864
- _context23.t1 = _context23.sent;
1865
- _context23.t2 = path;
1866
- _context23.t3 = {
1867
- headers: _context23.t1,
2420
+ _context34.t1 = _context34.sent;
2421
+ _context34.t2 = path;
2422
+ _context34.t3 = {
2423
+ headers: _context34.t1,
1868
2424
  method: "POST",
1869
- path: _context23.t2,
2425
+ path: _context34.t2,
1870
2426
  bodyType: "BINARY",
1871
2427
  body: "",
1872
2428
  allowFailover: false
1873
2429
  };
1874
- _context23.next = 12;
1875
- return _context23.t0.RequestJsonBody.call(_context23.t0, _context23.t3);
2430
+ _context34.next = 12;
2431
+ return _context34.t0.RequestJsonBody.call(_context34.t0, _context34.t3);
1876
2432
  case 12:
1877
- openResponse = _context23.sent;
1878
- return _context23.abrupt("return", openResponse.part.write_token);
2433
+ openResponse = _context34.sent;
2434
+ return _context34.abrupt("return", openResponse.part.write_token);
1879
2435
  case 14:
1880
2436
  case "end":
1881
- return _context23.stop();
2437
+ return _context34.stop();
1882
2438
  }
1883
- }, _callee22, this);
2439
+ }, _callee32, this);
1884
2440
  }));
1885
- return function (_x23) {
1886
- return _ref41.apply(this, arguments);
2441
+ return function (_x33) {
2442
+ return _ref60.apply(this, arguments);
1887
2443
  };
1888
2444
  }();
1889
2445
 
@@ -1903,38 +2459,38 @@ exports.CreatePart = /*#__PURE__*/function () {
1903
2459
  * @returns {Promise<string>} - The part write token for the part draft
1904
2460
  */
1905
2461
  exports.UploadPartChunk = /*#__PURE__*/function () {
1906
- var _ref43 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee23(_ref42) {
2462
+ var _ref62 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee33(_ref61) {
1907
2463
  var libraryId, objectId, writeToken, partWriteToken, chunk, encryption, conk, path;
1908
- return _regeneratorRuntime.wrap(function _callee23$(_context24) {
1909
- while (1) switch (_context24.prev = _context24.next) {
2464
+ return _regeneratorRuntime.wrap(function _callee33$(_context35) {
2465
+ while (1) switch (_context35.prev = _context35.next) {
1910
2466
  case 0:
1911
- libraryId = _ref42.libraryId, objectId = _ref42.objectId, writeToken = _ref42.writeToken, partWriteToken = _ref42.partWriteToken, chunk = _ref42.chunk, encryption = _ref42.encryption;
2467
+ libraryId = _ref61.libraryId, objectId = _ref61.objectId, writeToken = _ref61.writeToken, partWriteToken = _ref61.partWriteToken, chunk = _ref61.chunk, encryption = _ref61.encryption;
1912
2468
  ValidateParameters({
1913
2469
  libraryId: libraryId,
1914
2470
  objectId: objectId
1915
2471
  });
1916
2472
  ValidateWriteToken(writeToken);
1917
2473
  if (!(encryption && encryption !== "none")) {
1918
- _context24.next = 10;
2474
+ _context35.next = 10;
1919
2475
  break;
1920
2476
  }
1921
- _context24.next = 6;
2477
+ _context35.next = 6;
1922
2478
  return this.EncryptionConk({
1923
2479
  libraryId: libraryId,
1924
2480
  objectId: objectId,
1925
2481
  writeToken: writeToken
1926
2482
  });
1927
2483
  case 6:
1928
- conk = _context24.sent;
1929
- _context24.next = 9;
2484
+ conk = _context35.sent;
2485
+ _context35.next = 9;
1930
2486
  return this.Crypto.Encrypt(conk, chunk);
1931
2487
  case 9:
1932
- chunk = _context24.sent;
2488
+ chunk = _context35.sent;
1933
2489
  case 10:
1934
2490
  path = UrlJoin("q", writeToken, "parts");
1935
- _context24.t0 = this.utils;
1936
- _context24.t1 = this.HttpClient;
1937
- _context24.next = 15;
2491
+ _context35.t0 = this.utils;
2492
+ _context35.t1 = this.HttpClient;
2493
+ _context35.next = 15;
1938
2494
  return this.authClient.AuthorizationHeader({
1939
2495
  libraryId: libraryId,
1940
2496
  objectId: objectId,
@@ -1942,28 +2498,28 @@ exports.UploadPartChunk = /*#__PURE__*/function () {
1942
2498
  encryption: encryption
1943
2499
  });
1944
2500
  case 15:
1945
- _context24.t2 = _context24.sent;
1946
- _context24.t3 = UrlJoin(path, partWriteToken);
1947
- _context24.t4 = chunk;
1948
- _context24.t5 = {
1949
- headers: _context24.t2,
2501
+ _context35.t2 = _context35.sent;
2502
+ _context35.t3 = UrlJoin(path, partWriteToken);
2503
+ _context35.t4 = chunk;
2504
+ _context35.t5 = {
2505
+ headers: _context35.t2,
1950
2506
  method: "POST",
1951
- path: _context24.t3,
1952
- body: _context24.t4,
2507
+ path: _context35.t3,
2508
+ body: _context35.t4,
1953
2509
  bodyType: "BINARY",
1954
2510
  allowFailover: false
1955
2511
  };
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);
2512
+ _context35.t6 = _context35.t1.Request.call(_context35.t1, _context35.t5);
2513
+ _context35.next = 22;
2514
+ return _context35.t0.ResponseToJson.call(_context35.t0, _context35.t6);
1959
2515
  case 22:
1960
2516
  case "end":
1961
- return _context24.stop();
2517
+ return _context35.stop();
1962
2518
  }
1963
- }, _callee23, this);
2519
+ }, _callee33, this);
1964
2520
  }));
1965
- return function (_x24) {
1966
- return _ref43.apply(this, arguments);
2521
+ return function (_x34) {
2522
+ return _ref62.apply(this, arguments);
1967
2523
  };
1968
2524
  }();
1969
2525
 
@@ -1982,20 +2538,20 @@ exports.UploadPartChunk = /*#__PURE__*/function () {
1982
2538
  * @returns {Promise<object>} - The finalize response for the new part
1983
2539
  */
1984
2540
  exports.FinalizePart = /*#__PURE__*/function () {
1985
- var _ref45 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee24(_ref44) {
2541
+ var _ref64 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee34(_ref63) {
1986
2542
  var libraryId, objectId, writeToken, partWriteToken, encryption, path;
1987
- return _regeneratorRuntime.wrap(function _callee24$(_context25) {
1988
- while (1) switch (_context25.prev = _context25.next) {
2543
+ return _regeneratorRuntime.wrap(function _callee34$(_context36) {
2544
+ while (1) switch (_context36.prev = _context36.next) {
1989
2545
  case 0:
1990
- libraryId = _ref44.libraryId, objectId = _ref44.objectId, writeToken = _ref44.writeToken, partWriteToken = _ref44.partWriteToken, encryption = _ref44.encryption;
2546
+ libraryId = _ref63.libraryId, objectId = _ref63.objectId, writeToken = _ref63.writeToken, partWriteToken = _ref63.partWriteToken, encryption = _ref63.encryption;
1991
2547
  ValidateParameters({
1992
2548
  libraryId: libraryId,
1993
2549
  objectId: objectId
1994
2550
  });
1995
2551
  ValidateWriteToken(writeToken);
1996
2552
  path = UrlJoin("q", writeToken, "parts");
1997
- _context25.t0 = this.HttpClient;
1998
- _context25.next = 7;
2553
+ _context36.t0 = this.HttpClient;
2554
+ _context36.next = 7;
1999
2555
  return this.authClient.AuthorizationHeader({
2000
2556
  libraryId: libraryId,
2001
2557
  objectId: objectId,
@@ -2003,28 +2559,28 @@ exports.FinalizePart = /*#__PURE__*/function () {
2003
2559
  encryption: encryption
2004
2560
  });
2005
2561
  case 7:
2006
- _context25.t1 = _context25.sent;
2007
- _context25.t2 = UrlJoin(path, partWriteToken);
2008
- _context25.t3 = {
2009
- headers: _context25.t1,
2562
+ _context36.t1 = _context36.sent;
2563
+ _context36.t2 = UrlJoin(path, partWriteToken);
2564
+ _context36.t3 = {
2565
+ headers: _context36.t1,
2010
2566
  method: "POST",
2011
- path: _context25.t2,
2567
+ path: _context36.t2,
2012
2568
  bodyType: "BINARY",
2013
2569
  body: "",
2014
2570
  allowFailover: false
2015
2571
  };
2016
- _context25.next = 12;
2017
- return _context25.t0.RequestJsonBody.call(_context25.t0, _context25.t3);
2572
+ _context36.next = 12;
2573
+ return _context36.t0.RequestJsonBody.call(_context36.t0, _context36.t3);
2018
2574
  case 12:
2019
- return _context25.abrupt("return", _context25.sent);
2575
+ return _context36.abrupt("return", _context36.sent);
2020
2576
  case 13:
2021
2577
  case "end":
2022
- return _context25.stop();
2578
+ return _context36.stop();
2023
2579
  }
2024
- }, _callee24, this);
2580
+ }, _callee34, this);
2025
2581
  }));
2026
- return function (_x25) {
2027
- return _ref45.apply(this, arguments);
2582
+ return function (_x35) {
2583
+ return _ref64.apply(this, arguments);
2028
2584
  };
2029
2585
  }();
2030
2586
 
@@ -2050,18 +2606,18 @@ exports.FinalizePart = /*#__PURE__*/function () {
2050
2606
  * @returns {Promise<Object>} - Response containing information about the uploaded part
2051
2607
  */
2052
2608
  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) {
2609
+ var _ref66 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee35(_ref65) {
2610
+ var libraryId, objectId, writeToken, data, _ref65$encryption, encryption, _ref65$chunkSize, chunkSize, callback, partWriteToken, size, i, chunk;
2611
+ return _regeneratorRuntime.wrap(function _callee35$(_context37) {
2612
+ while (1) switch (_context37.prev = _context37.next) {
2057
2613
  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;
2614
+ libraryId = _ref65.libraryId, objectId = _ref65.objectId, writeToken = _ref65.writeToken, data = _ref65.data, _ref65$encryption = _ref65.encryption, encryption = _ref65$encryption === void 0 ? "none" : _ref65$encryption, _ref65$chunkSize = _ref65.chunkSize, chunkSize = _ref65$chunkSize === void 0 ? 10000000 : _ref65$chunkSize, callback = _ref65.callback;
2059
2615
  ValidateParameters({
2060
2616
  libraryId: libraryId,
2061
2617
  objectId: objectId
2062
2618
  });
2063
2619
  ValidateWriteToken(writeToken);
2064
- _context26.next = 5;
2620
+ _context37.next = 5;
2065
2621
  return this.CreatePart({
2066
2622
  libraryId: libraryId,
2067
2623
  objectId: objectId,
@@ -2069,7 +2625,7 @@ exports.UploadPart = /*#__PURE__*/function () {
2069
2625
  encryption: encryption
2070
2626
  });
2071
2627
  case 5:
2072
- partWriteToken = _context26.sent;
2628
+ partWriteToken = _context37.sent;
2073
2629
  size = data.length || data.byteLength || data.size;
2074
2630
  if (callback) {
2075
2631
  callback({
@@ -2080,11 +2636,11 @@ exports.UploadPart = /*#__PURE__*/function () {
2080
2636
  i = 0;
2081
2637
  case 9:
2082
2638
  if (!(i < size)) {
2083
- _context26.next = 17;
2639
+ _context37.next = 17;
2084
2640
  break;
2085
2641
  }
2086
2642
  chunk = data.slice(i, i + chunkSize);
2087
- _context26.next = 13;
2643
+ _context37.next = 13;
2088
2644
  return this.UploadPartChunk({
2089
2645
  libraryId: libraryId,
2090
2646
  objectId: objectId,
@@ -2102,10 +2658,10 @@ exports.UploadPart = /*#__PURE__*/function () {
2102
2658
  }
2103
2659
  case 14:
2104
2660
  i += chunkSize;
2105
- _context26.next = 9;
2661
+ _context37.next = 9;
2106
2662
  break;
2107
2663
  case 17:
2108
- _context26.next = 19;
2664
+ _context37.next = 19;
2109
2665
  return this.FinalizePart({
2110
2666
  libraryId: libraryId,
2111
2667
  objectId: objectId,
@@ -2114,15 +2670,15 @@ exports.UploadPart = /*#__PURE__*/function () {
2114
2670
  encryption: encryption
2115
2671
  });
2116
2672
  case 19:
2117
- return _context26.abrupt("return", _context26.sent);
2673
+ return _context37.abrupt("return", _context37.sent);
2118
2674
  case 20:
2119
2675
  case "end":
2120
- return _context26.stop();
2676
+ return _context37.stop();
2121
2677
  }
2122
- }, _callee25, this);
2678
+ }, _callee35, this);
2123
2679
  }));
2124
- return function (_x26) {
2125
- return _ref47.apply(this, arguments);
2680
+ return function (_x36) {
2681
+ return _ref66.apply(this, arguments);
2126
2682
  };
2127
2683
  }();
2128
2684
 
@@ -2138,12 +2694,12 @@ exports.UploadPart = /*#__PURE__*/function () {
2138
2694
  * @param {string} partHash - Hash of the part to delete
2139
2695
  */
2140
2696
  exports.DeletePart = /*#__PURE__*/function () {
2141
- var _ref49 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee26(_ref48) {
2697
+ var _ref68 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee36(_ref67) {
2142
2698
  var libraryId, objectId, writeToken, partHash, path;
2143
- return _regeneratorRuntime.wrap(function _callee26$(_context27) {
2144
- while (1) switch (_context27.prev = _context27.next) {
2699
+ return _regeneratorRuntime.wrap(function _callee36$(_context38) {
2700
+ while (1) switch (_context38.prev = _context38.next) {
2145
2701
  case 0:
2146
- libraryId = _ref48.libraryId, objectId = _ref48.objectId, writeToken = _ref48.writeToken, partHash = _ref48.partHash;
2702
+ libraryId = _ref67.libraryId, objectId = _ref67.objectId, writeToken = _ref67.writeToken, partHash = _ref67.partHash;
2147
2703
  ValidateParameters({
2148
2704
  libraryId: libraryId,
2149
2705
  objectId: objectId
@@ -2151,31 +2707,31 @@ exports.DeletePart = /*#__PURE__*/function () {
2151
2707
  ValidateWriteToken(writeToken);
2152
2708
  ValidatePartHash(partHash);
2153
2709
  path = UrlJoin("q", writeToken, "parts", partHash);
2154
- _context27.t0 = this.HttpClient;
2155
- _context27.next = 8;
2710
+ _context38.t0 = this.HttpClient;
2711
+ _context38.next = 8;
2156
2712
  return this.authClient.AuthorizationHeader({
2157
2713
  libraryId: libraryId,
2158
2714
  objectId: objectId,
2159
2715
  update: true
2160
2716
  });
2161
2717
  case 8:
2162
- _context27.t1 = _context27.sent;
2163
- _context27.t2 = path;
2164
- _context27.t3 = {
2165
- headers: _context27.t1,
2718
+ _context38.t1 = _context38.sent;
2719
+ _context38.t2 = path;
2720
+ _context38.t3 = {
2721
+ headers: _context38.t1,
2166
2722
  method: "DELETE",
2167
- path: _context27.t2,
2723
+ path: _context38.t2,
2168
2724
  allowFailover: false
2169
2725
  };
2170
- _context27.next = 13;
2171
- return _context27.t0.Request.call(_context27.t0, _context27.t3);
2726
+ _context38.next = 13;
2727
+ return _context38.t0.Request.call(_context38.t0, _context38.t3);
2172
2728
  case 13:
2173
2729
  case "end":
2174
- return _context27.stop();
2730
+ return _context38.stop();
2175
2731
  }
2176
- }, _callee26, this);
2732
+ }, _callee36, this);
2177
2733
  }));
2178
- return function (_x27) {
2179
- return _ref49.apply(this, arguments);
2734
+ return function (_x37) {
2735
+ return _ref68.apply(this, arguments);
2180
2736
  };
2181
2737
  }();