@atlaskit/media-client 33.0.0 → 33.1.0

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.
@@ -97,7 +97,7 @@ function createUrl(url, _ref2) {
97
97
  return value != null;
98
98
  }).forEach(function (pair) {
99
99
  var _parsedUrl$searchPara;
100
- (_parsedUrl$searchPara = parsedUrl.searchParams).append.apply(_parsedUrl$searchPara, (0, _toConsumableArray2.default)(pair));
100
+ (_parsedUrl$searchPara = parsedUrl.searchParams).set.apply(_parsedUrl$searchPara, (0, _toConsumableArray2.default)(pair));
101
101
  });
102
102
  parsedUrl.searchParams.sort();
103
103
  return parsedUrl.toString();
@@ -140,6 +140,21 @@ export class FileFetcherImpl {
140
140
  preview
141
141
  };
142
142
  });
143
+ _defineProperty(this, "uploadArtifact", async (id, file, params, collectionName, traceContext) => {
144
+ const {
145
+ data
146
+ } = await this.mediaApi.uploadArtifact(id, file, params, collectionName, traceContext);
147
+
148
+ /* TEMPORARYLY PULLING NEW METADATA till the endpoint is fixed */
149
+ const {
150
+ data: altData
151
+ } = await this.mediaApi.getItems([id], collectionName, traceContext);
152
+ const itemDetails = altData.items[0].details;
153
+ // ------------------------------------------------------------
154
+
155
+ this.setFileState(id, mapMediaItemToFileState(id, itemDetails));
156
+ return data;
157
+ });
143
158
  this.mediaApi = mediaApi;
144
159
  this.store = store;
145
160
  this.dataloader = createFileDataloader(mediaApi);
@@ -30,15 +30,62 @@ const jsonHeaders = {
30
30
  };
31
31
  const cdnFeatureFlag = endpoint => {
32
32
  let result = endpoint;
33
- if (fg('platform_media_cdn_delivery')) {
34
- if (isCommercial()) {
35
- result += '/cdn';
36
- }
33
+ if (isCommercial() && fg('platform_media_cdn_delivery')) {
34
+ result += '/cdn';
37
35
  }
38
36
  return result;
39
37
  };
40
38
  export class MediaStore {
41
39
  constructor(config) {
40
+ _defineProperty(this, "getArtifactBinary", async (artifacts, artifactName, {
41
+ collectionName,
42
+ abortController,
43
+ maxAge = FILE_CACHE_MAX_AGE,
44
+ traceContext
45
+ }) => {
46
+ const metadata = {
47
+ method: 'GET',
48
+ endpoint: `artifact-cdn-url`
49
+ };
50
+ const extendedTraceContext = extendTraceContext(traceContext);
51
+ const options = {
52
+ ...metadata,
53
+ traceContext: extendedTraceContext
54
+ };
55
+ const artifactUrl = await this.getArtifactURL(artifacts, artifactName, collectionName, maxAge);
56
+ return request(artifactUrl, options, abortController).then(createMapResponseToBlob(metadata));
57
+ });
58
+ _defineProperty(this, "uploadArtifact", async (id, file, params, collectionName, traceContext) => {
59
+ const metadata = {
60
+ method: 'POST',
61
+ endpoint: '/file/{fileId}/artifact/binary'
62
+ };
63
+ const headers = {
64
+ Accept: 'application/json',
65
+ 'Content-Type': file.type
66
+ };
67
+ const extendedParams = {
68
+ ...params,
69
+ name: file.name
70
+ };
71
+ const authContext = {
72
+ collectionName,
73
+ access: [{
74
+ type: 'file',
75
+ id,
76
+ actions: ['update']
77
+ }]
78
+ };
79
+ const options = {
80
+ ...metadata,
81
+ authContext,
82
+ headers,
83
+ params: extendedParams,
84
+ body: file,
85
+ traceContext
86
+ };
87
+ return this.request(`/file/${id}/artifact/binary`, options).then(createMapResponseToJson(metadata));
88
+ });
42
89
  _defineProperty(this, "resolveAuth", authContext => resolveAuth(this.config.authProvider, authContext, this.config.authProviderTimeout));
43
90
  _defineProperty(this, "resolveInitialAuth", () => resolveInitialAuth(this.config.initialAuth));
44
91
  this.config = config;
@@ -234,7 +281,16 @@ export class MediaStore {
234
281
  const binaryEndpoint = cdnFeatureFlag('binary');
235
282
  return mapToMediaCdnUrl(createUrl(`${auth.baseUrl}/file/${id}/${binaryEndpoint}`, options), auth.token);
236
283
  }
237
- async getArtifactURL(artifacts, artifactName, collectionName) {
284
+ async getArtifactURL(artifacts, artifactName, collectionName, maxAge = FILE_CACHE_MAX_AGE) {
285
+ // getArtifactURL returns a constructed url PATH, not the full Media/CDN Url.
286
+ // We use the provided cdnUrl from metadata first.
287
+ if (isCommercial() && fg('platform_media_cdn_delivery')) {
288
+ var _artifacts$artifactNa;
289
+ const cdnUrl = (_artifacts$artifactNa = artifacts[artifactName]) === null || _artifacts$artifactNa === void 0 ? void 0 : _artifacts$artifactNa.cdnUrl;
290
+ if (cdnUrl) {
291
+ return cdnUrl;
292
+ }
293
+ }
238
294
  const artifactUrl = getArtifactUrl(artifacts, artifactName);
239
295
  if (!artifactUrl) {
240
296
  throw new Error(`artifact ${artifactName} not found`);
@@ -245,7 +301,7 @@ export class MediaStore {
245
301
  const options = {
246
302
  params: {
247
303
  collection: collectionName,
248
- 'max-age': FILE_CACHE_MAX_AGE
304
+ 'max-age': maxAge
249
305
  },
250
306
  auth
251
307
  };
@@ -64,7 +64,7 @@ export function createUrl(url, {
64
64
  ...authParams
65
65
  };
66
66
  Object.entries(paramsToAppend).filter(([_, value]) => value != null).forEach(pair => {
67
- parsedUrl.searchParams.append(...pair);
67
+ parsedUrl.searchParams.set(...pair);
68
68
  });
69
69
  parsedUrl.searchParams.sort();
70
70
  return parsedUrl.toString();
@@ -171,6 +171,35 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
171
171
  preview: preview
172
172
  };
173
173
  });
174
+ _defineProperty(this, "uploadArtifact", /*#__PURE__*/function () {
175
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(id, file, params, collectionName, traceContext) {
176
+ var _yield$_this$mediaApi, data, _yield$_this$mediaApi2, altData, itemDetails;
177
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
178
+ while (1) switch (_context2.prev = _context2.next) {
179
+ case 0:
180
+ _context2.next = 2;
181
+ return _this.mediaApi.uploadArtifact(id, file, params, collectionName, traceContext);
182
+ case 2:
183
+ _yield$_this$mediaApi = _context2.sent;
184
+ data = _yield$_this$mediaApi.data;
185
+ _context2.next = 6;
186
+ return _this.mediaApi.getItems([id], collectionName, traceContext);
187
+ case 6:
188
+ _yield$_this$mediaApi2 = _context2.sent;
189
+ altData = _yield$_this$mediaApi2.data;
190
+ itemDetails = altData.items[0].details; // ------------------------------------------------------------
191
+ _this.setFileState(id, mapMediaItemToFileState(id, itemDetails));
192
+ return _context2.abrupt("return", data);
193
+ case 11:
194
+ case "end":
195
+ return _context2.stop();
196
+ }
197
+ }, _callee2);
198
+ }));
199
+ return function (_x, _x2, _x3, _x4, _x5) {
200
+ return _ref2.apply(this, arguments);
201
+ };
202
+ }());
174
203
  this.mediaApi = mediaApi;
175
204
  this.store = store;
176
205
  this.dataloader = createFileDataloader(mediaApi);
@@ -236,8 +265,8 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
236
265
  descriptors: descriptors
237
266
  }, {
238
267
  collection: collection
239
- }, traceContext).then(function (_ref2) {
240
- var data = _ref2.data;
268
+ }, traceContext).then(function (_ref3) {
269
+ var data = _ref3.data;
241
270
  return data;
242
271
  });
243
272
  }
@@ -263,11 +292,11 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
263
292
  }, {
264
293
  key: "uploadExternal",
265
294
  value: function () {
266
- var _uploadExternal = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(url, collection, traceContext) {
295
+ var _uploadExternal = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(url, collection, traceContext) {
267
296
  var _this3 = this;
268
297
  var uploadableFileUpfrontIds, id, occurrenceKey, subject, deferredBlob, preview, name, fileState;
269
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
270
- while (1) switch (_context4.prev = _context4.next) {
298
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
299
+ while (1) switch (_context5.prev = _context5.next) {
271
300
  case 0:
272
301
  uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
273
302
  id = uploadableFileUpfrontIds.id, occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
@@ -278,15 +307,15 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
278
307
  return undefined;
279
308
  });
280
309
  preview = new Promise( /*#__PURE__*/function () {
281
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resolve, reject) {
310
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resolve, reject) {
282
311
  var blob;
283
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
284
- while (1) switch (_context2.prev = _context2.next) {
312
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
313
+ while (1) switch (_context3.prev = _context3.next) {
285
314
  case 0:
286
- _context2.next = 2;
315
+ _context3.next = 2;
287
316
  return deferredBlob;
288
317
  case 2:
289
- blob = _context2.sent;
318
+ blob = _context3.sent;
290
319
  if (!blob) {
291
320
  reject('Could not fetch the blob');
292
321
  }
@@ -296,12 +325,12 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
296
325
  });
297
326
  case 5:
298
327
  case "end":
299
- return _context2.stop();
328
+ return _context3.stop();
300
329
  }
301
- }, _callee2);
330
+ }, _callee3);
302
331
  }));
303
- return function (_x4, _x5) {
304
- return _ref3.apply(this, arguments);
332
+ return function (_x9, _x10) {
333
+ return _ref4.apply(this, arguments);
305
334
  };
306
335
  }());
307
336
  name = url.split('/').pop() || ''; // we create a initial fileState with the minimum info that we have at this point
@@ -319,21 +348,21 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
319
348
  // we save it into the cache as soon as possible, in case someone subscribes
320
349
  getFileStreamsCache().set(id, subject);
321
350
  this.setFileState(id, fileState);
322
- return _context4.abrupt("return", new Promise( /*#__PURE__*/function () {
323
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resolve, reject) {
351
+ return _context5.abrupt("return", new Promise( /*#__PURE__*/function () {
352
+ var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(resolve, reject) {
324
353
  var blob, type, size, file, mediaType, dimensions;
325
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
326
- while (1) switch (_context3.prev = _context3.next) {
354
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
355
+ while (1) switch (_context4.prev = _context4.next) {
327
356
  case 0:
328
- _context3.next = 2;
357
+ _context4.next = 2;
329
358
  return deferredBlob;
330
359
  case 2:
331
- blob = _context3.sent;
360
+ blob = _context4.sent;
332
361
  if (blob) {
333
- _context3.next = 5;
362
+ _context4.next = 5;
334
363
  break;
335
364
  }
336
- return _context3.abrupt("return", reject('Could not download remote file'));
365
+ return _context4.abrupt("return", reject('Could not download remote file'));
337
366
  case 5:
338
367
  type = blob.type, size = blob.size;
339
368
  file = {
@@ -356,18 +385,18 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
356
385
  });
357
386
  // we don't want to wait for the file to be upload
358
387
  _this3.upload(file, undefined, uploadableFileUpfrontIds, traceContext);
359
- _context3.prev = 10;
360
- _context3.next = 13;
388
+ _context4.prev = 10;
389
+ _context4.next = 13;
361
390
  return getDimensionsFromBlob(mediaType, blob);
362
391
  case 13:
363
- dimensions = _context3.sent;
364
- _context3.next = 20;
392
+ dimensions = _context4.sent;
393
+ _context4.next = 20;
365
394
  break;
366
395
  case 16:
367
- _context3.prev = 16;
368
- _context3.t0 = _context3["catch"](10);
369
- reject(_context3.t0);
370
- return _context3.abrupt("return");
396
+ _context4.prev = 16;
397
+ _context4.t0 = _context4["catch"](10);
398
+ reject(_context4.t0);
399
+ return _context4.abrupt("return");
371
400
  case 20:
372
401
  resolve({
373
402
  dimensions: dimensions,
@@ -376,21 +405,21 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
376
405
  });
377
406
  case 21:
378
407
  case "end":
379
- return _context3.stop();
408
+ return _context4.stop();
380
409
  }
381
- }, _callee3, null, [[10, 16]]);
410
+ }, _callee4, null, [[10, 16]]);
382
411
  }));
383
- return function (_x6, _x7) {
384
- return _ref4.apply(this, arguments);
412
+ return function (_x11, _x12) {
413
+ return _ref5.apply(this, arguments);
385
414
  };
386
415
  }()));
387
416
  case 11:
388
417
  case "end":
389
- return _context4.stop();
418
+ return _context5.stop();
390
419
  }
391
- }, _callee4, this);
420
+ }, _callee5, this);
392
421
  }));
393
- function uploadExternal(_x, _x2, _x3) {
422
+ function uploadExternal(_x6, _x7, _x8) {
394
423
  return _uploadExternal.apply(this, arguments);
395
424
  }
396
425
  return uploadExternal;
@@ -457,22 +486,22 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
457
486
  }, {
458
487
  key: "downloadBinary",
459
488
  value: function () {
460
- var _downloadBinary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(id) {
489
+ var _downloadBinary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(id) {
461
490
  var name,
462
491
  collectionName,
463
492
  traceContext,
464
493
  url,
465
- _args5 = arguments;
466
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
467
- while (1) switch (_context5.prev = _context5.next) {
494
+ _args6 = arguments;
495
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
496
+ while (1) switch (_context6.prev = _context6.next) {
468
497
  case 0:
469
- name = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : 'download';
470
- collectionName = _args5.length > 2 ? _args5[2] : undefined;
471
- traceContext = _args5.length > 3 ? _args5[3] : undefined;
472
- _context5.next = 5;
498
+ name = _args6.length > 1 && _args6[1] !== undefined ? _args6[1] : 'download';
499
+ collectionName = _args6.length > 2 ? _args6[2] : undefined;
500
+ traceContext = _args6.length > 3 ? _args6[3] : undefined;
501
+ _context6.next = 5;
473
502
  return this.mediaApi.getFileBinaryURL(id, collectionName);
474
503
  case 5:
475
- url = _context5.sent;
504
+ url = _context6.sent;
476
505
  downloadUrl(url, {
477
506
  name: name
478
507
  });
@@ -482,17 +511,17 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
482
511
  viewingLevel: 'download'
483
512
  });
484
513
  // Test the download after initiated the Browser process to catch any potential errors.
485
- _context5.next = 10;
514
+ _context6.next = 10;
486
515
  return this.mediaApi.testUrl(url, {
487
516
  traceContext: traceContext
488
517
  });
489
518
  case 10:
490
519
  case "end":
491
- return _context5.stop();
520
+ return _context6.stop();
492
521
  }
493
- }, _callee5, this);
522
+ }, _callee6, this);
494
523
  }));
495
- function downloadBinary(_x8) {
524
+ function downloadBinary(_x13) {
496
525
  return _downloadBinary.apply(this, arguments);
497
526
  }
498
527
  return downloadBinary;
@@ -500,28 +529,28 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
500
529
  }, {
501
530
  key: "registerCopyIntent",
502
531
  value: function () {
503
- var _registerCopyIntent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(id, collectionName) {
532
+ var _registerCopyIntent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(id, collectionName) {
504
533
  var auth, key, error;
505
- return _regeneratorRuntime.wrap(function _callee6$(_context6) {
506
- while (1) switch (_context6.prev = _context6.next) {
534
+ return _regeneratorRuntime.wrap(function _callee7$(_context7) {
535
+ while (1) switch (_context7.prev = _context7.next) {
507
536
  case 0:
508
- _context6.next = 2;
537
+ _context7.next = 2;
509
538
  return this.mediaApi.resolveAuth({
510
539
  collectionName: collectionName
511
540
  });
512
541
  case 2:
513
- auth = _context6.sent;
542
+ auth = _context7.sent;
514
543
  key = {
515
544
  id: id,
516
545
  collectionName: collectionName,
517
546
  resolvedAuth: auth
518
547
  };
519
- _context6.next = 6;
548
+ _context7.next = 6;
520
549
  return this.copyIntentRegisterationBatcher.load(key);
521
550
  case 6:
522
- error = _context6.sent;
551
+ error = _context7.sent;
523
552
  if (!error) {
524
- _context6.next = 10;
553
+ _context7.next = 10;
525
554
  break;
526
555
  }
527
556
  // if the error is retryable then it should not be cached
@@ -531,11 +560,11 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
531
560
  throw error;
532
561
  case 10:
533
562
  case "end":
534
- return _context6.stop();
563
+ return _context7.stop();
535
564
  }
536
- }, _callee6, this);
565
+ }, _callee7, this);
537
566
  }));
538
- function registerCopyIntent(_x9, _x10) {
567
+ function registerCopyIntent(_x14, _x15) {
539
568
  return _registerCopyIntent.apply(this, arguments);
540
569
  }
541
570
  return registerCopyIntent;
@@ -543,24 +572,24 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
543
572
  }, {
544
573
  key: "copyFileWithToken",
545
574
  value: function () {
546
- var _copyFileWithToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(source, destination, traceContext) {
575
+ var _copyFileWithToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(source, destination, traceContext) {
547
576
  var authProvider, sourceCollection, id, destinationAuthProvider, destinationCollectionName, replaceFileId, occurrenceKey, mediaStore, owner, body, params, _yield$mediaStore$cop, data;
548
- return _regeneratorRuntime.wrap(function _callee7$(_context7) {
549
- while (1) switch (_context7.prev = _context7.next) {
577
+ return _regeneratorRuntime.wrap(function _callee8$(_context8) {
578
+ while (1) switch (_context8.prev = _context8.next) {
550
579
  case 0:
551
580
  authProvider = source.authProvider, sourceCollection = source.collection, id = source.id;
552
581
  destinationAuthProvider = destination.authProvider, destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
553
582
  mediaStore = destination.mediaStore || new MediaApi({
554
583
  authProvider: destinationAuthProvider
555
584
  });
556
- _context7.t0 = authToOwner;
557
- _context7.next = 6;
585
+ _context8.t0 = authToOwner;
586
+ _context8.next = 6;
558
587
  return authProvider({
559
588
  collectionName: sourceCollection
560
589
  });
561
590
  case 6:
562
- _context7.t1 = _context7.sent;
563
- owner = (0, _context7.t0)(_context7.t1);
591
+ _context8.t1 = _context8.sent;
592
+ owner = (0, _context8.t0)(_context8.t1);
564
593
  body = {
565
594
  sourceFile: {
566
595
  id: id,
@@ -573,19 +602,19 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
573
602
  replaceFileId: replaceFileId,
574
603
  occurrenceKey: occurrenceKey
575
604
  };
576
- _context7.next = 12;
605
+ _context8.next = 12;
577
606
  return mediaStore.copyFileWithToken(body, params, traceContext);
578
607
  case 12:
579
- _yield$mediaStore$cop = _context7.sent;
608
+ _yield$mediaStore$cop = _context8.sent;
580
609
  data = _yield$mediaStore$cop.data;
581
- return _context7.abrupt("return", data);
610
+ return _context8.abrupt("return", data);
582
611
  case 15:
583
612
  case "end":
584
- return _context7.stop();
613
+ return _context8.stop();
585
614
  }
586
- }, _callee7);
615
+ }, _callee8);
587
616
  }));
588
- function copyFileWithToken(_x11, _x12, _x13) {
617
+ function copyFileWithToken(_x16, _x17, _x18) {
589
618
  return _copyFileWithToken.apply(this, arguments);
590
619
  }
591
620
  return copyFileWithToken;
@@ -593,28 +622,28 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
593
622
  }, {
594
623
  key: "copyFileWithIntent",
595
624
  value: function () {
596
- var _copyFileWithIntent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(source, destination, traceContext) {
625
+ var _copyFileWithIntent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(source, destination, traceContext) {
597
626
  var res, data;
598
- return _regeneratorRuntime.wrap(function _callee8$(_context8) {
599
- while (1) switch (_context8.prev = _context8.next) {
627
+ return _regeneratorRuntime.wrap(function _callee9$(_context9) {
628
+ while (1) switch (_context9.prev = _context9.next) {
600
629
  case 0:
601
- _context8.next = 2;
630
+ _context9.next = 2;
602
631
  return this.mediaApi.copyFile(source.id, {
603
632
  sourceCollection: source.collection,
604
633
  collection: destination.collection,
605
634
  replaceFileId: destination.replaceFileId
606
635
  }, traceContext);
607
636
  case 2:
608
- res = _context8.sent;
637
+ res = _context9.sent;
609
638
  data = res.data;
610
- return _context8.abrupt("return", data);
639
+ return _context9.abrupt("return", data);
611
640
  case 5:
612
641
  case "end":
613
- return _context8.stop();
642
+ return _context9.stop();
614
643
  }
615
- }, _callee8, this);
644
+ }, _callee9, this);
616
645
  }));
617
- function copyFileWithIntent(_x14, _x15, _x16) {
646
+ function copyFileWithIntent(_x19, _x20, _x21) {
618
647
  return _copyFileWithIntent.apply(this, arguments);
619
648
  }
620
649
  return copyFileWithIntent;
@@ -622,7 +651,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
622
651
  }, {
623
652
  key: "copyFile",
624
653
  value: function () {
625
- var _copyFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(source, destination) {
654
+ var _copyFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(source, destination) {
626
655
  var _this5 = this;
627
656
  var options,
628
657
  traceContext,
@@ -649,32 +678,32 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
649
678
  replaceFileState,
650
679
  key,
651
680
  errorFileState,
652
- _args9 = arguments;
653
- return _regeneratorRuntime.wrap(function _callee9$(_context9) {
654
- while (1) switch (_context9.prev = _context9.next) {
681
+ _args10 = arguments;
682
+ return _regeneratorRuntime.wrap(function _callee10$(_context10) {
683
+ while (1) switch (_context10.prev = _context10.next) {
655
684
  case 0:
656
- options = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : {};
657
- traceContext = _args9.length > 3 ? _args9[3] : undefined;
685
+ options = _args10.length > 2 && _args10[2] !== undefined ? _args10[2] : {};
686
+ traceContext = _args10.length > 3 ? _args10[3] : undefined;
658
687
  id = source.id;
659
688
  destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
660
689
  preview = options.preview, mimeType = options.mimeType;
661
690
  cache = getFileStreamsCache();
662
- _context9.prev = 6;
691
+ _context10.prev = 6;
663
692
  if (!(isCopySourceFileWithToken(source) && isCopyDestinationWithToken(destination))) {
664
- _context9.next = 13;
693
+ _context10.next = 13;
665
694
  break;
666
695
  }
667
- _context9.next = 10;
696
+ _context10.next = 10;
668
697
  return this.copyFileWithToken(source, destination, traceContext);
669
698
  case 10:
670
- copiedFile = _context9.sent;
671
- _context9.next = 16;
699
+ copiedFile = _context10.sent;
700
+ _context10.next = 16;
672
701
  break;
673
702
  case 13:
674
- _context9.next = 15;
703
+ _context10.next = 15;
675
704
  return this.copyFileWithIntent(source, destination, traceContext);
676
705
  case 15:
677
- copiedFile = _context9.sent;
706
+ copiedFile = _context10.sent;
678
707
  case 16:
679
708
  // if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
680
709
  copiedFileWithMimeType = _objectSpread(_objectSpread({}, copiedFile), mimeType ? {
@@ -691,21 +720,21 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
691
720
  previewOverride = !isErrorFileState(copiedFileState) && !!preview ? {
692
721
  preview: preview
693
722
  } : {};
694
- _context9.t0 = !isFinalFileState(copiedFileState) &&
723
+ _context10.t0 = !isFinalFileState(copiedFileState) &&
695
724
  // mimeType should always be returned by "copyFileWithToken"
696
725
  // but in case it's not, we don't want to penalize "copyFile"
697
726
  copiedMimeType;
698
- if (!_context9.t0) {
699
- _context9.next = 28;
727
+ if (!_context10.t0) {
728
+ _context10.next = 28;
700
729
  break;
701
730
  }
702
- _context9.next = 27;
731
+ _context10.next = 27;
703
732
  return shouldFetchRemoteFileStates(mediaType, copiedMimeType, preview);
704
733
  case 27:
705
- _context9.t0 = _context9.sent;
734
+ _context10.t0 = _context10.sent;
706
735
  case 28:
707
- if (!_context9.t0) {
708
- _context9.next = 35;
736
+ if (!_context10.t0) {
737
+ _context10.next = 35;
709
738
  break;
710
739
  }
711
740
  fileState = _objectSpread(_objectSpread(_objectSpread({}, copiedFileState), overrideMediaTypeIfUnknown(copiedFileState, mediaType)), previewOverride);
@@ -726,7 +755,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
726
755
  return subject.complete();
727
756
  }
728
757
  });
729
- _context9.next = 36;
758
+ _context10.next = 36;
730
759
  break;
731
760
  case 35:
732
761
  if (!isProcessingFileState(copiedFileState)) {
@@ -738,10 +767,10 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
738
767
  if (!cache.has(copiedId)) {
739
768
  getFileStreamsCache().set(copiedId, subject);
740
769
  }
741
- return _context9.abrupt("return", copiedFile);
770
+ return _context10.abrupt("return", copiedFile);
742
771
  case 40:
743
- _context9.prev = 40;
744
- _context9.t1 = _context9["catch"](6);
772
+ _context10.prev = 40;
773
+ _context10.t1 = _context10["catch"](6);
745
774
  if (processingSubscription) {
746
775
  processingSubscription.unsubscribe();
747
776
  }
@@ -749,23 +778,23 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
749
778
  _fileCache = cache.get(replaceFileId);
750
779
  replaceFileState = this.store.getState().files[replaceFileId];
751
780
  if (_fileCache) {
752
- _fileCache.error(_context9.t1);
781
+ _fileCache.error(_context10.t1);
753
782
  } else {
754
783
  // Create a new subject with the error state for new subscriptions
755
- cache.set(id, createMediaSubject(_context9.t1));
784
+ cache.set(id, createMediaSubject(_context10.t1));
756
785
  }
757
786
  key = replaceFileState ? replaceFileId : id;
758
- errorFileState = this.getErrorFileState(_context9.t1, id, occurrenceKey);
787
+ errorFileState = this.getErrorFileState(_context10.t1, id, occurrenceKey);
759
788
  this.setFileState(key, errorFileState);
760
789
  }
761
- throw _context9.t1;
790
+ throw _context10.t1;
762
791
  case 45:
763
792
  case "end":
764
- return _context9.stop();
793
+ return _context10.stop();
765
794
  }
766
- }, _callee9, this, [[6, 40]]);
795
+ }, _callee10, this, [[6, 40]]);
767
796
  }));
768
- function copyFile(_x17, _x18) {
797
+ function copyFile(_x22, _x23) {
769
798
  return _copyFile.apply(this, arguments);
770
799
  }
771
800
  return copyFile;