@atlaskit/media-client 20.0.0 → 20.0.2

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 (163) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/client/collection-fetcher.js +4 -44
  3. package/dist/cjs/client/file-fetcher/error.js +3 -19
  4. package/dist/cjs/client/file-fetcher/index.js +152 -167
  5. package/dist/cjs/client/media-client.js +3 -27
  6. package/dist/cjs/client/media-store/error.js +1 -17
  7. package/dist/cjs/client/media-store/index.js +13 -103
  8. package/dist/cjs/client/media-store/resolveAuth.js +2 -23
  9. package/dist/cjs/client/mobile-upload.js +9 -22
  10. package/dist/cjs/client/stargate-client.js +0 -12
  11. package/dist/cjs/constants.js +0 -3
  12. package/dist/cjs/file-streams-cache.js +0 -11
  13. package/dist/cjs/globalMediaEventEmitter.js +0 -3
  14. package/dist/cjs/identifier.js +0 -8
  15. package/dist/cjs/index.js +0 -38
  16. package/dist/cjs/models/artifacts.js +0 -4
  17. package/dist/cjs/models/auth-headers.js +0 -2
  18. package/dist/cjs/models/auth-query-parameters.js +0 -2
  19. package/dist/cjs/models/errors/helpers.js +0 -2
  20. package/dist/cjs/models/errors/index.js +4 -20
  21. package/dist/cjs/models/file-state.js +10 -36
  22. package/dist/cjs/models/media.js +2 -8
  23. package/dist/cjs/upload-controller.js +0 -6
  24. package/dist/cjs/uploader/calculateChunkSize.js +1 -10
  25. package/dist/cjs/uploader/error.js +3 -19
  26. package/dist/cjs/uploader/index.js +3 -43
  27. package/dist/cjs/utils/checkWebpSupport.js +3 -7
  28. package/dist/cjs/utils/convertBase64ToBlob.js +0 -5
  29. package/dist/cjs/utils/createFileDataLoader.js +4 -28
  30. package/dist/cjs/utils/createMediaSubject.js +0 -4
  31. package/dist/cjs/utils/detectEmptyFile.js +8 -15
  32. package/dist/cjs/utils/getDimensionsFromBlob.js +0 -14
  33. package/dist/cjs/utils/getImageDimensionsFromBlob.js +0 -4
  34. package/dist/cjs/utils/getMediaTypeFromUploadableFile.js +0 -3
  35. package/dist/cjs/utils/getVideoDimensionsFromBlob.js +2 -8
  36. package/dist/cjs/utils/hashing/hasherCreator.js +0 -20
  37. package/dist/cjs/utils/hashing/simpleHasher.js +0 -12
  38. package/dist/cjs/utils/hashing/workerHasher.js +3 -24
  39. package/dist/cjs/utils/imageResizeModeToFileImageMode.js +0 -2
  40. package/dist/cjs/utils/isImageRemote.js +0 -5
  41. package/dist/cjs/utils/mediaSubscribable/fromObservable.js +2 -4
  42. package/dist/cjs/utils/mediaSubscribable/index.js +0 -2
  43. package/dist/cjs/utils/mediaSubscribable/toPromise.js +1 -3
  44. package/dist/cjs/utils/mobileUpload/error.js +3 -19
  45. package/dist/cjs/utils/mobileUpload/helpers.js +2 -26
  46. package/dist/cjs/utils/mobileUpload/index.js +0 -4
  47. package/dist/cjs/utils/mobileUpload/servicesCache.js +0 -2
  48. package/dist/cjs/utils/mobileUpload/stateMachine/index.js +0 -22
  49. package/dist/cjs/utils/mobileUpload/stateMachine/states/processing.js +0 -2
  50. package/dist/cjs/utils/mobileUpload/stateMachine/states/uploading.js +0 -7
  51. package/dist/cjs/utils/overrideMediaTypeIfUnknown.js +0 -4
  52. package/dist/cjs/utils/polling/errors.js +1 -17
  53. package/dist/cjs/utils/polling/index.js +1 -30
  54. package/dist/cjs/utils/request/errors.js +8 -24
  55. package/dist/cjs/utils/request/helpers.js +19 -103
  56. package/dist/cjs/utils/request/index.js +15 -26
  57. package/dist/cjs/utils/safeUnsubscribe.js +0 -2
  58. package/dist/cjs/utils/setTimeoutPromise.js +0 -4
  59. package/dist/cjs/utils/shouldFetchRemoteFileStates.js +0 -21
  60. package/dist/cjs/utils/url.js +4 -27
  61. package/dist/cjs/utils/with-media-client-hoc.js +12 -28
  62. package/dist/cjs/version.json +1 -1
  63. package/dist/es2019/client/collection-fetcher.js +6 -18
  64. package/dist/es2019/client/file-fetcher/error.js +0 -2
  65. package/dist/es2019/client/file-fetcher/index.js +138 -70
  66. package/dist/es2019/client/media-client.js +4 -14
  67. package/dist/es2019/client/media-store/error.js +0 -2
  68. package/dist/es2019/client/media-store/index.js +37 -52
  69. package/dist/es2019/client/media-store/resolveAuth.js +1 -5
  70. package/dist/es2019/client/mobile-upload.js +0 -8
  71. package/dist/es2019/client/stargate-client.js +0 -3
  72. package/dist/es2019/constants.js +0 -1
  73. package/dist/es2019/file-streams-cache.js +0 -11
  74. package/dist/es2019/globalMediaEventEmitter.js +0 -4
  75. package/dist/es2019/index.js +4 -11
  76. package/dist/es2019/models/artifacts.js +0 -2
  77. package/dist/es2019/models/errors/index.js +5 -4
  78. package/dist/es2019/models/file-state.js +6 -7
  79. package/dist/es2019/models/media.js +2 -3
  80. package/dist/es2019/upload-controller.js +0 -3
  81. package/dist/es2019/uploader/calculateChunkSize.js +1 -4
  82. package/dist/es2019/uploader/error.js +0 -2
  83. package/dist/es2019/uploader/index.js +0 -13
  84. package/dist/es2019/utils/checkWebpSupport.js +3 -4
  85. package/dist/es2019/utils/convertBase64ToBlob.js +0 -2
  86. package/dist/es2019/utils/createFileDataLoader.js +6 -9
  87. package/dist/es2019/utils/createMediaSubject.js +0 -2
  88. package/dist/es2019/utils/detectEmptyFile.js +1 -5
  89. package/dist/es2019/utils/getDimensionsFromBlob.js +0 -3
  90. package/dist/es2019/utils/getImageDimensionsFromBlob.js +0 -2
  91. package/dist/es2019/utils/getVideoDimensionsFromBlob.js +2 -1
  92. package/dist/es2019/utils/hashing/hasherCreator.js +0 -2
  93. package/dist/es2019/utils/hashing/simpleHasher.js +0 -3
  94. package/dist/es2019/utils/hashing/workerHasher.js +1 -16
  95. package/dist/es2019/utils/isImageRemote.js +0 -2
  96. package/dist/es2019/utils/mediaSubscribable/fromObservable.js +2 -1
  97. package/dist/es2019/utils/mediaSubscribable/toPromise.js +1 -1
  98. package/dist/es2019/utils/mobileUpload/error.js +0 -2
  99. package/dist/es2019/utils/mobileUpload/helpers.js +2 -7
  100. package/dist/es2019/utils/mobileUpload/stateMachine/index.js +0 -2
  101. package/dist/es2019/utils/mobileUpload/stateMachine/states/uploading.js +2 -1
  102. package/dist/es2019/utils/overrideMediaTypeIfUnknown.js +0 -1
  103. package/dist/es2019/utils/polling/errors.js +0 -2
  104. package/dist/es2019/utils/polling/index.js +3 -20
  105. package/dist/es2019/utils/request/errors.js +0 -2
  106. package/dist/es2019/utils/request/helpers.js +24 -35
  107. package/dist/es2019/utils/request/index.js +2 -2
  108. package/dist/es2019/utils/shouldFetchRemoteFileStates.js +1 -5
  109. package/dist/es2019/utils/url.js +6 -14
  110. package/dist/es2019/utils/with-media-client-hoc.js +10 -7
  111. package/dist/es2019/version.json +1 -1
  112. package/dist/esm/client/collection-fetcher.js +4 -34
  113. package/dist/esm/client/file-fetcher/error.js +3 -12
  114. package/dist/esm/client/file-fetcher/index.js +154 -137
  115. package/dist/esm/client/media-client.js +4 -17
  116. package/dist/esm/client/media-store/error.js +1 -10
  117. package/dist/esm/client/media-store/index.js +13 -89
  118. package/dist/esm/client/media-store/resolveAuth.js +2 -13
  119. package/dist/esm/client/mobile-upload.js +9 -15
  120. package/dist/esm/client/stargate-client.js +0 -7
  121. package/dist/esm/constants.js +0 -1
  122. package/dist/esm/file-streams-cache.js +0 -6
  123. package/dist/esm/globalMediaEventEmitter.js +0 -1
  124. package/dist/esm/index.js +4 -11
  125. package/dist/esm/models/artifacts.js +0 -2
  126. package/dist/esm/models/errors/index.js +5 -12
  127. package/dist/esm/models/file-state.js +10 -17
  128. package/dist/esm/models/media.js +2 -3
  129. package/dist/esm/upload-controller.js +0 -2
  130. package/dist/esm/uploader/calculateChunkSize.js +1 -4
  131. package/dist/esm/uploader/error.js +3 -12
  132. package/dist/esm/uploader/index.js +3 -32
  133. package/dist/esm/utils/checkWebpSupport.js +3 -4
  134. package/dist/esm/utils/convertBase64ToBlob.js +0 -3
  135. package/dist/esm/utils/createFileDataLoader.js +4 -18
  136. package/dist/esm/utils/createMediaSubject.js +0 -2
  137. package/dist/esm/utils/detectEmptyFile.js +8 -12
  138. package/dist/esm/utils/getDimensionsFromBlob.js +0 -7
  139. package/dist/esm/utils/getImageDimensionsFromBlob.js +0 -2
  140. package/dist/esm/utils/getVideoDimensionsFromBlob.js +2 -3
  141. package/dist/esm/utils/hashing/hasherCreator.js +0 -9
  142. package/dist/esm/utils/hashing/simpleHasher.js +0 -4
  143. package/dist/esm/utils/hashing/workerHasher.js +3 -18
  144. package/dist/esm/utils/isImageRemote.js +0 -3
  145. package/dist/esm/utils/mediaSubscribable/fromObservable.js +2 -1
  146. package/dist/esm/utils/mediaSubscribable/toPromise.js +1 -1
  147. package/dist/esm/utils/mobileUpload/error.js +3 -12
  148. package/dist/esm/utils/mobileUpload/helpers.js +2 -11
  149. package/dist/esm/utils/mobileUpload/stateMachine/index.js +0 -6
  150. package/dist/esm/utils/mobileUpload/stateMachine/states/uploading.js +0 -3
  151. package/dist/esm/utils/overrideMediaTypeIfUnknown.js +0 -1
  152. package/dist/esm/utils/polling/errors.js +1 -10
  153. package/dist/esm/utils/polling/index.js +1 -27
  154. package/dist/esm/utils/request/errors.js +8 -17
  155. package/dist/esm/utils/request/helpers.js +22 -76
  156. package/dist/esm/utils/request/index.js +15 -20
  157. package/dist/esm/utils/shouldFetchRemoteFileStates.js +1 -15
  158. package/dist/esm/utils/url.js +4 -18
  159. package/dist/esm/utils/with-media-client-hoc.js +12 -17
  160. package/dist/esm/version.json +1 -1
  161. package/dist/types/client/file-fetcher/index.d.ts +6 -2
  162. package/package.json +8 -6
  163. package/report.api.md +4 -1
@@ -2,19 +2,16 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
2
2
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
3
  import _createClass from "@babel/runtime/helpers/createClass";
4
4
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
-
6
5
  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; }
7
-
8
6
  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) { _defineProperty(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; }
9
-
10
7
  import _regeneratorRuntime from "@babel/runtime/regenerator";
11
8
  import { Subscription } from 'rxjs/Subscription';
12
9
  import { of } from 'rxjs/observable/of';
13
10
  import { map } from 'rxjs/operators/map';
14
11
  import { concatMap } from 'rxjs/operators/concatMap';
15
- import uuid from 'uuid/v4'; // import setimmediate to temporary fix dataloader 2.0.0 bug
12
+ import uuid from 'uuid/v4';
13
+ // import setimmediate to temporary fix dataloader 2.0.0 bug
16
14
  // @see https://github.com/graphql/dataloader/issues/249
17
-
18
15
  import 'setimmediate';
19
16
  import { authToOwner } from '@atlaskit/media-core';
20
17
  import { downloadUrl } from '@atlaskit/media-common/downloadUrl';
@@ -37,21 +34,20 @@ import { isMimeTypeSupportedByBrowser, getMediaTypeFromMimeType } from '@atlaski
37
34
  import { shouldFetchRemoteFileStates, shouldFetchRemoteFileStatesObservable } from '../../utils/shouldFetchRemoteFileStates';
38
35
  import { PollingFunction } from '../../utils/polling';
39
36
  import { isEmptyFile } from '../../utils/detectEmptyFile';
37
+ import { getMediaFeatureFlag } from '@atlaskit/media-common';
40
38
  export { isFileFetcherError, FileFetcherError } from './error';
41
39
  export var FileFetcherImpl = /*#__PURE__*/function () {
42
- function FileFetcherImpl(mediaStore) {
40
+ function FileFetcherImpl(mediaStore, featureFlags) {
43
41
  var _this = this;
44
-
45
42
  _classCallCheck(this, FileFetcherImpl);
46
-
47
43
  _defineProperty(this, "createDownloadFileStream", function (id, collectionName, occurrenceKey) {
48
44
  var subject = createMediaSubject();
49
- var poll = new PollingFunction(); // ensure subject errors if polling exceeds max iterations or uncaught exception in executor
45
+ var poll = new PollingFunction();
50
46
 
47
+ // ensure subject errors if polling exceeds max iterations or uncaught exception in executor
51
48
  poll.onError = function (error) {
52
49
  return subject.error(error);
53
50
  };
54
-
55
51
  poll.execute( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
56
52
  var response, fileState;
57
53
  return _regeneratorRuntime.wrap(function _callee$(_context) {
@@ -63,47 +59,38 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
63
59
  id: id,
64
60
  collectionName: collectionName
65
61
  });
66
-
67
62
  case 2:
68
63
  response = _context.sent;
69
-
70
64
  if (response) {
71
65
  _context.next = 5;
72
66
  break;
73
67
  }
74
-
75
68
  throw new FileFetcherError('emptyItems', id, {
76
69
  collectionName: collectionName,
77
70
  occurrenceKey: occurrenceKey
78
71
  });
79
-
80
72
  case 5:
81
73
  if (!isEmptyFile(response)) {
82
74
  _context.next = 7;
83
75
  break;
84
76
  }
85
-
86
77
  throw new FileFetcherError('zeroVersionFile', id, {
87
78
  collectionName: collectionName,
88
79
  occurrenceKey: occurrenceKey
89
80
  });
90
-
91
81
  case 7:
92
82
  fileState = mapMediaItemToFileState(id, response);
93
83
  subject.next(fileState);
94
84
  _context.t0 = fileState.status;
95
85
  _context.next = _context.t0 === 'processing' ? 12 : _context.t0 === 'processed' ? 14 : 16;
96
86
  break;
97
-
98
87
  case 12:
99
88
  // the only case for continuing polling, otherwise this function is run once only
100
89
  poll.next();
101
90
  return _context.abrupt("break", 16);
102
-
103
91
  case 14:
104
92
  subject.complete();
105
93
  return _context.abrupt("break", 16);
106
-
107
94
  case 16:
108
95
  case "end":
109
96
  return _context.stop();
@@ -113,20 +100,52 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
113
100
  })));
114
101
  return subject;
115
102
  });
116
-
103
+ _defineProperty(this, "getUploadingFileStateBase", function (file, upfrontId) {
104
+ // TODO: DO not modify the input parameter 'content' attribute
105
+ if (typeof file.content === 'string') {
106
+ file.content = convertBase64ToBlob(file.content);
107
+ }
108
+ var content = file.content,
109
+ _file$name = file.name,
110
+ name = _file$name === void 0 ? '' : _file$name;
111
+ var id = upfrontId.id,
112
+ occurrenceKey = upfrontId.occurrenceKey;
113
+ var preview;
114
+ // TODO [MSW-796]: get file size for base64
115
+ var size = 0;
116
+ var mimeType = '';
117
+ if (content instanceof Blob) {
118
+ size = content.size;
119
+ mimeType = content.type;
120
+ if (isMimeTypeSupportedByBrowser(content.type)) {
121
+ preview = {
122
+ value: content,
123
+ origin: 'local'
124
+ };
125
+ }
126
+ }
127
+ var mediaType = getMediaTypeFromUploadableFile(file);
128
+ return {
129
+ id: id,
130
+ occurrenceKey: occurrenceKey,
131
+ name: name,
132
+ size: size,
133
+ mediaType: mediaType,
134
+ mimeType: mimeType,
135
+ preview: preview
136
+ };
137
+ });
117
138
  this.mediaStore = mediaStore;
139
+ this.featureFlags = featureFlags;
118
140
  this.dataloader = createFileDataloader(mediaStore);
119
141
  }
120
-
121
142
  _createClass(FileFetcherImpl, [{
122
143
  key: "getFileState",
123
144
  value: function getFileState(id) {
124
145
  var _this2 = this;
125
-
126
146
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
127
147
  var collectionName = options.collectionName,
128
- occurrenceKey = options.occurrenceKey;
129
-
148
+ occurrenceKey = options.occurrenceKey;
130
149
  if (!isValidId(id)) {
131
150
  var subject = createMediaSubject();
132
151
  subject.error(new FileFetcherError('invalidFileId', id, {
@@ -135,7 +154,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
135
154
  }));
136
155
  return fromObservable(subject);
137
156
  }
138
-
139
157
  return fromObservable(getFileStreamsCache().getOrInsert(id, function () {
140
158
  return _this2.createDownloadFileStream(id, collectionName);
141
159
  }));
@@ -154,8 +172,9 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
154
172
  key: "getFileBinaryURL",
155
173
  value: function getFileBinaryURL(id, collectionName) {
156
174
  return this.mediaStore.getFileBinaryURL(id, collectionName);
157
- } // TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
175
+ }
158
176
 
177
+ // TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
159
178
  }, {
160
179
  key: "touchFiles",
161
180
  value: function touchFiles(descriptors, collection, traceContext) {
@@ -192,7 +211,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
192
211
  value: function () {
193
212
  var _uploadExternal = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(url, collection, traceContext) {
194
213
  var _this3 = this;
195
-
196
214
  var uploadableFileUpfrontIds, id, occurrenceKey, subject, deferredBlob, preview, name, fileState;
197
215
  return _regeneratorRuntime.wrap(function _callee4$(_context4) {
198
216
  while (1) {
@@ -215,19 +233,15 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
215
233
  case 0:
216
234
  _context2.next = 2;
217
235
  return deferredBlob;
218
-
219
236
  case 2:
220
237
  blob = _context2.sent;
221
-
222
238
  if (!blob) {
223
239
  reject('Could not fetch the blob');
224
240
  }
225
-
226
241
  resolve({
227
242
  value: blob,
228
243
  origin: 'remote'
229
244
  });
230
-
231
245
  case 5:
232
246
  case "end":
233
247
  return _context2.stop();
@@ -235,13 +249,11 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
235
249
  }
236
250
  }, _callee2);
237
251
  }));
238
-
239
252
  return function (_x4, _x5) {
240
253
  return _ref3.apply(this, arguments);
241
254
  };
242
255
  }());
243
256
  name = url.split('/').pop() || ''; // we create a initial fileState with the minimum info that we have at this point
244
-
245
257
  fileState = {
246
258
  status: 'processing',
247
259
  name: name,
@@ -252,8 +264,8 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
252
264
  occurrenceKey: occurrenceKey,
253
265
  preview: preview
254
266
  };
255
- subject.next(fileState); // we save it into the cache as soon as possible, in case someone subscribes
256
-
267
+ subject.next(fileState);
268
+ // we save it into the cache as soon as possible, in case someone subscribes
257
269
  getFileStreamsCache().set(id, subject);
258
270
  return _context4.abrupt("return", new Promise( /*#__PURE__*/function () {
259
271
  var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resolve, reject) {
@@ -264,17 +276,13 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
264
276
  case 0:
265
277
  _context3.next = 2;
266
278
  return deferredBlob;
267
-
268
279
  case 2:
269
280
  blob = _context3.sent;
270
-
271
281
  if (blob) {
272
282
  _context3.next = 5;
273
283
  break;
274
284
  }
275
-
276
285
  return _context3.abrupt("return", reject('Could not download remote file'));
277
-
278
286
  case 5:
279
287
  type = blob.type, size = blob.size;
280
288
  file = {
@@ -284,7 +292,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
284
292
  name: name
285
293
  };
286
294
  mediaType = getMediaTypeFromMimeType(type); // we emit a richer state after the blob is fetched
287
-
288
295
  subject.next({
289
296
  status: 'processing',
290
297
  name: name,
@@ -294,20 +301,17 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
294
301
  id: id,
295
302
  occurrenceKey: occurrenceKey,
296
303
  preview: preview
297
- }); // we don't want to wait for the file to be upload
298
-
304
+ });
305
+ // we don't want to wait for the file to be upload
299
306
  _this3.upload(file, undefined, uploadableFileUpfrontIds, traceContext);
300
-
301
307
  _context3.next = 12;
302
308
  return getDimensionsFromBlob(mediaType, blob);
303
-
304
309
  case 12:
305
310
  dimensions = _context3.sent;
306
311
  resolve({
307
312
  dimensions: dimensions,
308
313
  uploadableFileUpfrontIds: uploadableFileUpfrontIds
309
314
  });
310
-
311
315
  case 14:
312
316
  case "end":
313
317
  return _context3.stop();
@@ -315,12 +319,10 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
315
319
  }
316
320
  }, _callee3);
317
321
  }));
318
-
319
322
  return function (_x6, _x7) {
320
323
  return _ref4.apply(this, arguments);
321
324
  };
322
325
  }()));
323
-
324
326
  case 10:
325
327
  case "end":
326
328
  return _context4.stop();
@@ -328,45 +330,83 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
328
330
  }
329
331
  }, _callee4, this);
330
332
  }));
331
-
332
333
  function uploadExternal(_x, _x2, _x3) {
333
334
  return _uploadExternal.apply(this, arguments);
334
335
  }
335
-
336
336
  return uploadExternal;
337
337
  }()
338
338
  }, {
339
- key: "upload",
340
- value: function upload(file, controller, uploadableFileUpfrontIds, traceContext) {
339
+ key: "uploadAwlaysPullFileStates",
340
+ value:
341
+ // TODO: make this the public upload method when the FF is removed
342
+ function uploadAwlaysPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext) {
341
343
  var _this4 = this;
344
+ var collection = file.collection;
345
+ var upfrontId = uploadableFileUpfrontIds || this.generateUploadableFileUpfrontIds(collection, traceContext);
346
+ var id = upfrontId.id,
347
+ occurrenceKey = upfrontId.occurrenceKey;
348
+ var stateBase = this.getUploadingFileStateBase(file, upfrontId);
349
+ var subject = createMediaSubject();
350
+ getFileStreamsCache().set(id, subject);
351
+ var onProgress = function onProgress(progress) {
352
+ subject.next(_objectSpread(_objectSpread({
353
+ status: 'uploading'
354
+ }, stateBase), {}, {
355
+ progress: progress
356
+ }));
357
+ };
358
+ var processingSubscription = new Subscription();
359
+ var onUploadFinish = function onUploadFinish(error) {
360
+ if (error) {
361
+ return subject.error(error);
362
+ }
363
+ processingSubscription = _this4.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(function (remoteFileState) {
364
+ return _objectSpread(_objectSpread(_objectSpread({}, stateBase), remoteFileState), overrideMediaTypeIfUnknown(remoteFileState, stateBase.mediaType));
365
+ })).subscribe(subject);
366
+ };
367
+ var _uploadFile = uploadFile(file, this.mediaStore, upfrontId, {
368
+ onUploadFinish: onUploadFinish,
369
+ onProgress: onProgress
370
+ }, traceContext),
371
+ cancel = _uploadFile.cancel;
372
+ controller === null || controller === void 0 ? void 0 : controller.setAbort(function () {
373
+ cancel();
374
+ // TODO: filestate should turn to "Aborted" or something.
375
+ // Consider canceling an upload that is already finished
376
+ processingSubscription.unsubscribe();
377
+ });
342
378
 
379
+ // We should report progress asynchronously, since this is what consumer expects
380
+ // (otherwise in newUploadService file-converting event will be emitted before files-added)
381
+ setTimeout(onProgress, 0, 0);
382
+ return fromObservable(subject);
383
+ }
384
+ }, {
385
+ key: "uploadConditionallyPullFileStates",
386
+ value: function uploadConditionallyPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext) {
387
+ var _this5 = this;
343
388
  if (typeof file.content === 'string') {
344
389
  file.content = convertBase64ToBlob(file.content);
345
390
  }
346
-
347
391
  var content = file.content,
348
- _file$name = file.name,
349
- name = _file$name === void 0 ? '' : _file$name,
350
- collection = file.collection;
351
-
392
+ _file$name2 = file.name,
393
+ name = _file$name2 === void 0 ? '' : _file$name2,
394
+ collection = file.collection;
352
395
  if (!uploadableFileUpfrontIds) {
353
396
  uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
354
397
  }
355
-
356
398
  var id = uploadableFileUpfrontIds.id;
357
399
  var occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
358
400
  var mimeType = '';
359
401
  var size = 0;
360
- var preview; // TODO [MSW-796]: get file size for base64
361
-
402
+ var preview;
403
+ // TODO [MSW-796]: get file size for base64
362
404
  var mediaType = getMediaTypeFromUploadableFile(file);
363
405
  var subject = createMediaSubject();
364
406
  var processingSubscription = new Subscription();
365
-
366
407
  if (content instanceof Blob) {
367
408
  size = content.size;
368
409
  mimeType = content.type;
369
-
370
410
  if (isMimeTypeSupportedByBrowser(content.type)) {
371
411
  preview = {
372
412
  value: content,
@@ -374,7 +414,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
374
414
  };
375
415
  }
376
416
  }
377
-
378
417
  var stateBase = {
379
418
  id: id,
380
419
  occurrenceKey: occurrenceKey,
@@ -384,7 +423,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
384
423
  mimeType: mimeType,
385
424
  preview: preview
386
425
  };
387
-
388
426
  var onProgress = function onProgress(progress) {
389
427
  subject.next(_objectSpread(_objectSpread({
390
428
  status: 'uploading'
@@ -392,57 +430,61 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
392
430
  progress: progress
393
431
  }));
394
432
  };
395
-
396
433
  var onUploadFinish = function onUploadFinish(error) {
397
434
  if (error) {
398
435
  return subject.error(error);
399
436
  }
400
-
401
437
  processingSubscription.add(shouldFetchRemoteFileStatesObservable(mediaType, mimeType, preview).pipe(concatMap(function (shouldFetchRemoteFileStates) {
402
438
  if (shouldFetchRemoteFileStates) {
403
- return _this4.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(function (remoteFileState) {
439
+ return _this5.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(function (remoteFileState) {
404
440
  return _objectSpread(_objectSpread(_objectSpread({}, stateBase), remoteFileState), overrideMediaTypeIfUnknown(remoteFileState, mediaType));
405
441
  }));
406
442
  }
407
-
408
443
  return of(_objectSpread({
409
444
  status: 'processing',
410
445
  representations: {}
411
446
  }, stateBase));
412
447
  })).subscribe(subject));
413
448
  };
414
-
415
- var _uploadFile = uploadFile(file, this.mediaStore, uploadableFileUpfrontIds, {
416
- onUploadFinish: onUploadFinish,
417
- onProgress: onProgress
418
- }, traceContext),
419
- cancel = _uploadFile.cancel;
420
-
421
- getFileStreamsCache().set(id, subject); // We should report progress asynchronously, since this is what consumer expects
449
+ var _uploadFile2 = uploadFile(file, this.mediaStore, uploadableFileUpfrontIds, {
450
+ onUploadFinish: onUploadFinish,
451
+ onProgress: onProgress
452
+ }, traceContext),
453
+ cancel = _uploadFile2.cancel;
454
+ getFileStreamsCache().set(id, subject);
455
+
456
+ // We should report progress asynchronously, since this is what consumer expects
422
457
  // (otherwise in newUploadService file-converting event will be emitted before files-added)
423
-
424
458
  setTimeout(function () {
425
459
  onProgress(0);
426
460
  }, 0);
427
-
428
461
  if (controller) {
429
462
  controller.setAbort(function () {
430
463
  cancel();
431
464
  processingSubscription.unsubscribe();
432
465
  });
433
466
  }
434
-
435
467
  return fromObservable(subject);
436
- } // TODO: ----- ADD TICKET
468
+ }
469
+ }, {
470
+ key: "upload",
471
+ value: function upload(file, controller, uploadableFileUpfrontIds, traceContext) {
472
+ var shouldAlwaysFetchFileState = getMediaFeatureFlag('fetchFileStateAfterUpload', this.featureFlags);
473
+ if (shouldAlwaysFetchFileState) {
474
+ return this.uploadAwlaysPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext);
475
+ }
476
+ return this.uploadConditionallyPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext);
477
+ }
437
478
 
479
+ // TODO: ----- ADD TICKET
438
480
  }, {
439
481
  key: "downloadBinary",
440
482
  value: function () {
441
483
  var _downloadBinary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(id) {
442
484
  var name,
443
- collectionName,
444
- url,
445
- _args5 = arguments;
485
+ collectionName,
486
+ url,
487
+ _args5 = arguments;
446
488
  return _regeneratorRuntime.wrap(function _callee5$(_context5) {
447
489
  while (1) {
448
490
  switch (_context5.prev = _context5.next) {
@@ -451,7 +493,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
451
493
  collectionName = _args5.length > 2 ? _args5[2] : undefined;
452
494
  _context5.next = 4;
453
495
  return this.mediaStore.getFileBinaryURL(id, collectionName);
454
-
455
496
  case 4:
456
497
  url = _context5.sent;
457
498
  downloadUrl(url, {
@@ -462,7 +503,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
462
503
  isUserCollection: collectionName === RECENTS_COLLECTION,
463
504
  viewingLevel: 'download'
464
505
  });
465
-
466
506
  case 7:
467
507
  case "end":
468
508
  return _context5.stop();
@@ -470,11 +510,9 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
470
510
  }
471
511
  }, _callee5, this);
472
512
  }));
473
-
474
513
  function downloadBinary(_x8) {
475
514
  return _downloadBinary.apply(this, arguments);
476
515
  }
477
-
478
516
  return downloadBinary;
479
517
  }()
480
518
  }, {
@@ -482,35 +520,34 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
482
520
  value: function () {
483
521
  var _copyFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(source, destination) {
484
522
  var options,
485
- traceContext,
486
- authProvider,
487
- sourceCollection,
488
- id,
489
- destinationAuthProvider,
490
- destinationCollectionName,
491
- replaceFileId,
492
- occurrenceKey,
493
- preview,
494
- mimeType,
495
- mediaStore,
496
- owner,
497
- body,
498
- params,
499
- cache,
500
- processingSubscription,
501
- _yield$mediaStore$cop,
502
- copiedFile,
503
- copiedFileWithMimeType,
504
- copiedId,
505
- copiedMimeType,
506
- mediaType,
507
- copiedFileState,
508
- fileCache,
509
- subject,
510
- previewOverride,
511
- _fileCache,
512
- _args6 = arguments;
513
-
523
+ traceContext,
524
+ authProvider,
525
+ sourceCollection,
526
+ id,
527
+ destinationAuthProvider,
528
+ destinationCollectionName,
529
+ replaceFileId,
530
+ occurrenceKey,
531
+ preview,
532
+ mimeType,
533
+ mediaStore,
534
+ owner,
535
+ body,
536
+ params,
537
+ cache,
538
+ processingSubscription,
539
+ _yield$mediaStore$cop,
540
+ copiedFile,
541
+ copiedFileWithMimeType,
542
+ copiedId,
543
+ copiedMimeType,
544
+ mediaType,
545
+ copiedFileState,
546
+ fileCache,
547
+ subject,
548
+ previewOverride,
549
+ _fileCache,
550
+ _args6 = arguments;
514
551
  return _regeneratorRuntime.wrap(function _callee6$(_context6) {
515
552
  while (1) {
516
553
  switch (_context6.prev = _context6.next) {
@@ -528,7 +565,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
528
565
  return authProvider({
529
566
  collectionName: sourceCollection
530
567
  });
531
-
532
568
  case 9:
533
569
  _context6.t1 = _context6.sent;
534
570
  owner = (0, _context6.t0)(_context6.t1);
@@ -548,7 +584,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
548
584
  _context6.prev = 14;
549
585
  _context6.next = 17;
550
586
  return mediaStore.copyFileWithToken(body, params, traceContext);
551
-
552
587
  case 17:
553
588
  _yield$mediaStore$cop = _context6.sent;
554
589
  copiedFile = _yield$mediaStore$cop.data;
@@ -558,38 +593,32 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
558
593
  } : undefined);
559
594
  copiedId = copiedFileWithMimeType.id, copiedMimeType = copiedFileWithMimeType.mimeType; // backend may return an "unknown" mediaType just after the copy
560
595
  // it's better to deduce it from "copiedMimeType" using getMediaTypeFromMimeType()
561
-
562
596
  mediaType = copiedMimeType ? getMediaTypeFromMimeType(copiedMimeType) : 'unknown';
563
597
  copiedFileState = mapMediaFileToFileState({
564
598
  data: copiedFileWithMimeType
565
599
  });
566
600
  fileCache = cache.get(copiedId);
567
601
  subject = fileCache || createMediaSubject(); // if we were passed a "preview", we propagate it into the copiedFileState
568
-
569
602
  previewOverride = !isErrorFileState(copiedFileState) && !!preview ? {
570
603
  preview: preview
571
604
  } : {};
572
- _context6.t2 = !isFinalFileState(copiedFileState) && // mimeType should always be returned by "copyFileWithToken"
605
+ _context6.t2 = !isFinalFileState(copiedFileState) &&
606
+ // mimeType should always be returned by "copyFileWithToken"
573
607
  // but in case it's not, we don't want to penalize "copyFile"
574
608
  copiedMimeType;
575
-
576
609
  if (!_context6.t2) {
577
610
  _context6.next = 31;
578
611
  break;
579
612
  }
580
-
581
613
  _context6.next = 30;
582
614
  return shouldFetchRemoteFileStates(mediaType, copiedMimeType, preview);
583
-
584
615
  case 30:
585
616
  _context6.t2 = _context6.sent;
586
-
587
617
  case 31:
588
618
  if (!_context6.t2) {
589
619
  _context6.next = 36;
590
620
  break;
591
621
  }
592
-
593
622
  subject.next(_objectSpread(_objectSpread(_objectSpread({}, copiedFileState), overrideMediaTypeIfUnknown(copiedFileState, mediaType)), previewOverride));
594
623
  processingSubscription = this.createDownloadFileStream(copiedId, destinationCollectionName, occurrenceKey).subscribe({
595
624
  next: function next(remoteFileState) {
@@ -604,30 +633,23 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
604
633
  });
605
634
  _context6.next = 37;
606
635
  break;
607
-
608
636
  case 36:
609
637
  if (!isProcessingFileState(copiedFileState)) {
610
638
  subject.next(_objectSpread(_objectSpread({}, copiedFileState), !isErrorFileState(copiedFileState) && previewOverride));
611
639
  }
612
-
613
640
  case 37:
614
641
  if (!cache.has(copiedId)) {
615
642
  getFileStreamsCache().set(copiedId, subject);
616
643
  }
617
-
618
644
  return _context6.abrupt("return", copiedFile);
619
-
620
645
  case 41:
621
646
  _context6.prev = 41;
622
647
  _context6.t3 = _context6["catch"](14);
623
-
624
648
  if (processingSubscription) {
625
649
  processingSubscription.unsubscribe();
626
650
  }
627
-
628
651
  if (replaceFileId) {
629
652
  _fileCache = cache.get(replaceFileId);
630
-
631
653
  if (_fileCache) {
632
654
  _fileCache.error(_context6.t3);
633
655
  } else {
@@ -635,9 +657,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
635
657
  cache.set(id, createMediaSubject(_context6.t3));
636
658
  }
637
659
  }
638
-
639
660
  throw _context6.t3;
640
-
641
661
  case 46:
642
662
  case "end":
643
663
  return _context6.stop();
@@ -645,14 +665,11 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
645
665
  }
646
666
  }, _callee6, this, [[14, 41]]);
647
667
  }));
648
-
649
668
  function copyFile(_x9, _x10) {
650
669
  return _copyFile.apply(this, arguments);
651
670
  }
652
-
653
671
  return copyFile;
654
672
  }()
655
673
  }]);
656
-
657
674
  return FileFetcherImpl;
658
675
  }();