@atlaskit/media-client 20.2.1 → 21.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.
Files changed (91) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/cjs/client/file-fetcher/error.js +4 -4
  3. package/dist/cjs/client/file-fetcher/index.js +275 -287
  4. package/dist/cjs/client/media-client.js +48 -34
  5. package/dist/cjs/client/media-store/index.js +367 -314
  6. package/dist/cjs/client/media-store/resolveAuth.js +30 -32
  7. package/dist/cjs/client/stargate-client.js +14 -16
  8. package/dist/cjs/index.js +6 -13
  9. package/dist/cjs/models/media.js +8 -9
  10. package/dist/cjs/uploader/error.js +4 -4
  11. package/dist/cjs/uploader/index.js +88 -96
  12. package/dist/cjs/utils/convertBase64ToBlob.js +2 -2
  13. package/dist/cjs/utils/createFileDataLoader.js +67 -70
  14. package/dist/cjs/utils/getDimensionsFromBlob.js +23 -25
  15. package/dist/cjs/utils/getVideoDimensionsFromBlob.js +24 -26
  16. package/dist/cjs/utils/hashing/hasherCreator.js +32 -34
  17. package/dist/cjs/utils/mediaSubscribable/fromObservable.js +2 -2
  18. package/dist/cjs/utils/mobileUpload/error.js +4 -4
  19. package/dist/cjs/utils/mobileUpload/helpers.js +41 -43
  20. package/dist/cjs/utils/mobileUpload/stateMachine/index.js +14 -16
  21. package/dist/cjs/utils/parseJwt.js +52 -0
  22. package/dist/cjs/utils/polling/index.js +40 -42
  23. package/dist/cjs/utils/request/errors.js +9 -9
  24. package/dist/cjs/utils/request/helpers.js +143 -155
  25. package/dist/cjs/utils/request/index.js +24 -26
  26. package/dist/cjs/utils/shouldFetchRemoteFileStates.js +39 -41
  27. package/dist/cjs/version.json +1 -1
  28. package/dist/es2019/client/file-fetcher/index.js +1 -3
  29. package/dist/es2019/client/media-client.js +3 -2
  30. package/dist/es2019/client/media-store/index.js +58 -15
  31. package/dist/es2019/index.js +2 -3
  32. package/dist/es2019/models/media.js +6 -4
  33. package/dist/es2019/uploader/index.js +3 -0
  34. package/dist/es2019/utils/mediaSubscribable/fromObservable.js +2 -2
  35. package/dist/es2019/utils/mediaSubscribable/toPromise.js +10 -12
  36. package/dist/es2019/utils/parseJwt.js +46 -0
  37. package/dist/es2019/version.json +1 -1
  38. package/dist/esm/client/file-fetcher/error.js +4 -4
  39. package/dist/esm/client/file-fetcher/index.js +273 -286
  40. package/dist/esm/client/media-client.js +46 -32
  41. package/dist/esm/client/media-store/index.js +367 -314
  42. package/dist/esm/client/media-store/resolveAuth.js +30 -32
  43. package/dist/esm/client/stargate-client.js +14 -16
  44. package/dist/esm/index.js +2 -3
  45. package/dist/esm/models/media.js +6 -6
  46. package/dist/esm/uploader/error.js +4 -4
  47. package/dist/esm/uploader/index.js +89 -96
  48. package/dist/esm/utils/convertBase64ToBlob.js +2 -2
  49. package/dist/esm/utils/createFileDataLoader.js +65 -69
  50. package/dist/esm/utils/getDimensionsFromBlob.js +23 -25
  51. package/dist/esm/utils/getVideoDimensionsFromBlob.js +24 -26
  52. package/dist/esm/utils/hashing/hasherCreator.js +28 -30
  53. package/dist/esm/utils/mediaSubscribable/fromObservable.js +2 -2
  54. package/dist/esm/utils/mobileUpload/error.js +4 -4
  55. package/dist/esm/utils/mobileUpload/helpers.js +41 -43
  56. package/dist/esm/utils/mobileUpload/stateMachine/index.js +14 -16
  57. package/dist/esm/utils/parseJwt.js +46 -0
  58. package/dist/esm/utils/polling/index.js +40 -42
  59. package/dist/esm/utils/request/errors.js +9 -9
  60. package/dist/esm/utils/request/helpers.js +143 -155
  61. package/dist/esm/utils/request/index.js +24 -26
  62. package/dist/esm/utils/shouldFetchRemoteFileStates.js +39 -41
  63. package/dist/esm/version.json +1 -1
  64. package/dist/types/client/__mocks__/media-client.d.ts +0 -2
  65. package/dist/types/client/file-fetcher/index.d.ts +4 -4
  66. package/dist/types/client/media-client.d.ts +1 -2
  67. package/dist/types/client/media-store/index.d.ts +17 -13
  68. package/dist/types/index.d.ts +4 -6
  69. package/dist/types/models/file-state.d.ts +2 -2
  70. package/dist/types/models/media.d.ts +1 -21
  71. package/dist/types/utils/createFileDataLoader.d.ts +2 -2
  72. package/dist/types/utils/createMediaSubject.d.ts +2 -2
  73. package/dist/types/utils/detectEmptyFile.d.ts +2 -2
  74. package/dist/types/utils/mediaSubscribable/fromObservable.d.ts +3 -3
  75. package/dist/types/utils/mediaSubscribable/toPromise.d.ts +2 -2
  76. package/dist/types/utils/mediaSubscribable/types.d.ts +9 -8
  77. package/dist/types/utils/parseJwt.d.ts +1 -0
  78. package/package.json +2 -2
  79. package/report.api.md +77 -126
  80. package/dist/cjs/client/collection-fetcher.js +0 -98
  81. package/dist/cjs/models/media-subscribable.js +0 -5
  82. package/dist/cjs/utils/deprecatedEndpointError.js +0 -43
  83. package/dist/es2019/client/collection-fetcher.js +0 -38
  84. package/dist/es2019/models/media-subscribable.js +0 -1
  85. package/dist/es2019/utils/deprecatedEndpointError.js +0 -20
  86. package/dist/esm/client/collection-fetcher.js +0 -89
  87. package/dist/esm/models/media-subscribable.js +0 -1
  88. package/dist/esm/utils/deprecatedEndpointError.js +0 -34
  89. package/dist/types/client/collection-fetcher.d.ts +0 -42
  90. package/dist/types/models/media-subscribable.d.ts +0 -3
  91. package/dist/types/utils/deprecatedEndpointError.d.ts +0 -16
@@ -40,6 +40,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
40
40
  function FileFetcherImpl(mediaStore, featureFlags) {
41
41
  var _this = this;
42
42
  _classCallCheck(this, FileFetcherImpl);
43
+ // TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
43
44
  _defineProperty(this, "createDownloadFileStream", function (id, collectionName, occurrenceKey) {
44
45
  var subject = createMediaSubject();
45
46
  var poll = new PollingFunction();
@@ -51,50 +52,48 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
51
52
  poll.execute( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
52
53
  var response, fileState;
53
54
  return _regeneratorRuntime.wrap(function _callee$(_context) {
54
- while (1) {
55
- switch (_context.prev = _context.next) {
56
- case 0:
57
- _context.next = 2;
58
- return _this.dataloader.load({
59
- id: id,
60
- collectionName: collectionName
61
- });
62
- case 2:
63
- response = _context.sent;
64
- if (response) {
65
- _context.next = 5;
66
- break;
67
- }
68
- throw new FileFetcherError('emptyItems', id, {
69
- collectionName: collectionName,
70
- occurrenceKey: occurrenceKey
71
- });
72
- case 5:
73
- if (!isEmptyFile(response)) {
74
- _context.next = 7;
75
- break;
76
- }
77
- throw new FileFetcherError('zeroVersionFile', id, {
78
- collectionName: collectionName,
79
- occurrenceKey: occurrenceKey
80
- });
81
- case 7:
82
- fileState = mapMediaItemToFileState(id, response);
83
- subject.next(fileState);
84
- _context.t0 = fileState.status;
85
- _context.next = _context.t0 === 'processing' ? 12 : _context.t0 === 'processed' ? 14 : 16;
55
+ while (1) switch (_context.prev = _context.next) {
56
+ case 0:
57
+ _context.next = 2;
58
+ return _this.dataloader.load({
59
+ id: id,
60
+ collectionName: collectionName
61
+ });
62
+ case 2:
63
+ response = _context.sent;
64
+ if (response) {
65
+ _context.next = 5;
86
66
  break;
87
- case 12:
88
- // the only case for continuing polling, otherwise this function is run once only
89
- poll.next();
90
- return _context.abrupt("break", 16);
91
- case 14:
92
- subject.complete();
93
- return _context.abrupt("break", 16);
94
- case 16:
95
- case "end":
96
- return _context.stop();
97
- }
67
+ }
68
+ throw new FileFetcherError('emptyItems', id, {
69
+ collectionName: collectionName,
70
+ occurrenceKey: occurrenceKey
71
+ });
72
+ case 5:
73
+ if (!isEmptyFile(response)) {
74
+ _context.next = 7;
75
+ break;
76
+ }
77
+ throw new FileFetcherError('zeroVersionFile', id, {
78
+ collectionName: collectionName,
79
+ occurrenceKey: occurrenceKey
80
+ });
81
+ case 7:
82
+ fileState = mapMediaItemToFileState(id, response);
83
+ subject.next(fileState);
84
+ _context.t0 = fileState.status;
85
+ _context.next = _context.t0 === 'processing' ? 12 : _context.t0 === 'processed' ? 14 : 16;
86
+ break;
87
+ case 12:
88
+ // the only case for continuing polling, otherwise this function is run once only
89
+ poll.next();
90
+ return _context.abrupt("break", 16);
91
+ case 14:
92
+ subject.complete();
93
+ return _context.abrupt("break", 16);
94
+ case 16:
95
+ case "end":
96
+ return _context.stop();
98
97
  }
99
98
  }, _callee);
100
99
  })));
@@ -173,8 +172,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
173
172
  value: function getFileBinaryURL(id, collectionName) {
174
173
  return this.mediaStore.getFileBinaryURL(id, collectionName);
175
174
  }
176
-
177
- // TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
178
175
  }, {
179
176
  key: "touchFiles",
180
177
  value: function touchFiles(descriptors, collection, traceContext) {
@@ -213,120 +210,114 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
213
210
  var _this3 = this;
214
211
  var uploadableFileUpfrontIds, id, occurrenceKey, subject, deferredBlob, preview, name, fileState;
215
212
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
216
- while (1) {
217
- switch (_context4.prev = _context4.next) {
218
- case 0:
219
- uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
220
- id = uploadableFileUpfrontIds.id, occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
221
- subject = createMediaSubject();
222
- deferredBlob = fetch(url).then(function (response) {
223
- return response.blob();
224
- }).catch(function () {
225
- return undefined;
226
- });
227
- preview = new Promise( /*#__PURE__*/function () {
228
- var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resolve, reject) {
229
- var blob;
230
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
231
- while (1) {
232
- switch (_context2.prev = _context2.next) {
233
- case 0:
234
- _context2.next = 2;
235
- return deferredBlob;
236
- case 2:
237
- blob = _context2.sent;
238
- if (!blob) {
239
- reject('Could not fetch the blob');
240
- }
241
- resolve({
242
- value: blob,
243
- origin: 'remote'
244
- });
245
- case 5:
246
- case "end":
247
- return _context2.stop();
213
+ while (1) switch (_context4.prev = _context4.next) {
214
+ case 0:
215
+ uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
216
+ id = uploadableFileUpfrontIds.id, occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
217
+ subject = createMediaSubject();
218
+ deferredBlob = fetch(url).then(function (response) {
219
+ return response.blob();
220
+ }).catch(function () {
221
+ return undefined;
222
+ });
223
+ preview = new Promise( /*#__PURE__*/function () {
224
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resolve, reject) {
225
+ var blob;
226
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
227
+ while (1) switch (_context2.prev = _context2.next) {
228
+ case 0:
229
+ _context2.next = 2;
230
+ return deferredBlob;
231
+ case 2:
232
+ blob = _context2.sent;
233
+ if (!blob) {
234
+ reject('Could not fetch the blob');
248
235
  }
249
- }
250
- }, _callee2);
251
- }));
252
- return function (_x4, _x5) {
253
- return _ref3.apply(this, arguments);
254
- };
255
- }());
256
- name = url.split('/').pop() || ''; // we create a initial fileState with the minimum info that we have at this point
257
- fileState = {
258
- status: 'processing',
259
- name: name,
260
- size: 0,
261
- mediaType: 'unknown',
262
- mimeType: '',
263
- id: id,
264
- occurrenceKey: occurrenceKey,
265
- preview: preview
236
+ resolve({
237
+ value: blob,
238
+ origin: 'remote'
239
+ });
240
+ case 5:
241
+ case "end":
242
+ return _context2.stop();
243
+ }
244
+ }, _callee2);
245
+ }));
246
+ return function (_x4, _x5) {
247
+ return _ref3.apply(this, arguments);
266
248
  };
267
- subject.next(fileState);
268
- // we save it into the cache as soon as possible, in case someone subscribes
269
- getFileStreamsCache().set(id, subject);
270
- return _context4.abrupt("return", new Promise( /*#__PURE__*/function () {
271
- var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resolve, reject) {
272
- var blob, type, size, file, mediaType, dimensions;
273
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
274
- while (1) {
275
- switch (_context3.prev = _context3.next) {
276
- case 0:
277
- _context3.next = 2;
278
- return deferredBlob;
279
- case 2:
280
- blob = _context3.sent;
281
- if (blob) {
282
- _context3.next = 5;
283
- break;
284
- }
285
- return _context3.abrupt("return", reject('Could not download remote file'));
286
- case 5:
287
- type = blob.type, size = blob.size;
288
- file = {
289
- content: blob,
290
- mimeType: type,
291
- collection: collection,
292
- name: name
293
- };
294
- mediaType = getMediaTypeFromMimeType(type); // we emit a richer state after the blob is fetched
295
- subject.next({
296
- status: 'processing',
297
- name: name,
298
- size: size,
299
- mediaType: mediaType,
300
- mimeType: type,
301
- id: id,
302
- occurrenceKey: occurrenceKey,
303
- preview: preview
304
- });
305
- // we don't want to wait for the file to be upload
306
- _this3.upload(file, undefined, uploadableFileUpfrontIds, traceContext);
307
- _context3.next = 12;
308
- return getDimensionsFromBlob(mediaType, blob);
309
- case 12:
310
- dimensions = _context3.sent;
311
- resolve({
312
- dimensions: dimensions,
313
- uploadableFileUpfrontIds: uploadableFileUpfrontIds
314
- });
315
- case 14:
316
- case "end":
317
- return _context3.stop();
249
+ }());
250
+ name = url.split('/').pop() || ''; // we create a initial fileState with the minimum info that we have at this point
251
+ fileState = {
252
+ status: 'processing',
253
+ name: name,
254
+ size: 0,
255
+ mediaType: 'unknown',
256
+ mimeType: '',
257
+ id: id,
258
+ occurrenceKey: occurrenceKey,
259
+ preview: preview
260
+ };
261
+ subject.next(fileState);
262
+ // we save it into the cache as soon as possible, in case someone subscribes
263
+ getFileStreamsCache().set(id, subject);
264
+ return _context4.abrupt("return", new Promise( /*#__PURE__*/function () {
265
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resolve, reject) {
266
+ var blob, type, size, file, mediaType, dimensions;
267
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
268
+ while (1) switch (_context3.prev = _context3.next) {
269
+ case 0:
270
+ _context3.next = 2;
271
+ return deferredBlob;
272
+ case 2:
273
+ blob = _context3.sent;
274
+ if (blob) {
275
+ _context3.next = 5;
276
+ break;
318
277
  }
319
- }
320
- }, _callee3);
321
- }));
322
- return function (_x6, _x7) {
323
- return _ref4.apply(this, arguments);
324
- };
325
- }()));
326
- case 10:
327
- case "end":
328
- return _context4.stop();
329
- }
278
+ return _context3.abrupt("return", reject('Could not download remote file'));
279
+ case 5:
280
+ type = blob.type, size = blob.size;
281
+ file = {
282
+ content: blob,
283
+ mimeType: type,
284
+ collection: collection,
285
+ name: name
286
+ };
287
+ mediaType = getMediaTypeFromMimeType(type); // we emit a richer state after the blob is fetched
288
+ subject.next({
289
+ status: 'processing',
290
+ name: name,
291
+ size: size,
292
+ mediaType: mediaType,
293
+ mimeType: type,
294
+ id: id,
295
+ occurrenceKey: occurrenceKey,
296
+ preview: preview
297
+ });
298
+ // we don't want to wait for the file to be upload
299
+ _this3.upload(file, undefined, uploadableFileUpfrontIds, traceContext);
300
+ _context3.next = 12;
301
+ return getDimensionsFromBlob(mediaType, blob);
302
+ case 12:
303
+ dimensions = _context3.sent;
304
+ resolve({
305
+ dimensions: dimensions,
306
+ uploadableFileUpfrontIds: uploadableFileUpfrontIds
307
+ });
308
+ case 14:
309
+ case "end":
310
+ return _context3.stop();
311
+ }
312
+ }, _callee3);
313
+ }));
314
+ return function (_x6, _x7) {
315
+ return _ref4.apply(this, arguments);
316
+ };
317
+ }()));
318
+ case 10:
319
+ case "end":
320
+ return _context4.stop();
330
321
  }
331
322
  }, _callee4, this);
332
323
  }));
@@ -486,27 +477,25 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
486
477
  url,
487
478
  _args5 = arguments;
488
479
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
489
- while (1) {
490
- switch (_context5.prev = _context5.next) {
491
- case 0:
492
- name = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : 'download';
493
- collectionName = _args5.length > 2 ? _args5[2] : undefined;
494
- _context5.next = 4;
495
- return this.mediaStore.getFileBinaryURL(id, collectionName);
496
- case 4:
497
- url = _context5.sent;
498
- downloadUrl(url, {
499
- name: name
500
- });
501
- globalMediaEventEmitter.emit('media-viewed', {
502
- fileId: id,
503
- isUserCollection: collectionName === RECENTS_COLLECTION,
504
- viewingLevel: 'download'
505
- });
506
- case 7:
507
- case "end":
508
- return _context5.stop();
509
- }
480
+ while (1) switch (_context5.prev = _context5.next) {
481
+ case 0:
482
+ name = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : 'download';
483
+ collectionName = _args5.length > 2 ? _args5[2] : undefined;
484
+ _context5.next = 4;
485
+ return this.mediaStore.getFileBinaryURL(id, collectionName);
486
+ case 4:
487
+ url = _context5.sent;
488
+ downloadUrl(url, {
489
+ name: name
490
+ });
491
+ globalMediaEventEmitter.emit('media-viewed', {
492
+ fileId: id,
493
+ isUserCollection: collectionName === RECENTS_COLLECTION,
494
+ viewingLevel: 'download'
495
+ });
496
+ case 7:
497
+ case "end":
498
+ return _context5.stop();
510
499
  }
511
500
  }, _callee5, this);
512
501
  }));
@@ -549,119 +538,117 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
549
538
  _fileCache,
550
539
  _args6 = arguments;
551
540
  return _regeneratorRuntime.wrap(function _callee6$(_context6) {
552
- while (1) {
553
- switch (_context6.prev = _context6.next) {
554
- case 0:
555
- options = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {};
556
- traceContext = _args6.length > 3 ? _args6[3] : undefined;
557
- authProvider = source.authProvider, sourceCollection = source.collection, id = source.id;
558
- destinationAuthProvider = destination.authProvider, destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
559
- preview = options.preview, mimeType = options.mimeType;
560
- mediaStore = destination.mediaStore || new MediaStore({
561
- authProvider: destinationAuthProvider
562
- });
563
- _context6.t0 = authToOwner;
564
- _context6.next = 9;
565
- return authProvider({
566
- collectionName: sourceCollection
567
- });
568
- case 9:
569
- _context6.t1 = _context6.sent;
570
- owner = (0, _context6.t0)(_context6.t1);
571
- body = {
572
- sourceFile: {
573
- id: id,
574
- collection: sourceCollection,
575
- owner: owner
576
- }
577
- };
578
- params = {
579
- collection: destinationCollectionName,
580
- replaceFileId: replaceFileId,
581
- occurrenceKey: occurrenceKey
582
- };
583
- cache = getFileStreamsCache();
584
- _context6.prev = 14;
585
- _context6.next = 17;
586
- return mediaStore.copyFileWithToken(body, params, traceContext);
587
- case 17:
588
- _yield$mediaStore$cop = _context6.sent;
589
- copiedFile = _yield$mediaStore$cop.data;
590
- // if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
591
- copiedFileWithMimeType = _objectSpread(_objectSpread({}, copiedFile), mimeType ? {
592
- mimeType: mimeType
593
- } : undefined);
594
- copiedId = copiedFileWithMimeType.id, copiedMimeType = copiedFileWithMimeType.mimeType; // backend may return an "unknown" mediaType just after the copy
595
- // it's better to deduce it from "copiedMimeType" using getMediaTypeFromMimeType()
596
- mediaType = copiedMimeType ? getMediaTypeFromMimeType(copiedMimeType) : 'unknown';
597
- copiedFileState = mapMediaFileToFileState({
598
- data: copiedFileWithMimeType
599
- });
600
- fileCache = cache.get(copiedId);
601
- subject = fileCache || createMediaSubject(); // if we were passed a "preview", we propagate it into the copiedFileState
602
- previewOverride = !isErrorFileState(copiedFileState) && !!preview ? {
603
- preview: preview
604
- } : {};
605
- _context6.t2 = !isFinalFileState(copiedFileState) &&
606
- // mimeType should always be returned by "copyFileWithToken"
607
- // but in case it's not, we don't want to penalize "copyFile"
608
- copiedMimeType;
609
- if (!_context6.t2) {
610
- _context6.next = 31;
611
- break;
612
- }
613
- _context6.next = 30;
614
- return shouldFetchRemoteFileStates(mediaType, copiedMimeType, preview);
615
- case 30:
616
- _context6.t2 = _context6.sent;
617
- case 31:
618
- if (!_context6.t2) {
619
- _context6.next = 36;
620
- break;
541
+ while (1) switch (_context6.prev = _context6.next) {
542
+ case 0:
543
+ options = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {};
544
+ traceContext = _args6.length > 3 ? _args6[3] : undefined;
545
+ authProvider = source.authProvider, sourceCollection = source.collection, id = source.id;
546
+ destinationAuthProvider = destination.authProvider, destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
547
+ preview = options.preview, mimeType = options.mimeType;
548
+ mediaStore = destination.mediaStore || new MediaStore({
549
+ authProvider: destinationAuthProvider
550
+ });
551
+ _context6.t0 = authToOwner;
552
+ _context6.next = 9;
553
+ return authProvider({
554
+ collectionName: sourceCollection
555
+ });
556
+ case 9:
557
+ _context6.t1 = _context6.sent;
558
+ owner = (0, _context6.t0)(_context6.t1);
559
+ body = {
560
+ sourceFile: {
561
+ id: id,
562
+ collection: sourceCollection,
563
+ owner: owner
621
564
  }
622
- subject.next(_objectSpread(_objectSpread(_objectSpread({}, copiedFileState), overrideMediaTypeIfUnknown(copiedFileState, mediaType)), previewOverride));
623
- processingSubscription = this.createDownloadFileStream(copiedId, destinationCollectionName, occurrenceKey).subscribe({
624
- next: function next(remoteFileState) {
625
- return subject.next(_objectSpread(_objectSpread(_objectSpread({}, remoteFileState), overrideMediaTypeIfUnknown(remoteFileState, mediaType)), !isErrorFileState(remoteFileState) && previewOverride));
626
- },
627
- error: function error(err) {
628
- return subject.error(err);
629
- },
630
- complete: function complete() {
631
- return subject.complete();
632
- }
633
- });
634
- _context6.next = 37;
565
+ };
566
+ params = {
567
+ collection: destinationCollectionName,
568
+ replaceFileId: replaceFileId,
569
+ occurrenceKey: occurrenceKey
570
+ };
571
+ cache = getFileStreamsCache();
572
+ _context6.prev = 14;
573
+ _context6.next = 17;
574
+ return mediaStore.copyFileWithToken(body, params, traceContext);
575
+ case 17:
576
+ _yield$mediaStore$cop = _context6.sent;
577
+ copiedFile = _yield$mediaStore$cop.data;
578
+ // if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
579
+ copiedFileWithMimeType = _objectSpread(_objectSpread({}, copiedFile), mimeType ? {
580
+ mimeType: mimeType
581
+ } : undefined);
582
+ copiedId = copiedFileWithMimeType.id, copiedMimeType = copiedFileWithMimeType.mimeType; // backend may return an "unknown" mediaType just after the copy
583
+ // it's better to deduce it from "copiedMimeType" using getMediaTypeFromMimeType()
584
+ mediaType = copiedMimeType ? getMediaTypeFromMimeType(copiedMimeType) : 'unknown';
585
+ copiedFileState = mapMediaFileToFileState({
586
+ data: copiedFileWithMimeType
587
+ });
588
+ fileCache = cache.get(copiedId);
589
+ subject = fileCache || createMediaSubject(); // if we were passed a "preview", we propagate it into the copiedFileState
590
+ previewOverride = !isErrorFileState(copiedFileState) && !!preview ? {
591
+ preview: preview
592
+ } : {};
593
+ _context6.t2 = !isFinalFileState(copiedFileState) &&
594
+ // mimeType should always be returned by "copyFileWithToken"
595
+ // but in case it's not, we don't want to penalize "copyFile"
596
+ copiedMimeType;
597
+ if (!_context6.t2) {
598
+ _context6.next = 31;
635
599
  break;
636
- case 36:
637
- if (!isProcessingFileState(copiedFileState)) {
638
- subject.next(_objectSpread(_objectSpread({}, copiedFileState), !isErrorFileState(copiedFileState) && previewOverride));
639
- }
640
- case 37:
641
- if (!cache.has(copiedId)) {
642
- getFileStreamsCache().set(copiedId, subject);
643
- }
644
- return _context6.abrupt("return", copiedFile);
645
- case 41:
646
- _context6.prev = 41;
647
- _context6.t3 = _context6["catch"](14);
648
- if (processingSubscription) {
649
- processingSubscription.unsubscribe();
600
+ }
601
+ _context6.next = 30;
602
+ return shouldFetchRemoteFileStates(mediaType, copiedMimeType, preview);
603
+ case 30:
604
+ _context6.t2 = _context6.sent;
605
+ case 31:
606
+ if (!_context6.t2) {
607
+ _context6.next = 36;
608
+ break;
609
+ }
610
+ subject.next(_objectSpread(_objectSpread(_objectSpread({}, copiedFileState), overrideMediaTypeIfUnknown(copiedFileState, mediaType)), previewOverride));
611
+ processingSubscription = this.createDownloadFileStream(copiedId, destinationCollectionName, occurrenceKey).subscribe({
612
+ next: function next(remoteFileState) {
613
+ return subject.next(_objectSpread(_objectSpread(_objectSpread({}, remoteFileState), overrideMediaTypeIfUnknown(remoteFileState, mediaType)), !isErrorFileState(remoteFileState) && previewOverride));
614
+ },
615
+ error: function error(err) {
616
+ return subject.error(err);
617
+ },
618
+ complete: function complete() {
619
+ return subject.complete();
650
620
  }
651
- if (replaceFileId) {
652
- _fileCache = cache.get(replaceFileId);
653
- if (_fileCache) {
654
- _fileCache.error(_context6.t3);
655
- } else {
656
- // Create a new subject with the error state for new subscriptions
657
- cache.set(id, createMediaSubject(_context6.t3));
658
- }
621
+ });
622
+ _context6.next = 37;
623
+ break;
624
+ case 36:
625
+ if (!isProcessingFileState(copiedFileState)) {
626
+ subject.next(_objectSpread(_objectSpread({}, copiedFileState), !isErrorFileState(copiedFileState) && previewOverride));
627
+ }
628
+ case 37:
629
+ if (!cache.has(copiedId)) {
630
+ getFileStreamsCache().set(copiedId, subject);
631
+ }
632
+ return _context6.abrupt("return", copiedFile);
633
+ case 41:
634
+ _context6.prev = 41;
635
+ _context6.t3 = _context6["catch"](14);
636
+ if (processingSubscription) {
637
+ processingSubscription.unsubscribe();
638
+ }
639
+ if (replaceFileId) {
640
+ _fileCache = cache.get(replaceFileId);
641
+ if (_fileCache) {
642
+ _fileCache.error(_context6.t3);
643
+ } else {
644
+ // Create a new subject with the error state for new subscriptions
645
+ cache.set(id, createMediaSubject(_context6.t3));
659
646
  }
660
- throw _context6.t3;
661
- case 46:
662
- case "end":
663
- return _context6.stop();
664
- }
647
+ }
648
+ throw _context6.t3;
649
+ case 46:
650
+ case "end":
651
+ return _context6.stop();
665
652
  }
666
653
  }, _callee6, this, [[14, 41]]);
667
654
  }));