@atlaskit/media-client 20.0.1 → 20.0.3

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 (161) hide show
  1. package/CHANGELOG.md +12 -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 +72 -191
  5. package/dist/cjs/client/media-client.js +2 -26
  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 +1 -4
  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 +49 -91
  66. package/dist/es2019/client/media-client.js +3 -13
  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 +1 -2
  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 +74 -161
  115. package/dist/esm/client/media-client.js +3 -16
  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 +1 -2
  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/package.json +7 -5
@@ -3,9 +3,9 @@ import { Subscription } from 'rxjs/Subscription';
3
3
  import { of } from 'rxjs/observable/of';
4
4
  import { map } from 'rxjs/operators/map';
5
5
  import { concatMap } from 'rxjs/operators/concatMap';
6
- import uuid from 'uuid/v4'; // import setimmediate to temporary fix dataloader 2.0.0 bug
6
+ import uuid from 'uuid/v4';
7
+ // import setimmediate to temporary fix dataloader 2.0.0 bug
7
8
  // @see https://github.com/graphql/dataloader/issues/249
8
-
9
9
  import 'setimmediate';
10
10
  import { authToOwner } from '@atlaskit/media-core';
11
11
  import { downloadUrl } from '@atlaskit/media-common/downloadUrl';
@@ -34,39 +34,34 @@ export class FileFetcherImpl {
34
34
  constructor(mediaStore, featureFlags) {
35
35
  _defineProperty(this, "createDownloadFileStream", (id, collectionName, occurrenceKey) => {
36
36
  const subject = createMediaSubject();
37
- const poll = new PollingFunction(); // ensure subject errors if polling exceeds max iterations or uncaught exception in executor
37
+ const poll = new PollingFunction();
38
38
 
39
+ // ensure subject errors if polling exceeds max iterations or uncaught exception in executor
39
40
  poll.onError = error => subject.error(error);
40
-
41
41
  poll.execute(async () => {
42
42
  const response = await this.dataloader.load({
43
43
  id,
44
44
  collectionName
45
45
  });
46
-
47
46
  if (!response) {
48
47
  throw new FileFetcherError('emptyItems', id, {
49
48
  collectionName,
50
49
  occurrenceKey
51
50
  });
52
51
  }
53
-
54
52
  if (isEmptyFile(response)) {
55
53
  throw new FileFetcherError('zeroVersionFile', id, {
56
54
  collectionName,
57
55
  occurrenceKey
58
56
  });
59
57
  }
60
-
61
58
  const fileState = mapMediaItemToFileState(id, response);
62
59
  subject.next(fileState);
63
-
64
60
  switch (fileState.status) {
65
61
  case 'processing':
66
62
  // the only case for continuing polling, otherwise this function is run once only
67
63
  poll.next();
68
64
  break;
69
-
70
65
  case 'processed':
71
66
  subject.complete();
72
67
  break;
@@ -74,31 +69,26 @@ export class FileFetcherImpl {
74
69
  });
75
70
  return subject;
76
71
  });
77
-
78
72
  _defineProperty(this, "getUploadingFileStateBase", (file, upfrontId) => {
79
73
  // TODO: DO not modify the input parameter 'content' attribute
80
74
  if (typeof file.content === 'string') {
81
75
  file.content = convertBase64ToBlob(file.content);
82
76
  }
83
-
84
77
  const {
85
78
  content,
86
79
  name = '' // name property is not available in base64 image
87
-
88
80
  } = file;
89
81
  const {
90
82
  id,
91
83
  occurrenceKey
92
84
  } = upfrontId;
93
- let preview; // TODO [MSW-796]: get file size for base64
94
-
85
+ let preview;
86
+ // TODO [MSW-796]: get file size for base64
95
87
  let size = 0;
96
88
  let mimeType = '';
97
-
98
89
  if (content instanceof Blob) {
99
90
  size = content.size;
100
91
  mimeType = content.type;
101
-
102
92
  if (isMimeTypeSupportedByBrowser(content.type)) {
103
93
  preview = {
104
94
  value: content,
@@ -106,7 +96,6 @@ export class FileFetcherImpl {
106
96
  };
107
97
  }
108
98
  }
109
-
110
99
  const mediaType = getMediaTypeFromUploadableFile(file);
111
100
  return {
112
101
  id,
@@ -118,18 +107,15 @@ export class FileFetcherImpl {
118
107
  preview
119
108
  };
120
109
  });
121
-
122
110
  this.mediaStore = mediaStore;
123
111
  this.featureFlags = featureFlags;
124
112
  this.dataloader = createFileDataloader(mediaStore);
125
113
  }
126
-
127
114
  getFileState(id, options = {}) {
128
115
  const {
129
116
  collectionName,
130
117
  occurrenceKey
131
118
  } = options;
132
-
133
119
  if (!isValidId(id)) {
134
120
  const subject = createMediaSubject();
135
121
  subject.error(new FileFetcherError('invalidFileId', id, {
@@ -138,22 +124,19 @@ export class FileFetcherImpl {
138
124
  }));
139
125
  return fromObservable(subject);
140
126
  }
141
-
142
127
  return fromObservable(getFileStreamsCache().getOrInsert(id, () => this.createDownloadFileStream(id, collectionName)));
143
128
  }
144
-
145
129
  getCurrentState(id, options) {
146
130
  return toPromise(this.getFileState(id, options));
147
131
  }
148
-
149
132
  getArtifactURL(artifacts, artifactName, collectionName) {
150
133
  return this.mediaStore.getArtifactURL(artifacts, artifactName, collectionName);
151
134
  }
152
-
153
135
  getFileBinaryURL(id, collectionName) {
154
136
  return this.mediaStore.getFileBinaryURL(id, collectionName);
155
- } // TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
137
+ }
156
138
 
139
+ // TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
157
140
 
158
141
  touchFiles(descriptors, collection, traceContext) {
159
142
  return this.mediaStore.touchFiles({
@@ -164,7 +147,6 @@ export class FileFetcherImpl {
164
147
  data
165
148
  }) => data);
166
149
  }
167
-
168
150
  generateUploadableFileUpfrontIds(collection, traceContext) {
169
151
  const id = uuid();
170
152
  const occurrenceKey = uuid();
@@ -180,7 +162,6 @@ export class FileFetcherImpl {
180
162
  deferredUploadId
181
163
  };
182
164
  }
183
-
184
165
  async uploadExternal(url, collection, traceContext) {
185
166
  const uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
186
167
  const {
@@ -191,18 +172,16 @@ export class FileFetcherImpl {
191
172
  const deferredBlob = fetch(url).then(response => response.blob()).catch(() => undefined);
192
173
  const preview = new Promise(async (resolve, reject) => {
193
174
  const blob = await deferredBlob;
194
-
195
175
  if (!blob) {
196
176
  reject('Could not fetch the blob');
197
177
  }
198
-
199
178
  resolve({
200
179
  value: blob,
201
180
  origin: 'remote'
202
181
  });
203
182
  });
204
- const name = url.split('/').pop() || ''; // we create a initial fileState with the minimum info that we have at this point
205
-
183
+ const name = url.split('/').pop() || '';
184
+ // we create a initial fileState with the minimum info that we have at this point
206
185
  const fileState = {
207
186
  status: 'processing',
208
187
  name,
@@ -213,16 +192,14 @@ export class FileFetcherImpl {
213
192
  occurrenceKey,
214
193
  preview
215
194
  };
216
- subject.next(fileState); // we save it into the cache as soon as possible, in case someone subscribes
217
-
195
+ subject.next(fileState);
196
+ // we save it into the cache as soon as possible, in case someone subscribes
218
197
  getFileStreamsCache().set(id, subject);
219
198
  return new Promise(async (resolve, reject) => {
220
199
  const blob = await deferredBlob;
221
-
222
200
  if (!blob) {
223
201
  return reject('Could not download remote file');
224
202
  }
225
-
226
203
  const {
227
204
  type,
228
205
  size
@@ -233,8 +210,9 @@ export class FileFetcherImpl {
233
210
  collection,
234
211
  name
235
212
  };
236
- const mediaType = getMediaTypeFromMimeType(type); // we emit a richer state after the blob is fetched
213
+ const mediaType = getMediaTypeFromMimeType(type);
237
214
 
215
+ // we emit a richer state after the blob is fetched
238
216
  subject.next({
239
217
  status: 'processing',
240
218
  name,
@@ -244,8 +222,8 @@ export class FileFetcherImpl {
244
222
  id,
245
223
  occurrenceKey,
246
224
  preview
247
- }); // we don't want to wait for the file to be upload
248
-
225
+ });
226
+ // we don't want to wait for the file to be upload
249
227
  this.upload(file, undefined, uploadableFileUpfrontIds, traceContext);
250
228
  const dimensions = await getDimensionsFromBlob(mediaType, blob);
251
229
  resolve({
@@ -254,7 +232,6 @@ export class FileFetcherImpl {
254
232
  });
255
233
  });
256
234
  }
257
-
258
235
  // TODO: make this the public upload method when the FF is removed
259
236
  uploadAwlaysPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext) {
260
237
  const {
@@ -268,7 +245,6 @@ export class FileFetcherImpl {
268
245
  const stateBase = this.getUploadingFileStateBase(file, upfrontId);
269
246
  const subject = createMediaSubject();
270
247
  getFileStreamsCache().set(id, subject);
271
-
272
248
  const onProgress = progress => {
273
249
  subject.next({
274
250
  status: 'uploading',
@@ -276,21 +252,18 @@ export class FileFetcherImpl {
276
252
  progress
277
253
  });
278
254
  };
279
-
280
255
  let processingSubscription = new Subscription();
281
-
282
256
  const onUploadFinish = error => {
283
257
  if (error) {
284
258
  return subject.error(error);
285
259
  }
286
-
287
- processingSubscription = this.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(remoteFileState => ({ // merges base state with remote state
260
+ processingSubscription = this.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(remoteFileState => ({
261
+ // merges base state with remote state
288
262
  ...stateBase,
289
263
  ...remoteFileState,
290
264
  ...overrideMediaTypeIfUnknown(remoteFileState, stateBase.mediaType)
291
265
  }))).subscribe(subject);
292
266
  };
293
-
294
267
  const {
295
268
  cancel
296
269
  } = uploadFile(file, this.mediaStore, upfrontId, {
@@ -298,47 +271,42 @@ export class FileFetcherImpl {
298
271
  onProgress
299
272
  }, traceContext);
300
273
  controller === null || controller === void 0 ? void 0 : controller.setAbort(() => {
301
- cancel(); // TODO: filestate should turn to "Aborted" or something.
274
+ cancel();
275
+ // TODO: filestate should turn to "Aborted" or something.
302
276
  // Consider canceling an upload that is already finished
303
-
304
277
  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)
278
+ });
307
279
 
280
+ // We should report progress asynchronously, since this is what consumer expects
281
+ // (otherwise in newUploadService file-converting event will be emitted before files-added)
308
282
  setTimeout(onProgress, 0, 0);
309
283
  return fromObservable(subject);
310
284
  }
311
-
312
285
  uploadConditionallyPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext) {
313
286
  if (typeof file.content === 'string') {
314
287
  file.content = convertBase64ToBlob(file.content);
315
288
  }
316
-
317
289
  const {
318
290
  content,
319
291
  name = '',
320
292
  // name property is not available in base64 image
321
293
  collection
322
294
  } = file;
323
-
324
295
  if (!uploadableFileUpfrontIds) {
325
296
  uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
326
297
  }
327
-
328
298
  const id = uploadableFileUpfrontIds.id;
329
299
  const occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
330
300
  let mimeType = '';
331
301
  let size = 0;
332
- let preview; // TODO [MSW-796]: get file size for base64
333
-
302
+ let preview;
303
+ // TODO [MSW-796]: get file size for base64
334
304
  const mediaType = getMediaTypeFromUploadableFile(file);
335
305
  const subject = createMediaSubject();
336
306
  const processingSubscription = new Subscription();
337
-
338
307
  if (content instanceof Blob) {
339
308
  size = content.size;
340
309
  mimeType = content.type;
341
-
342
310
  if (isMimeTypeSupportedByBrowser(content.type)) {
343
311
  preview = {
344
312
  value: content,
@@ -346,7 +314,6 @@ export class FileFetcherImpl {
346
314
  };
347
315
  }
348
316
  }
349
-
350
317
  const stateBase = {
351
318
  id,
352
319
  occurrenceKey,
@@ -356,7 +323,6 @@ export class FileFetcherImpl {
356
323
  mimeType,
357
324
  preview
358
325
  };
359
-
360
326
  const onProgress = progress => {
361
327
  subject.next({
362
328
  status: 'uploading',
@@ -364,21 +330,19 @@ export class FileFetcherImpl {
364
330
  progress
365
331
  });
366
332
  };
367
-
368
333
  const onUploadFinish = error => {
369
334
  if (error) {
370
335
  return subject.error(error);
371
336
  }
372
-
373
337
  processingSubscription.add(shouldFetchRemoteFileStatesObservable(mediaType, mimeType, preview).pipe(concatMap(shouldFetchRemoteFileStates => {
374
338
  if (shouldFetchRemoteFileStates) {
375
- return this.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(remoteFileState => ({ // merges base state with remote state
339
+ return this.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(remoteFileState => ({
340
+ // merges base state with remote state
376
341
  ...stateBase,
377
342
  ...remoteFileState,
378
343
  ...overrideMediaTypeIfUnknown(remoteFileState, mediaType)
379
344
  })));
380
345
  }
381
-
382
346
  return of({
383
347
  status: 'processing',
384
348
  representations: {},
@@ -386,41 +350,36 @@ export class FileFetcherImpl {
386
350
  });
387
351
  })).subscribe(subject));
388
352
  };
389
-
390
353
  const {
391
354
  cancel
392
355
  } = uploadFile(file, this.mediaStore, uploadableFileUpfrontIds, {
393
356
  onUploadFinish,
394
357
  onProgress
395
358
  }, traceContext);
396
- getFileStreamsCache().set(id, subject); // We should report progress asynchronously, since this is what consumer expects
397
- // (otherwise in newUploadService file-converting event will be emitted before files-added)
359
+ getFileStreamsCache().set(id, subject);
398
360
 
361
+ // We should report progress asynchronously, since this is what consumer expects
362
+ // (otherwise in newUploadService file-converting event will be emitted before files-added)
399
363
  setTimeout(() => {
400
364
  onProgress(0);
401
365
  }, 0);
402
-
403
366
  if (controller) {
404
367
  controller.setAbort(() => {
405
368
  cancel();
406
369
  processingSubscription.unsubscribe();
407
370
  });
408
371
  }
409
-
410
372
  return fromObservable(subject);
411
373
  }
412
-
413
374
  upload(file, controller, uploadableFileUpfrontIds, traceContext) {
414
375
  const shouldAlwaysFetchFileState = getMediaFeatureFlag('fetchFileStateAfterUpload', this.featureFlags);
415
-
416
376
  if (shouldAlwaysFetchFileState) {
417
377
  return this.uploadAwlaysPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext);
418
378
  }
419
-
420
379
  return this.uploadConditionallyPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext);
421
- } // TODO: ----- ADD TICKET
422
-
380
+ }
423
381
 
382
+ // TODO: ----- ADD TICKET
424
383
  async downloadBinary(id, name = 'download', collectionName) {
425
384
  const url = await this.mediaStore.getFileBinaryURL(id, collectionName);
426
385
  downloadUrl(url, {
@@ -432,7 +391,6 @@ export class FileFetcherImpl {
432
391
  viewingLevel: 'download'
433
392
  });
434
393
  }
435
-
436
394
  async copyFile(source, destination, options = {}, traceContext) {
437
395
  const {
438
396
  authProvider,
@@ -469,13 +427,14 @@ export class FileFetcherImpl {
469
427
  };
470
428
  const cache = getFileStreamsCache();
471
429
  let processingSubscription;
472
-
473
430
  try {
474
431
  const {
475
432
  data: copiedFile
476
- } = await mediaStore.copyFileWithToken(body, params, traceContext); // if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
433
+ } = await mediaStore.copyFileWithToken(body, params, traceContext);
477
434
 
478
- const copiedFileWithMimeType = { ...copiedFile,
435
+ // if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
436
+ const copiedFileWithMimeType = {
437
+ ...copiedFile,
479
438
  ...(mimeType ? {
480
439
  mimeType
481
440
  } : undefined)
@@ -483,29 +442,33 @@ export class FileFetcherImpl {
483
442
  const {
484
443
  id: copiedId,
485
444
  mimeType: copiedMimeType
486
- } = copiedFileWithMimeType; // backend may return an "unknown" mediaType just after the copy
487
- // it's better to deduce it from "copiedMimeType" using getMediaTypeFromMimeType()
445
+ } = copiedFileWithMimeType;
488
446
 
447
+ // backend may return an "unknown" mediaType just after the copy
448
+ // it's better to deduce it from "copiedMimeType" using getMediaTypeFromMimeType()
489
449
  const mediaType = copiedMimeType ? getMediaTypeFromMimeType(copiedMimeType) : 'unknown';
490
450
  const copiedFileState = mapMediaFileToFileState({
491
451
  data: copiedFileWithMimeType
492
452
  });
493
453
  const fileCache = cache.get(copiedId);
494
- const subject = fileCache || createMediaSubject(); // if we were passed a "preview", we propagate it into the copiedFileState
454
+ const subject = fileCache || createMediaSubject();
495
455
 
456
+ // if we were passed a "preview", we propagate it into the copiedFileState
496
457
  const previewOverride = !isErrorFileState(copiedFileState) && !!preview ? {
497
458
  preview
498
459
  } : {};
499
-
500
- if (!isFinalFileState(copiedFileState) && // mimeType should always be returned by "copyFileWithToken"
460
+ if (!isFinalFileState(copiedFileState) &&
461
+ // mimeType should always be returned by "copyFileWithToken"
501
462
  // but in case it's not, we don't want to penalize "copyFile"
502
463
  copiedMimeType && (await shouldFetchRemoteFileStates(mediaType, copiedMimeType, preview))) {
503
- subject.next({ ...copiedFileState,
464
+ subject.next({
465
+ ...copiedFileState,
504
466
  ...overrideMediaTypeIfUnknown(copiedFileState, mediaType),
505
467
  ...previewOverride
506
468
  });
507
469
  processingSubscription = this.createDownloadFileStream(copiedId, destinationCollectionName, occurrenceKey).subscribe({
508
- next: remoteFileState => subject.next({ ...remoteFileState,
470
+ next: remoteFileState => subject.next({
471
+ ...remoteFileState,
509
472
  ...overrideMediaTypeIfUnknown(remoteFileState, mediaType),
510
473
  ...(!isErrorFileState(remoteFileState) && previewOverride)
511
474
  }),
@@ -513,24 +476,21 @@ export class FileFetcherImpl {
513
476
  complete: () => subject.complete()
514
477
  });
515
478
  } else if (!isProcessingFileState(copiedFileState)) {
516
- subject.next({ ...copiedFileState,
479
+ subject.next({
480
+ ...copiedFileState,
517
481
  ...(!isErrorFileState(copiedFileState) && previewOverride)
518
482
  });
519
483
  }
520
-
521
484
  if (!cache.has(copiedId)) {
522
485
  getFileStreamsCache().set(copiedId, subject);
523
486
  }
524
-
525
487
  return copiedFile;
526
488
  } catch (error) {
527
489
  if (processingSubscription) {
528
490
  processingSubscription.unsubscribe();
529
491
  }
530
-
531
492
  if (replaceFileId) {
532
493
  const fileCache = cache.get(replaceFileId);
533
-
534
494
  if (fileCache) {
535
495
  fileCache.error(error);
536
496
  } else {
@@ -538,9 +498,7 @@ export class FileFetcherImpl {
538
498
  cache.set(id, createMediaSubject(error));
539
499
  }
540
500
  }
541
-
542
501
  throw error;
543
502
  }
544
503
  }
545
-
546
504
  }
@@ -5,7 +5,9 @@ import { FileFetcherImpl } from './file-fetcher';
5
5
  import { StargateClient } from './stargate-client';
6
6
  export class MediaClient {
7
7
  // mobile upload is lazily loaded
8
+
8
9
  // Deprecated value introduced for backward compatibility with Context
10
+
9
11
  constructor(mediaClientConfig, featureFlags) {
10
12
  this.mediaClientConfig = mediaClientConfig;
11
13
  this.featureFlags = featureFlags;
@@ -19,45 +21,33 @@ export class MediaClient {
19
21
  this.eventEmitter = new EventEmitter2();
20
22
  this.stargate = new StargateClient(mediaClientConfig.stargateBaseUrl);
21
23
  }
22
-
23
24
  getImage(id, params, controller, fetchMaxRes, traceContext) {
24
25
  return this.mediaStore.getImage(id, params, controller, fetchMaxRes, traceContext);
25
26
  }
26
-
27
27
  getImageUrl(id, params) {
28
28
  return this.mediaStore.getFileImageURL(id, params);
29
29
  }
30
-
31
30
  getImageUrlSync(id, params) {
32
31
  return this.mediaStore.getFileImageURLSync(id, params);
33
32
  }
34
-
35
33
  async getImageMetadata(id, params) {
36
34
  return (await this.mediaStore.getImageMetadata(id, params)).metadata;
37
35
  }
38
-
39
36
  async mobileUploadPromise() {
40
37
  if (this.mobileUpload) {
41
38
  return this.mobileUpload;
42
39
  }
43
-
44
- const module = await import(
45
- /* webpackChunkName: "@atlaskit-internal_media-client-mobile-upload" */
46
- './mobile-upload');
40
+ const module = await import( /* webpackChunkName: "@atlaskit-internal_media-client-mobile-upload" */'./mobile-upload');
47
41
  this.mobileUpload = new module.MobileUploadImpl(this.mediaStore);
48
42
  return this.mobileUpload;
49
43
  }
50
-
51
44
  on(event, listener) {
52
45
  this.eventEmitter.on(event, listener);
53
46
  }
54
-
55
47
  off(event, listener) {
56
48
  this.eventEmitter.off(event, listener);
57
49
  }
58
-
59
50
  emit(event, payload) {
60
51
  return this.eventEmitter.emit(event, payload);
61
52
  }
62
-
63
53
  }
@@ -5,7 +5,6 @@ export class MediaStoreError extends BaseMediaClientError {
5
5
  this.reason = reason;
6
6
  this.innerError = innerError;
7
7
  }
8
-
9
8
  get attributes() {
10
9
  const {
11
10
  reason,
@@ -16,7 +15,6 @@ export class MediaStoreError extends BaseMediaClientError {
16
15
  innerError
17
16
  };
18
17
  }
19
-
20
18
  }
21
19
  export function isMediaStoreError(err) {
22
20
  return err instanceof MediaStoreError;