@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
@@ -51,11 +51,13 @@ var _polling = require("../../utils/polling");
51
51
  var _detectEmptyFile = require("../../utils/detectEmptyFile");
52
52
  var _mediaCommon = require("@atlaskit/media-common");
53
53
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
54
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
54
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } // import setimmediate to temporary fix dataloader 2.0.0 bug
55
+ // @see https://github.com/graphql/dataloader/issues/249
55
56
  var FileFetcherImpl = /*#__PURE__*/function () {
56
57
  function FileFetcherImpl(mediaStore, featureFlags) {
57
58
  var _this = this;
58
59
  (0, _classCallCheck2.default)(this, FileFetcherImpl);
60
+ // TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
59
61
  (0, _defineProperty2.default)(this, "createDownloadFileStream", function (id, collectionName, occurrenceKey) {
60
62
  var subject = (0, _createMediaSubject.createMediaSubject)();
61
63
  var poll = new _polling.PollingFunction();
@@ -67,50 +69,48 @@ var FileFetcherImpl = /*#__PURE__*/function () {
67
69
  poll.execute( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
68
70
  var response, fileState;
69
71
  return _regenerator.default.wrap(function _callee$(_context) {
70
- while (1) {
71
- switch (_context.prev = _context.next) {
72
- case 0:
73
- _context.next = 2;
74
- return _this.dataloader.load({
75
- id: id,
76
- collectionName: collectionName
77
- });
78
- case 2:
79
- response = _context.sent;
80
- if (response) {
81
- _context.next = 5;
82
- break;
83
- }
84
- throw new _error.FileFetcherError('emptyItems', id, {
85
- collectionName: collectionName,
86
- occurrenceKey: occurrenceKey
87
- });
88
- case 5:
89
- if (!(0, _detectEmptyFile.isEmptyFile)(response)) {
90
- _context.next = 7;
91
- break;
92
- }
93
- throw new _error.FileFetcherError('zeroVersionFile', id, {
94
- collectionName: collectionName,
95
- occurrenceKey: occurrenceKey
96
- });
97
- case 7:
98
- fileState = (0, _fileState.mapMediaItemToFileState)(id, response);
99
- subject.next(fileState);
100
- _context.t0 = fileState.status;
101
- _context.next = _context.t0 === 'processing' ? 12 : _context.t0 === 'processed' ? 14 : 16;
72
+ while (1) switch (_context.prev = _context.next) {
73
+ case 0:
74
+ _context.next = 2;
75
+ return _this.dataloader.load({
76
+ id: id,
77
+ collectionName: collectionName
78
+ });
79
+ case 2:
80
+ response = _context.sent;
81
+ if (response) {
82
+ _context.next = 5;
102
83
  break;
103
- case 12:
104
- // the only case for continuing polling, otherwise this function is run once only
105
- poll.next();
106
- return _context.abrupt("break", 16);
107
- case 14:
108
- subject.complete();
109
- return _context.abrupt("break", 16);
110
- case 16:
111
- case "end":
112
- return _context.stop();
113
- }
84
+ }
85
+ throw new _error.FileFetcherError('emptyItems', id, {
86
+ collectionName: collectionName,
87
+ occurrenceKey: occurrenceKey
88
+ });
89
+ case 5:
90
+ if (!(0, _detectEmptyFile.isEmptyFile)(response)) {
91
+ _context.next = 7;
92
+ break;
93
+ }
94
+ throw new _error.FileFetcherError('zeroVersionFile', id, {
95
+ collectionName: collectionName,
96
+ occurrenceKey: occurrenceKey
97
+ });
98
+ case 7:
99
+ fileState = (0, _fileState.mapMediaItemToFileState)(id, response);
100
+ subject.next(fileState);
101
+ _context.t0 = fileState.status;
102
+ _context.next = _context.t0 === 'processing' ? 12 : _context.t0 === 'processed' ? 14 : 16;
103
+ break;
104
+ case 12:
105
+ // the only case for continuing polling, otherwise this function is run once only
106
+ poll.next();
107
+ return _context.abrupt("break", 16);
108
+ case 14:
109
+ subject.complete();
110
+ return _context.abrupt("break", 16);
111
+ case 16:
112
+ case "end":
113
+ return _context.stop();
114
114
  }
115
115
  }, _callee);
116
116
  })));
@@ -189,8 +189,6 @@ var FileFetcherImpl = /*#__PURE__*/function () {
189
189
  value: function getFileBinaryURL(id, collectionName) {
190
190
  return this.mediaStore.getFileBinaryURL(id, collectionName);
191
191
  }
192
-
193
- // TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
194
192
  }, {
195
193
  key: "touchFiles",
196
194
  value: function touchFiles(descriptors, collection, traceContext) {
@@ -229,120 +227,114 @@ var FileFetcherImpl = /*#__PURE__*/function () {
229
227
  var _this3 = this;
230
228
  var uploadableFileUpfrontIds, id, occurrenceKey, subject, deferredBlob, preview, name, fileState;
231
229
  return _regenerator.default.wrap(function _callee4$(_context4) {
232
- while (1) {
233
- switch (_context4.prev = _context4.next) {
234
- case 0:
235
- uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
236
- id = uploadableFileUpfrontIds.id, occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
237
- subject = (0, _createMediaSubject.createMediaSubject)();
238
- deferredBlob = fetch(url).then(function (response) {
239
- return response.blob();
240
- }).catch(function () {
241
- return undefined;
242
- });
243
- preview = new Promise( /*#__PURE__*/function () {
244
- var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(resolve, reject) {
245
- var blob;
246
- return _regenerator.default.wrap(function _callee2$(_context2) {
247
- while (1) {
248
- switch (_context2.prev = _context2.next) {
249
- case 0:
250
- _context2.next = 2;
251
- return deferredBlob;
252
- case 2:
253
- blob = _context2.sent;
254
- if (!blob) {
255
- reject('Could not fetch the blob');
256
- }
257
- resolve({
258
- value: blob,
259
- origin: 'remote'
260
- });
261
- case 5:
262
- case "end":
263
- return _context2.stop();
230
+ while (1) switch (_context4.prev = _context4.next) {
231
+ case 0:
232
+ uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
233
+ id = uploadableFileUpfrontIds.id, occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
234
+ subject = (0, _createMediaSubject.createMediaSubject)();
235
+ deferredBlob = fetch(url).then(function (response) {
236
+ return response.blob();
237
+ }).catch(function () {
238
+ return undefined;
239
+ });
240
+ preview = new Promise( /*#__PURE__*/function () {
241
+ var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(resolve, reject) {
242
+ var blob;
243
+ return _regenerator.default.wrap(function _callee2$(_context2) {
244
+ while (1) switch (_context2.prev = _context2.next) {
245
+ case 0:
246
+ _context2.next = 2;
247
+ return deferredBlob;
248
+ case 2:
249
+ blob = _context2.sent;
250
+ if (!blob) {
251
+ reject('Could not fetch the blob');
264
252
  }
265
- }
266
- }, _callee2);
267
- }));
268
- return function (_x4, _x5) {
269
- return _ref3.apply(this, arguments);
270
- };
271
- }());
272
- name = url.split('/').pop() || ''; // we create a initial fileState with the minimum info that we have at this point
273
- fileState = {
274
- status: 'processing',
275
- name: name,
276
- size: 0,
277
- mediaType: 'unknown',
278
- mimeType: '',
279
- id: id,
280
- occurrenceKey: occurrenceKey,
281
- preview: preview
253
+ resolve({
254
+ value: blob,
255
+ origin: 'remote'
256
+ });
257
+ case 5:
258
+ case "end":
259
+ return _context2.stop();
260
+ }
261
+ }, _callee2);
262
+ }));
263
+ return function (_x4, _x5) {
264
+ return _ref3.apply(this, arguments);
282
265
  };
283
- subject.next(fileState);
284
- // we save it into the cache as soon as possible, in case someone subscribes
285
- (0, _fileStreamsCache.getFileStreamsCache)().set(id, subject);
286
- return _context4.abrupt("return", new Promise( /*#__PURE__*/function () {
287
- var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(resolve, reject) {
288
- var blob, type, size, file, mediaType, dimensions;
289
- return _regenerator.default.wrap(function _callee3$(_context3) {
290
- while (1) {
291
- switch (_context3.prev = _context3.next) {
292
- case 0:
293
- _context3.next = 2;
294
- return deferredBlob;
295
- case 2:
296
- blob = _context3.sent;
297
- if (blob) {
298
- _context3.next = 5;
299
- break;
300
- }
301
- return _context3.abrupt("return", reject('Could not download remote file'));
302
- case 5:
303
- type = blob.type, size = blob.size;
304
- file = {
305
- content: blob,
306
- mimeType: type,
307
- collection: collection,
308
- name: name
309
- };
310
- mediaType = (0, _mediaTypeUtils.getMediaTypeFromMimeType)(type); // we emit a richer state after the blob is fetched
311
- subject.next({
312
- status: 'processing',
313
- name: name,
314
- size: size,
315
- mediaType: mediaType,
316
- mimeType: type,
317
- id: id,
318
- occurrenceKey: occurrenceKey,
319
- preview: preview
320
- });
321
- // we don't want to wait for the file to be upload
322
- _this3.upload(file, undefined, uploadableFileUpfrontIds, traceContext);
323
- _context3.next = 12;
324
- return (0, _getDimensionsFromBlob.getDimensionsFromBlob)(mediaType, blob);
325
- case 12:
326
- dimensions = _context3.sent;
327
- resolve({
328
- dimensions: dimensions,
329
- uploadableFileUpfrontIds: uploadableFileUpfrontIds
330
- });
331
- case 14:
332
- case "end":
333
- return _context3.stop();
266
+ }());
267
+ name = url.split('/').pop() || ''; // we create a initial fileState with the minimum info that we have at this point
268
+ fileState = {
269
+ status: 'processing',
270
+ name: name,
271
+ size: 0,
272
+ mediaType: 'unknown',
273
+ mimeType: '',
274
+ id: id,
275
+ occurrenceKey: occurrenceKey,
276
+ preview: preview
277
+ };
278
+ subject.next(fileState);
279
+ // we save it into the cache as soon as possible, in case someone subscribes
280
+ (0, _fileStreamsCache.getFileStreamsCache)().set(id, subject);
281
+ return _context4.abrupt("return", new Promise( /*#__PURE__*/function () {
282
+ var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(resolve, reject) {
283
+ var blob, type, size, file, mediaType, dimensions;
284
+ return _regenerator.default.wrap(function _callee3$(_context3) {
285
+ while (1) switch (_context3.prev = _context3.next) {
286
+ case 0:
287
+ _context3.next = 2;
288
+ return deferredBlob;
289
+ case 2:
290
+ blob = _context3.sent;
291
+ if (blob) {
292
+ _context3.next = 5;
293
+ break;
334
294
  }
335
- }
336
- }, _callee3);
337
- }));
338
- return function (_x6, _x7) {
339
- return _ref4.apply(this, arguments);
340
- };
341
- }()));
342
- case 10:
343
- case "end":
344
- return _context4.stop();
345
- }
295
+ return _context3.abrupt("return", reject('Could not download remote file'));
296
+ case 5:
297
+ type = blob.type, size = blob.size;
298
+ file = {
299
+ content: blob,
300
+ mimeType: type,
301
+ collection: collection,
302
+ name: name
303
+ };
304
+ mediaType = (0, _mediaTypeUtils.getMediaTypeFromMimeType)(type); // we emit a richer state after the blob is fetched
305
+ subject.next({
306
+ status: 'processing',
307
+ name: name,
308
+ size: size,
309
+ mediaType: mediaType,
310
+ mimeType: type,
311
+ id: id,
312
+ occurrenceKey: occurrenceKey,
313
+ preview: preview
314
+ });
315
+ // we don't want to wait for the file to be upload
316
+ _this3.upload(file, undefined, uploadableFileUpfrontIds, traceContext);
317
+ _context3.next = 12;
318
+ return (0, _getDimensionsFromBlob.getDimensionsFromBlob)(mediaType, blob);
319
+ case 12:
320
+ dimensions = _context3.sent;
321
+ resolve({
322
+ dimensions: dimensions,
323
+ uploadableFileUpfrontIds: uploadableFileUpfrontIds
324
+ });
325
+ case 14:
326
+ case "end":
327
+ return _context3.stop();
328
+ }
329
+ }, _callee3);
330
+ }));
331
+ return function (_x6, _x7) {
332
+ return _ref4.apply(this, arguments);
333
+ };
334
+ }()));
335
+ case 10:
336
+ case "end":
337
+ return _context4.stop();
346
338
  }
347
339
  }, _callee4, this);
348
340
  }));
@@ -502,27 +494,25 @@ var FileFetcherImpl = /*#__PURE__*/function () {
502
494
  url,
503
495
  _args5 = arguments;
504
496
  return _regenerator.default.wrap(function _callee5$(_context5) {
505
- while (1) {
506
- switch (_context5.prev = _context5.next) {
507
- case 0:
508
- name = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : 'download';
509
- collectionName = _args5.length > 2 ? _args5[2] : undefined;
510
- _context5.next = 4;
511
- return this.mediaStore.getFileBinaryURL(id, collectionName);
512
- case 4:
513
- url = _context5.sent;
514
- (0, _downloadUrl.downloadUrl)(url, {
515
- name: name
516
- });
517
- _globalMediaEventEmitter.globalMediaEventEmitter.emit('media-viewed', {
518
- fileId: id,
519
- isUserCollection: collectionName === _constants.RECENTS_COLLECTION,
520
- viewingLevel: 'download'
521
- });
522
- case 7:
523
- case "end":
524
- return _context5.stop();
525
- }
497
+ while (1) switch (_context5.prev = _context5.next) {
498
+ case 0:
499
+ name = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : 'download';
500
+ collectionName = _args5.length > 2 ? _args5[2] : undefined;
501
+ _context5.next = 4;
502
+ return this.mediaStore.getFileBinaryURL(id, collectionName);
503
+ case 4:
504
+ url = _context5.sent;
505
+ (0, _downloadUrl.downloadUrl)(url, {
506
+ name: name
507
+ });
508
+ _globalMediaEventEmitter.globalMediaEventEmitter.emit('media-viewed', {
509
+ fileId: id,
510
+ isUserCollection: collectionName === _constants.RECENTS_COLLECTION,
511
+ viewingLevel: 'download'
512
+ });
513
+ case 7:
514
+ case "end":
515
+ return _context5.stop();
526
516
  }
527
517
  }, _callee5, this);
528
518
  }));
@@ -565,119 +555,117 @@ var FileFetcherImpl = /*#__PURE__*/function () {
565
555
  _fileCache,
566
556
  _args6 = arguments;
567
557
  return _regenerator.default.wrap(function _callee6$(_context6) {
568
- while (1) {
569
- switch (_context6.prev = _context6.next) {
570
- case 0:
571
- options = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {};
572
- traceContext = _args6.length > 3 ? _args6[3] : undefined;
573
- authProvider = source.authProvider, sourceCollection = source.collection, id = source.id;
574
- destinationAuthProvider = destination.authProvider, destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
575
- preview = options.preview, mimeType = options.mimeType;
576
- mediaStore = destination.mediaStore || new _mediaStore.MediaStore({
577
- authProvider: destinationAuthProvider
578
- });
579
- _context6.t0 = _mediaCore.authToOwner;
580
- _context6.next = 9;
581
- return authProvider({
582
- collectionName: sourceCollection
583
- });
584
- case 9:
585
- _context6.t1 = _context6.sent;
586
- owner = (0, _context6.t0)(_context6.t1);
587
- body = {
588
- sourceFile: {
589
- id: id,
590
- collection: sourceCollection,
591
- owner: owner
592
- }
593
- };
594
- params = {
595
- collection: destinationCollectionName,
596
- replaceFileId: replaceFileId,
597
- occurrenceKey: occurrenceKey
598
- };
599
- cache = (0, _fileStreamsCache.getFileStreamsCache)();
600
- _context6.prev = 14;
601
- _context6.next = 17;
602
- return mediaStore.copyFileWithToken(body, params, traceContext);
603
- case 17:
604
- _yield$mediaStore$cop = _context6.sent;
605
- copiedFile = _yield$mediaStore$cop.data;
606
- // if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
607
- copiedFileWithMimeType = _objectSpread(_objectSpread({}, copiedFile), mimeType ? {
608
- mimeType: mimeType
609
- } : undefined);
610
- copiedId = copiedFileWithMimeType.id, copiedMimeType = copiedFileWithMimeType.mimeType; // backend may return an "unknown" mediaType just after the copy
611
- // it's better to deduce it from "copiedMimeType" using getMediaTypeFromMimeType()
612
- mediaType = copiedMimeType ? (0, _mediaTypeUtils.getMediaTypeFromMimeType)(copiedMimeType) : 'unknown';
613
- copiedFileState = (0, _fileState.mapMediaFileToFileState)({
614
- data: copiedFileWithMimeType
615
- });
616
- fileCache = cache.get(copiedId);
617
- subject = fileCache || (0, _createMediaSubject.createMediaSubject)(); // if we were passed a "preview", we propagate it into the copiedFileState
618
- previewOverride = !(0, _fileState.isErrorFileState)(copiedFileState) && !!preview ? {
619
- preview: preview
620
- } : {};
621
- _context6.t2 = !(0, _fileState.isFinalFileState)(copiedFileState) &&
622
- // mimeType should always be returned by "copyFileWithToken"
623
- // but in case it's not, we don't want to penalize "copyFile"
624
- copiedMimeType;
625
- if (!_context6.t2) {
626
- _context6.next = 31;
627
- break;
628
- }
629
- _context6.next = 30;
630
- return (0, _shouldFetchRemoteFileStates.shouldFetchRemoteFileStates)(mediaType, copiedMimeType, preview);
631
- case 30:
632
- _context6.t2 = _context6.sent;
633
- case 31:
634
- if (!_context6.t2) {
635
- _context6.next = 36;
636
- break;
558
+ while (1) switch (_context6.prev = _context6.next) {
559
+ case 0:
560
+ options = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {};
561
+ traceContext = _args6.length > 3 ? _args6[3] : undefined;
562
+ authProvider = source.authProvider, sourceCollection = source.collection, id = source.id;
563
+ destinationAuthProvider = destination.authProvider, destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
564
+ preview = options.preview, mimeType = options.mimeType;
565
+ mediaStore = destination.mediaStore || new _mediaStore.MediaStore({
566
+ authProvider: destinationAuthProvider
567
+ });
568
+ _context6.t0 = _mediaCore.authToOwner;
569
+ _context6.next = 9;
570
+ return authProvider({
571
+ collectionName: sourceCollection
572
+ });
573
+ case 9:
574
+ _context6.t1 = _context6.sent;
575
+ owner = (0, _context6.t0)(_context6.t1);
576
+ body = {
577
+ sourceFile: {
578
+ id: id,
579
+ collection: sourceCollection,
580
+ owner: owner
637
581
  }
638
- subject.next(_objectSpread(_objectSpread(_objectSpread({}, copiedFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(copiedFileState, mediaType)), previewOverride));
639
- processingSubscription = this.createDownloadFileStream(copiedId, destinationCollectionName, occurrenceKey).subscribe({
640
- next: function next(remoteFileState) {
641
- return subject.next(_objectSpread(_objectSpread(_objectSpread({}, remoteFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(remoteFileState, mediaType)), !(0, _fileState.isErrorFileState)(remoteFileState) && previewOverride));
642
- },
643
- error: function error(err) {
644
- return subject.error(err);
645
- },
646
- complete: function complete() {
647
- return subject.complete();
648
- }
649
- });
650
- _context6.next = 37;
582
+ };
583
+ params = {
584
+ collection: destinationCollectionName,
585
+ replaceFileId: replaceFileId,
586
+ occurrenceKey: occurrenceKey
587
+ };
588
+ cache = (0, _fileStreamsCache.getFileStreamsCache)();
589
+ _context6.prev = 14;
590
+ _context6.next = 17;
591
+ return mediaStore.copyFileWithToken(body, params, traceContext);
592
+ case 17:
593
+ _yield$mediaStore$cop = _context6.sent;
594
+ copiedFile = _yield$mediaStore$cop.data;
595
+ // if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
596
+ copiedFileWithMimeType = _objectSpread(_objectSpread({}, copiedFile), mimeType ? {
597
+ mimeType: mimeType
598
+ } : undefined);
599
+ copiedId = copiedFileWithMimeType.id, copiedMimeType = copiedFileWithMimeType.mimeType; // backend may return an "unknown" mediaType just after the copy
600
+ // it's better to deduce it from "copiedMimeType" using getMediaTypeFromMimeType()
601
+ mediaType = copiedMimeType ? (0, _mediaTypeUtils.getMediaTypeFromMimeType)(copiedMimeType) : 'unknown';
602
+ copiedFileState = (0, _fileState.mapMediaFileToFileState)({
603
+ data: copiedFileWithMimeType
604
+ });
605
+ fileCache = cache.get(copiedId);
606
+ subject = fileCache || (0, _createMediaSubject.createMediaSubject)(); // if we were passed a "preview", we propagate it into the copiedFileState
607
+ previewOverride = !(0, _fileState.isErrorFileState)(copiedFileState) && !!preview ? {
608
+ preview: preview
609
+ } : {};
610
+ _context6.t2 = !(0, _fileState.isFinalFileState)(copiedFileState) &&
611
+ // mimeType should always be returned by "copyFileWithToken"
612
+ // but in case it's not, we don't want to penalize "copyFile"
613
+ copiedMimeType;
614
+ if (!_context6.t2) {
615
+ _context6.next = 31;
651
616
  break;
652
- case 36:
653
- if (!(0, _fileState.isProcessingFileState)(copiedFileState)) {
654
- subject.next(_objectSpread(_objectSpread({}, copiedFileState), !(0, _fileState.isErrorFileState)(copiedFileState) && previewOverride));
655
- }
656
- case 37:
657
- if (!cache.has(copiedId)) {
658
- (0, _fileStreamsCache.getFileStreamsCache)().set(copiedId, subject);
659
- }
660
- return _context6.abrupt("return", copiedFile);
661
- case 41:
662
- _context6.prev = 41;
663
- _context6.t3 = _context6["catch"](14);
664
- if (processingSubscription) {
665
- processingSubscription.unsubscribe();
617
+ }
618
+ _context6.next = 30;
619
+ return (0, _shouldFetchRemoteFileStates.shouldFetchRemoteFileStates)(mediaType, copiedMimeType, preview);
620
+ case 30:
621
+ _context6.t2 = _context6.sent;
622
+ case 31:
623
+ if (!_context6.t2) {
624
+ _context6.next = 36;
625
+ break;
626
+ }
627
+ subject.next(_objectSpread(_objectSpread(_objectSpread({}, copiedFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(copiedFileState, mediaType)), previewOverride));
628
+ processingSubscription = this.createDownloadFileStream(copiedId, destinationCollectionName, occurrenceKey).subscribe({
629
+ next: function next(remoteFileState) {
630
+ return subject.next(_objectSpread(_objectSpread(_objectSpread({}, remoteFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(remoteFileState, mediaType)), !(0, _fileState.isErrorFileState)(remoteFileState) && previewOverride));
631
+ },
632
+ error: function error(err) {
633
+ return subject.error(err);
634
+ },
635
+ complete: function complete() {
636
+ return subject.complete();
666
637
  }
667
- if (replaceFileId) {
668
- _fileCache = cache.get(replaceFileId);
669
- if (_fileCache) {
670
- _fileCache.error(_context6.t3);
671
- } else {
672
- // Create a new subject with the error state for new subscriptions
673
- cache.set(id, (0, _createMediaSubject.createMediaSubject)(_context6.t3));
674
- }
638
+ });
639
+ _context6.next = 37;
640
+ break;
641
+ case 36:
642
+ if (!(0, _fileState.isProcessingFileState)(copiedFileState)) {
643
+ subject.next(_objectSpread(_objectSpread({}, copiedFileState), !(0, _fileState.isErrorFileState)(copiedFileState) && previewOverride));
644
+ }
645
+ case 37:
646
+ if (!cache.has(copiedId)) {
647
+ (0, _fileStreamsCache.getFileStreamsCache)().set(copiedId, subject);
648
+ }
649
+ return _context6.abrupt("return", copiedFile);
650
+ case 41:
651
+ _context6.prev = 41;
652
+ _context6.t3 = _context6["catch"](14);
653
+ if (processingSubscription) {
654
+ processingSubscription.unsubscribe();
655
+ }
656
+ if (replaceFileId) {
657
+ _fileCache = cache.get(replaceFileId);
658
+ if (_fileCache) {
659
+ _fileCache.error(_context6.t3);
660
+ } else {
661
+ // Create a new subject with the error state for new subscriptions
662
+ cache.set(id, (0, _createMediaSubject.createMediaSubject)(_context6.t3));
675
663
  }
676
- throw _context6.t3;
677
- case 46:
678
- case "end":
679
- return _context6.stop();
680
- }
664
+ }
665
+ throw _context6.t3;
666
+ case 46:
667
+ case "end":
668
+ return _context6.stop();
681
669
  }
682
670
  }, _callee6, this, [[14, 41]]);
683
671
  }));