@atlaskit/media-client 20.0.0 → 20.0.1

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @atlaskit/media-client
2
2
 
3
+ ## 20.0.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`90f6203e794`](https://bitbucket.org/atlassian/atlassian-frontend/commits/90f6203e794) - Media Client now fetch remote file state regardless of file browser support (behind feature flag)
8
+ - Updated dependencies
9
+
3
10
  ## 20.0.0
4
11
 
5
12
  ### Major Changes
@@ -83,12 +83,14 @@ var _polling = require("../../utils/polling");
83
83
 
84
84
  var _detectEmptyFile = require("../../utils/detectEmptyFile");
85
85
 
86
+ var _mediaCommon = require("@atlaskit/media-common");
87
+
86
88
  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; }
87
89
 
88
90
  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; }
89
91
 
90
92
  var FileFetcherImpl = /*#__PURE__*/function () {
91
- function FileFetcherImpl(mediaStore) {
93
+ function FileFetcherImpl(mediaStore, featureFlags) {
92
94
  var _this = this;
93
95
 
94
96
  (0, _classCallCheck2.default)(this, FileFetcherImpl);
@@ -161,7 +163,47 @@ var FileFetcherImpl = /*#__PURE__*/function () {
161
163
  })));
162
164
  return subject;
163
165
  });
166
+ (0, _defineProperty2.default)(this, "getUploadingFileStateBase", function (file, upfrontId) {
167
+ // TODO: DO not modify the input parameter 'content' attribute
168
+ if (typeof file.content === 'string') {
169
+ file.content = (0, _convertBase64ToBlob.convertBase64ToBlob)(file.content);
170
+ }
171
+
172
+ var content = file.content,
173
+ _file$name = file.name,
174
+ name = _file$name === void 0 ? '' : _file$name;
175
+ var id = upfrontId.id,
176
+ occurrenceKey = upfrontId.occurrenceKey;
177
+ var preview; // TODO [MSW-796]: get file size for base64
178
+
179
+ var size = 0;
180
+ var mimeType = '';
181
+
182
+ if (content instanceof Blob) {
183
+ size = content.size;
184
+ mimeType = content.type;
185
+
186
+ if ((0, _mediaTypeUtils.isMimeTypeSupportedByBrowser)(content.type)) {
187
+ preview = {
188
+ value: content,
189
+ origin: 'local'
190
+ };
191
+ }
192
+ }
193
+
194
+ var mediaType = (0, _getMediaTypeFromUploadableFile.getMediaTypeFromUploadableFile)(file);
195
+ return {
196
+ id: id,
197
+ occurrenceKey: occurrenceKey,
198
+ name: name,
199
+ size: size,
200
+ mediaType: mediaType,
201
+ mimeType: mimeType,
202
+ preview: preview
203
+ };
204
+ });
164
205
  this.mediaStore = mediaStore;
206
+ this.featureFlags = featureFlags;
165
207
  this.dataloader = (0, _createFileDataLoader.createFileDataloader)(mediaStore);
166
208
  }
167
209
 
@@ -383,17 +425,68 @@ var FileFetcherImpl = /*#__PURE__*/function () {
383
425
  return uploadExternal;
384
426
  }()
385
427
  }, {
386
- key: "upload",
387
- value: function upload(file, controller, uploadableFileUpfrontIds, traceContext) {
428
+ key: "uploadAwlaysPullFileStates",
429
+ value: // TODO: make this the public upload method when the FF is removed
430
+ function uploadAwlaysPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext) {
388
431
  var _this4 = this;
389
432
 
433
+ var collection = file.collection;
434
+ var upfrontId = uploadableFileUpfrontIds || this.generateUploadableFileUpfrontIds(collection, traceContext);
435
+ var id = upfrontId.id,
436
+ occurrenceKey = upfrontId.occurrenceKey;
437
+ var stateBase = this.getUploadingFileStateBase(file, upfrontId);
438
+ var subject = (0, _createMediaSubject.createMediaSubject)();
439
+ (0, _fileStreamsCache.getFileStreamsCache)().set(id, subject);
440
+
441
+ var onProgress = function onProgress(progress) {
442
+ subject.next(_objectSpread(_objectSpread({
443
+ status: 'uploading'
444
+ }, stateBase), {}, {
445
+ progress: progress
446
+ }));
447
+ };
448
+
449
+ var processingSubscription = new _Subscription.Subscription();
450
+
451
+ var onUploadFinish = function onUploadFinish(error) {
452
+ if (error) {
453
+ return subject.error(error);
454
+ }
455
+
456
+ processingSubscription = _this4.createDownloadFileStream(id, collection, occurrenceKey).pipe((0, _map.map)(function (remoteFileState) {
457
+ return _objectSpread(_objectSpread(_objectSpread({}, stateBase), remoteFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(remoteFileState, stateBase.mediaType));
458
+ })).subscribe(subject);
459
+ };
460
+
461
+ var _uploadFile = (0, _uploader.uploadFile)(file, this.mediaStore, upfrontId, {
462
+ onUploadFinish: onUploadFinish,
463
+ onProgress: onProgress
464
+ }, traceContext),
465
+ cancel = _uploadFile.cancel;
466
+
467
+ controller === null || controller === void 0 ? void 0 : controller.setAbort(function () {
468
+ cancel(); // TODO: filestate should turn to "Aborted" or something.
469
+ // Consider canceling an upload that is already finished
470
+
471
+ processingSubscription.unsubscribe();
472
+ }); // We should report progress asynchronously, since this is what consumer expects
473
+ // (otherwise in newUploadService file-converting event will be emitted before files-added)
474
+
475
+ setTimeout(onProgress, 0, 0);
476
+ return (0, _mediaSubscribable.fromObservable)(subject);
477
+ }
478
+ }, {
479
+ key: "uploadConditionallyPullFileStates",
480
+ value: function uploadConditionallyPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext) {
481
+ var _this5 = this;
482
+
390
483
  if (typeof file.content === 'string') {
391
484
  file.content = (0, _convertBase64ToBlob.convertBase64ToBlob)(file.content);
392
485
  }
393
486
 
394
487
  var content = file.content,
395
- _file$name = file.name,
396
- name = _file$name === void 0 ? '' : _file$name,
488
+ _file$name2 = file.name,
489
+ name = _file$name2 === void 0 ? '' : _file$name2,
397
490
  collection = file.collection;
398
491
 
399
492
  if (!uploadableFileUpfrontIds) {
@@ -447,7 +540,7 @@ var FileFetcherImpl = /*#__PURE__*/function () {
447
540
 
448
541
  processingSubscription.add((0, _shouldFetchRemoteFileStates.shouldFetchRemoteFileStatesObservable)(mediaType, mimeType, preview).pipe((0, _concatMap.concatMap)(function (shouldFetchRemoteFileStates) {
449
542
  if (shouldFetchRemoteFileStates) {
450
- return _this4.createDownloadFileStream(id, collection, occurrenceKey).pipe((0, _map.map)(function (remoteFileState) {
543
+ return _this5.createDownloadFileStream(id, collection, occurrenceKey).pipe((0, _map.map)(function (remoteFileState) {
451
544
  return _objectSpread(_objectSpread(_objectSpread({}, stateBase), remoteFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(remoteFileState, mediaType));
452
545
  }));
453
546
  }
@@ -459,11 +552,11 @@ var FileFetcherImpl = /*#__PURE__*/function () {
459
552
  })).subscribe(subject));
460
553
  };
461
554
 
462
- var _uploadFile = (0, _uploader.uploadFile)(file, this.mediaStore, uploadableFileUpfrontIds, {
555
+ var _uploadFile2 = (0, _uploader.uploadFile)(file, this.mediaStore, uploadableFileUpfrontIds, {
463
556
  onUploadFinish: onUploadFinish,
464
557
  onProgress: onProgress
465
558
  }, traceContext),
466
- cancel = _uploadFile.cancel;
559
+ cancel = _uploadFile2.cancel;
467
560
 
468
561
  (0, _fileStreamsCache.getFileStreamsCache)().set(id, subject); // We should report progress asynchronously, since this is what consumer expects
469
562
  // (otherwise in newUploadService file-converting event will be emitted before files-added)
@@ -480,6 +573,17 @@ var FileFetcherImpl = /*#__PURE__*/function () {
480
573
  }
481
574
 
482
575
  return (0, _mediaSubscribable.fromObservable)(subject);
576
+ }
577
+ }, {
578
+ key: "upload",
579
+ value: function upload(file, controller, uploadableFileUpfrontIds, traceContext) {
580
+ var shouldAlwaysFetchFileState = (0, _mediaCommon.getMediaFeatureFlag)('fetchFileStateAfterUpload', this.featureFlags);
581
+
582
+ if (shouldAlwaysFetchFileState) {
583
+ return this.uploadAwlaysPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext);
584
+ }
585
+
586
+ return this.uploadConditionallyPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext);
483
587
  } // TODO: ----- ADD TICKET
484
588
 
485
589
  }, {
@@ -44,7 +44,7 @@ var MediaClient = /*#__PURE__*/function () {
44
44
  }, featureFlags);
45
45
  this.config = mediaClientConfig;
46
46
  this.collection = new _collectionFetcher.CollectionFetcher(this.mediaStore);
47
- this.file = new _fileFetcher.FileFetcherImpl(this.mediaStore);
47
+ this.file = new _fileFetcher.FileFetcherImpl(this.mediaStore, featureFlags);
48
48
  this.eventEmitter = new _eventemitter.EventEmitter2();
49
49
  this.stargate = new _stargateClient.StargateClient(mediaClientConfig.stargateBaseUrl);
50
50
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "20.0.0",
3
+ "version": "20.0.1",
4
4
  "sideEffects": false
5
5
  }
@@ -28,9 +28,10 @@ import { isMimeTypeSupportedByBrowser, getMediaTypeFromMimeType } from '@atlaski
28
28
  import { shouldFetchRemoteFileStates, shouldFetchRemoteFileStatesObservable } from '../../utils/shouldFetchRemoteFileStates';
29
29
  import { PollingFunction } from '../../utils/polling';
30
30
  import { isEmptyFile } from '../../utils/detectEmptyFile';
31
+ import { getMediaFeatureFlag } from '@atlaskit/media-common';
31
32
  export { isFileFetcherError, FileFetcherError } from './error';
32
33
  export class FileFetcherImpl {
33
- constructor(mediaStore) {
34
+ constructor(mediaStore, featureFlags) {
34
35
  _defineProperty(this, "createDownloadFileStream", (id, collectionName, occurrenceKey) => {
35
36
  const subject = createMediaSubject();
36
37
  const poll = new PollingFunction(); // ensure subject errors if polling exceeds max iterations or uncaught exception in executor
@@ -74,7 +75,52 @@ export class FileFetcherImpl {
74
75
  return subject;
75
76
  });
76
77
 
78
+ _defineProperty(this, "getUploadingFileStateBase", (file, upfrontId) => {
79
+ // TODO: DO not modify the input parameter 'content' attribute
80
+ if (typeof file.content === 'string') {
81
+ file.content = convertBase64ToBlob(file.content);
82
+ }
83
+
84
+ const {
85
+ content,
86
+ name = '' // name property is not available in base64 image
87
+
88
+ } = file;
89
+ const {
90
+ id,
91
+ occurrenceKey
92
+ } = upfrontId;
93
+ let preview; // TODO [MSW-796]: get file size for base64
94
+
95
+ let size = 0;
96
+ let mimeType = '';
97
+
98
+ if (content instanceof Blob) {
99
+ size = content.size;
100
+ mimeType = content.type;
101
+
102
+ if (isMimeTypeSupportedByBrowser(content.type)) {
103
+ preview = {
104
+ value: content,
105
+ origin: 'local'
106
+ };
107
+ }
108
+ }
109
+
110
+ const mediaType = getMediaTypeFromUploadableFile(file);
111
+ return {
112
+ id,
113
+ occurrenceKey,
114
+ name,
115
+ size,
116
+ mediaType,
117
+ mimeType,
118
+ preview
119
+ };
120
+ });
121
+
77
122
  this.mediaStore = mediaStore;
123
+ this.featureFlags = featureFlags;
78
124
  this.dataloader = createFileDataloader(mediaStore);
79
125
  }
80
126
 
@@ -209,7 +255,61 @@ export class FileFetcherImpl {
209
255
  });
210
256
  }
211
257
 
212
- upload(file, controller, uploadableFileUpfrontIds, traceContext) {
258
+ // TODO: make this the public upload method when the FF is removed
259
+ uploadAwlaysPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext) {
260
+ const {
261
+ collection
262
+ } = file;
263
+ const upfrontId = uploadableFileUpfrontIds || this.generateUploadableFileUpfrontIds(collection, traceContext);
264
+ const {
265
+ id,
266
+ occurrenceKey
267
+ } = upfrontId;
268
+ const stateBase = this.getUploadingFileStateBase(file, upfrontId);
269
+ const subject = createMediaSubject();
270
+ getFileStreamsCache().set(id, subject);
271
+
272
+ const onProgress = progress => {
273
+ subject.next({
274
+ status: 'uploading',
275
+ ...stateBase,
276
+ progress
277
+ });
278
+ };
279
+
280
+ let processingSubscription = new Subscription();
281
+
282
+ const onUploadFinish = error => {
283
+ if (error) {
284
+ return subject.error(error);
285
+ }
286
+
287
+ processingSubscription = this.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(remoteFileState => ({ // merges base state with remote state
288
+ ...stateBase,
289
+ ...remoteFileState,
290
+ ...overrideMediaTypeIfUnknown(remoteFileState, stateBase.mediaType)
291
+ }))).subscribe(subject);
292
+ };
293
+
294
+ const {
295
+ cancel
296
+ } = uploadFile(file, this.mediaStore, upfrontId, {
297
+ onUploadFinish,
298
+ onProgress
299
+ }, traceContext);
300
+ controller === null || controller === void 0 ? void 0 : controller.setAbort(() => {
301
+ cancel(); // TODO: filestate should turn to "Aborted" or something.
302
+ // Consider canceling an upload that is already finished
303
+
304
+ processingSubscription.unsubscribe();
305
+ }); // We should report progress asynchronously, since this is what consumer expects
306
+ // (otherwise in newUploadService file-converting event will be emitted before files-added)
307
+
308
+ setTimeout(onProgress, 0, 0);
309
+ return fromObservable(subject);
310
+ }
311
+
312
+ uploadConditionallyPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext) {
213
313
  if (typeof file.content === 'string') {
214
314
  file.content = convertBase64ToBlob(file.content);
215
315
  }
@@ -308,6 +408,16 @@ export class FileFetcherImpl {
308
408
  }
309
409
 
310
410
  return fromObservable(subject);
411
+ }
412
+
413
+ upload(file, controller, uploadableFileUpfrontIds, traceContext) {
414
+ const shouldAlwaysFetchFileState = getMediaFeatureFlag('fetchFileStateAfterUpload', this.featureFlags);
415
+
416
+ if (shouldAlwaysFetchFileState) {
417
+ return this.uploadAwlaysPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext);
418
+ }
419
+
420
+ return this.uploadConditionallyPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext);
311
421
  } // TODO: ----- ADD TICKET
312
422
 
313
423
 
@@ -15,7 +15,7 @@ export class MediaClient {
15
15
  }, featureFlags);
16
16
  this.config = mediaClientConfig;
17
17
  this.collection = new CollectionFetcher(this.mediaStore);
18
- this.file = new FileFetcherImpl(this.mediaStore);
18
+ this.file = new FileFetcherImpl(this.mediaStore, featureFlags);
19
19
  this.eventEmitter = new EventEmitter2();
20
20
  this.stargate = new StargateClient(mediaClientConfig.stargateBaseUrl);
21
21
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "20.0.0",
3
+ "version": "20.0.1",
4
4
  "sideEffects": false
5
5
  }
@@ -37,9 +37,10 @@ import { isMimeTypeSupportedByBrowser, getMediaTypeFromMimeType } from '@atlaski
37
37
  import { shouldFetchRemoteFileStates, shouldFetchRemoteFileStatesObservable } from '../../utils/shouldFetchRemoteFileStates';
38
38
  import { PollingFunction } from '../../utils/polling';
39
39
  import { isEmptyFile } from '../../utils/detectEmptyFile';
40
+ import { getMediaFeatureFlag } from '@atlaskit/media-common';
40
41
  export { isFileFetcherError, FileFetcherError } from './error';
41
42
  export var FileFetcherImpl = /*#__PURE__*/function () {
42
- function FileFetcherImpl(mediaStore) {
43
+ function FileFetcherImpl(mediaStore, featureFlags) {
43
44
  var _this = this;
44
45
 
45
46
  _classCallCheck(this, FileFetcherImpl);
@@ -114,7 +115,48 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
114
115
  return subject;
115
116
  });
116
117
 
118
+ _defineProperty(this, "getUploadingFileStateBase", function (file, upfrontId) {
119
+ // TODO: DO not modify the input parameter 'content' attribute
120
+ if (typeof file.content === 'string') {
121
+ file.content = convertBase64ToBlob(file.content);
122
+ }
123
+
124
+ var content = file.content,
125
+ _file$name = file.name,
126
+ name = _file$name === void 0 ? '' : _file$name;
127
+ var id = upfrontId.id,
128
+ occurrenceKey = upfrontId.occurrenceKey;
129
+ var preview; // TODO [MSW-796]: get file size for base64
130
+
131
+ var size = 0;
132
+ var mimeType = '';
133
+
134
+ if (content instanceof Blob) {
135
+ size = content.size;
136
+ mimeType = content.type;
137
+
138
+ if (isMimeTypeSupportedByBrowser(content.type)) {
139
+ preview = {
140
+ value: content,
141
+ origin: 'local'
142
+ };
143
+ }
144
+ }
145
+
146
+ var mediaType = getMediaTypeFromUploadableFile(file);
147
+ return {
148
+ id: id,
149
+ occurrenceKey: occurrenceKey,
150
+ name: name,
151
+ size: size,
152
+ mediaType: mediaType,
153
+ mimeType: mimeType,
154
+ preview: preview
155
+ };
156
+ });
157
+
117
158
  this.mediaStore = mediaStore;
159
+ this.featureFlags = featureFlags;
118
160
  this.dataloader = createFileDataloader(mediaStore);
119
161
  }
120
162
 
@@ -336,17 +378,68 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
336
378
  return uploadExternal;
337
379
  }()
338
380
  }, {
339
- key: "upload",
340
- value: function upload(file, controller, uploadableFileUpfrontIds, traceContext) {
381
+ key: "uploadAwlaysPullFileStates",
382
+ value: // TODO: make this the public upload method when the FF is removed
383
+ function uploadAwlaysPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext) {
341
384
  var _this4 = this;
342
385
 
386
+ var collection = file.collection;
387
+ var upfrontId = uploadableFileUpfrontIds || this.generateUploadableFileUpfrontIds(collection, traceContext);
388
+ var id = upfrontId.id,
389
+ occurrenceKey = upfrontId.occurrenceKey;
390
+ var stateBase = this.getUploadingFileStateBase(file, upfrontId);
391
+ var subject = createMediaSubject();
392
+ getFileStreamsCache().set(id, subject);
393
+
394
+ var onProgress = function onProgress(progress) {
395
+ subject.next(_objectSpread(_objectSpread({
396
+ status: 'uploading'
397
+ }, stateBase), {}, {
398
+ progress: progress
399
+ }));
400
+ };
401
+
402
+ var processingSubscription = new Subscription();
403
+
404
+ var onUploadFinish = function onUploadFinish(error) {
405
+ if (error) {
406
+ return subject.error(error);
407
+ }
408
+
409
+ processingSubscription = _this4.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(function (remoteFileState) {
410
+ return _objectSpread(_objectSpread(_objectSpread({}, stateBase), remoteFileState), overrideMediaTypeIfUnknown(remoteFileState, stateBase.mediaType));
411
+ })).subscribe(subject);
412
+ };
413
+
414
+ var _uploadFile = uploadFile(file, this.mediaStore, upfrontId, {
415
+ onUploadFinish: onUploadFinish,
416
+ onProgress: onProgress
417
+ }, traceContext),
418
+ cancel = _uploadFile.cancel;
419
+
420
+ controller === null || controller === void 0 ? void 0 : controller.setAbort(function () {
421
+ cancel(); // TODO: filestate should turn to "Aborted" or something.
422
+ // Consider canceling an upload that is already finished
423
+
424
+ processingSubscription.unsubscribe();
425
+ }); // We should report progress asynchronously, since this is what consumer expects
426
+ // (otherwise in newUploadService file-converting event will be emitted before files-added)
427
+
428
+ setTimeout(onProgress, 0, 0);
429
+ return fromObservable(subject);
430
+ }
431
+ }, {
432
+ key: "uploadConditionallyPullFileStates",
433
+ value: function uploadConditionallyPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext) {
434
+ var _this5 = this;
435
+
343
436
  if (typeof file.content === 'string') {
344
437
  file.content = convertBase64ToBlob(file.content);
345
438
  }
346
439
 
347
440
  var content = file.content,
348
- _file$name = file.name,
349
- name = _file$name === void 0 ? '' : _file$name,
441
+ _file$name2 = file.name,
442
+ name = _file$name2 === void 0 ? '' : _file$name2,
350
443
  collection = file.collection;
351
444
 
352
445
  if (!uploadableFileUpfrontIds) {
@@ -400,7 +493,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
400
493
 
401
494
  processingSubscription.add(shouldFetchRemoteFileStatesObservable(mediaType, mimeType, preview).pipe(concatMap(function (shouldFetchRemoteFileStates) {
402
495
  if (shouldFetchRemoteFileStates) {
403
- return _this4.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(function (remoteFileState) {
496
+ return _this5.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(function (remoteFileState) {
404
497
  return _objectSpread(_objectSpread(_objectSpread({}, stateBase), remoteFileState), overrideMediaTypeIfUnknown(remoteFileState, mediaType));
405
498
  }));
406
499
  }
@@ -412,11 +505,11 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
412
505
  })).subscribe(subject));
413
506
  };
414
507
 
415
- var _uploadFile = uploadFile(file, this.mediaStore, uploadableFileUpfrontIds, {
508
+ var _uploadFile2 = uploadFile(file, this.mediaStore, uploadableFileUpfrontIds, {
416
509
  onUploadFinish: onUploadFinish,
417
510
  onProgress: onProgress
418
511
  }, traceContext),
419
- cancel = _uploadFile.cancel;
512
+ cancel = _uploadFile2.cancel;
420
513
 
421
514
  getFileStreamsCache().set(id, subject); // We should report progress asynchronously, since this is what consumer expects
422
515
  // (otherwise in newUploadService file-converting event will be emitted before files-added)
@@ -433,6 +526,17 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
433
526
  }
434
527
 
435
528
  return fromObservable(subject);
529
+ }
530
+ }, {
531
+ key: "upload",
532
+ value: function upload(file, controller, uploadableFileUpfrontIds, traceContext) {
533
+ var shouldAlwaysFetchFileState = getMediaFeatureFlag('fetchFileStateAfterUpload', this.featureFlags);
534
+
535
+ if (shouldAlwaysFetchFileState) {
536
+ return this.uploadAwlaysPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext);
537
+ }
538
+
539
+ return this.uploadConditionallyPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext);
436
540
  } // TODO: ----- ADD TICKET
437
541
 
438
542
  }, {
@@ -21,7 +21,7 @@ export var MediaClient = /*#__PURE__*/function () {
21
21
  }, featureFlags);
22
22
  this.config = mediaClientConfig;
23
23
  this.collection = new CollectionFetcher(this.mediaStore);
24
- this.file = new FileFetcherImpl(this.mediaStore);
24
+ this.file = new FileFetcherImpl(this.mediaStore, featureFlags);
25
25
  this.eventEmitter = new EventEmitter2();
26
26
  this.stargate = new StargateClient(mediaClientConfig.stargateBaseUrl);
27
27
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "20.0.0",
3
+ "version": "20.0.1",
4
4
  "sideEffects": false
5
5
  }
@@ -8,7 +8,7 @@ import { MediaFileArtifacts } from '../../models/artifacts';
8
8
  import { UploadController } from '../../upload-controller';
9
9
  import { MediaSubscribable } from '../../utils/mediaSubscribable';
10
10
  import { Dimensions } from '../../utils/getDimensionsFromBlob';
11
- import { MediaTraceContext } from '@atlaskit/media-common';
11
+ import { MediaFeatureFlags, MediaTraceContext } from '@atlaskit/media-common';
12
12
  export type { FileFetcherErrorAttributes, FileFetcherErrorReason, } from './error';
13
13
  export { isFileFetcherError, FileFetcherError } from './error';
14
14
  export interface CopySourceFile {
@@ -41,8 +41,9 @@ export interface FileFetcher {
41
41
  }
42
42
  export declare class FileFetcherImpl implements FileFetcher {
43
43
  private readonly mediaStore;
44
+ private readonly featureFlags?;
44
45
  private readonly dataloader;
45
- constructor(mediaStore: MediaStore);
46
+ constructor(mediaStore: MediaStore, featureFlags?: MediaFeatureFlags | undefined);
46
47
  getFileState(id: string, options?: GetFileOptions): MediaSubscribable<FileState>;
47
48
  getCurrentState(id: string, options?: GetFileOptions): Promise<FileState>;
48
49
  getArtifactURL(artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string): Promise<string>;
@@ -51,6 +52,9 @@ export declare class FileFetcherImpl implements FileFetcher {
51
52
  touchFiles(descriptors: TouchFileDescriptor[], collection?: string, traceContext?: MediaTraceContext): Promise<TouchedFiles>;
52
53
  private generateUploadableFileUpfrontIds;
53
54
  uploadExternal(url: string, collection?: string, traceContext?: MediaTraceContext): Promise<ExternalUploadPayload>;
55
+ private getUploadingFileStateBase;
56
+ private uploadAwlaysPullFileStates;
57
+ private uploadConditionallyPullFileStates;
54
58
  upload(file: UploadableFile, controller?: UploadController, uploadableFileUpfrontIds?: UploadableFileUpfrontIds, traceContext?: MediaTraceContext): MediaSubscribable<FileState>;
55
59
  downloadBinary(id: string, name?: string, collectionName?: string): Promise<void>;
56
60
  copyFile(source: CopySourceFile, destination: CopyDestination, options?: CopyFileOptions, traceContext?: MediaTraceContext): Promise<MediaFile>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/media-client",
3
- "version": "20.0.0",
3
+ "version": "20.0.1",
4
4
  "description": "Media API Web Client Library",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -28,7 +28,7 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@atlaskit/chunkinator": "^4.1.0",
31
- "@atlaskit/media-common": "^2.18.0",
31
+ "@atlaskit/media-common": "^2.19.0",
32
32
  "@babel/runtime": "^7.0.0",
33
33
  "dataloader": "^2.0.0",
34
34
  "deep-equal": "^1.0.1",
@@ -49,7 +49,7 @@
49
49
  "devDependencies": {
50
50
  "@atlaskit/button": "^16.5.0",
51
51
  "@atlaskit/docs": "*",
52
- "@atlaskit/media-card": "^74.4.0",
52
+ "@atlaskit/media-card": "^74.5.0",
53
53
  "@atlaskit/media-core": "^34.0.0",
54
54
  "@atlaskit/media-test-helpers": "^30.1.0",
55
55
  "@atlaskit/ssr": "*",
package/report.api.md CHANGED
@@ -361,7 +361,10 @@ export type FileFetcherErrorReason =
361
361
 
362
362
  // @public (undocumented)
363
363
  export class FileFetcherImpl implements FileFetcher {
364
- constructor(mediaStore: MediaStore);
364
+ constructor(
365
+ mediaStore: MediaStore,
366
+ featureFlags?: MediaFeatureFlags | undefined,
367
+ );
365
368
  // (undocumented)
366
369
  copyFile(
367
370
  source: CopySourceFile,