@atlaskit/media-client 23.2.0 → 24.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/client/file-fetcher/index.js +110 -34
- package/dist/cjs/client/media-client.js +18 -6
- package/dist/cjs/client/media-store/index.js +1 -2
- package/dist/cjs/client/mobile-upload.js +38 -2
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/utils/with-media-client-hoc.js +8 -16
- package/dist/es2019/client/file-fetcher/index.js +101 -28
- package/dist/es2019/client/media-client.js +15 -7
- package/dist/es2019/client/media-store/index.js +1 -2
- package/dist/es2019/client/mobile-upload.js +33 -2
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/utils/with-media-client-hoc.js +8 -16
- package/dist/esm/client/file-fetcher/index.js +106 -30
- package/dist/esm/client/media-client.js +19 -7
- package/dist/esm/client/media-store/index.js +1 -2
- package/dist/esm/client/mobile-upload.js +38 -2
- package/dist/esm/index.js +1 -0
- package/dist/esm/utils/with-media-client-hoc.js +8 -16
- package/dist/types/client/events.d.ts +1 -1
- package/dist/types/client/file-fetcher/index.d.ts +10 -6
- package/dist/types/client/media-client.d.ts +10 -5
- package/dist/types/client/media-store/index.d.ts +3 -4
- package/dist/types/client/mobile-upload.d.ts +6 -2
- package/dist/types/file-streams-cache.d.ts +1 -1
- package/dist/types/index.d.ts +4 -2
- package/dist/types/models/artifacts.d.ts +1 -14
- package/dist/types/models/file-state.d.ts +4 -73
- package/dist/types/models/media.d.ts +1 -1
- package/dist/types/models/mobile-upload.d.ts +1 -1
- package/dist/types/utils/createMediaSubject.d.ts +1 -1
- package/dist/types/utils/mediaSubscribable/fromObservable.d.ts +1 -1
- package/dist/types/utils/mediaSubscribable/toPromise.d.ts +1 -1
- package/dist/types/utils/mediaSubscribable/types.d.ts +1 -1
- package/dist/types/utils/mobileUpload/helpers.d.ts +1 -1
- package/dist/types/utils/mobileUpload/stateMachine/index.d.ts +1 -1
- package/dist/types/utils/mobileUpload/stateMachine/types.d.ts +1 -1
- package/dist/types/utils/overrideMediaTypeIfUnknown.d.ts +1 -1
- package/dist/types/utils/shouldFetchRemoteFileStates.d.ts +1 -1
- package/dist/types/utils/with-media-client-hoc.d.ts +2 -3
- package/dist/types-ts4.5/client/events.d.ts +1 -1
- package/dist/types-ts4.5/client/file-fetcher/index.d.ts +10 -6
- package/dist/types-ts4.5/client/media-client.d.ts +10 -5
- package/dist/types-ts4.5/client/media-store/index.d.ts +3 -4
- package/dist/types-ts4.5/client/mobile-upload.d.ts +6 -2
- package/dist/types-ts4.5/file-streams-cache.d.ts +1 -1
- package/dist/types-ts4.5/index.d.ts +4 -2
- package/dist/types-ts4.5/models/artifacts.d.ts +1 -14
- package/dist/types-ts4.5/models/file-state.d.ts +4 -73
- package/dist/types-ts4.5/models/media.d.ts +1 -1
- package/dist/types-ts4.5/models/mobile-upload.d.ts +1 -1
- package/dist/types-ts4.5/utils/createMediaSubject.d.ts +1 -1
- package/dist/types-ts4.5/utils/mediaSubscribable/fromObservable.d.ts +1 -1
- package/dist/types-ts4.5/utils/mediaSubscribable/toPromise.d.ts +1 -1
- package/dist/types-ts4.5/utils/mediaSubscribable/types.d.ts +1 -1
- package/dist/types-ts4.5/utils/mobileUpload/helpers.d.ts +1 -1
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/index.d.ts +1 -1
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/types.d.ts +1 -1
- package/dist/types-ts4.5/utils/overrideMediaTypeIfUnknown.d.ts +1 -1
- package/dist/types-ts4.5/utils/shouldFetchRemoteFileStates.d.ts +1 -1
- package/dist/types-ts4.5/utils/with-media-client-hoc.d.ts +2 -3
- package/package.json +5 -3
- package/report.api.md +51 -168
- package/tmp/api-report-tmp.d.ts +51 -160
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @atlaskit/media-client
|
|
2
2
|
|
|
3
|
+
## 24.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [`7b6a2c6671b`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7b6a2c6671b) - Introducing 'media-state' for handling media internal file state.
|
|
8
|
+
Introducing 'media-client-react' to provide hooks for seamless media-client integration with React.
|
|
9
|
+
Introducing 'MediaCardV2' with a feature flag to replace rxjs based fileState subscription with 'useFileState' hook.
|
|
10
|
+
Removed unused feature flags APIs from 'media-client' and its helper functions from 'media-common'.
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies
|
|
15
|
+
|
|
3
16
|
## 23.2.0
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
|
@@ -29,7 +29,7 @@ require("setimmediate");
|
|
|
29
29
|
var _mediaCore = require("@atlaskit/media-core");
|
|
30
30
|
var _downloadUrl = require("@atlaskit/media-common/downloadUrl");
|
|
31
31
|
var _mediaStore = require("../media-store");
|
|
32
|
-
var
|
|
32
|
+
var _fileState2 = require("../../models/file-state");
|
|
33
33
|
var _error = require("./error");
|
|
34
34
|
var _uploader = require("../../uploader");
|
|
35
35
|
var _fileStreamsCache = require("../../file-streams-cache");
|
|
@@ -47,13 +47,36 @@ var _mediaTypeUtils = require("@atlaskit/media-common/mediaTypeUtils");
|
|
|
47
47
|
var _shouldFetchRemoteFileStates = require("../../utils/shouldFetchRemoteFileStates");
|
|
48
48
|
var _polling = require("../../utils/polling");
|
|
49
49
|
var _detectEmptyFile = require("../../utils/detectEmptyFile");
|
|
50
|
+
var _mediaState = require("@atlaskit/media-state");
|
|
50
51
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
51
52
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } // import setimmediate to temporary fix dataloader 2.0.0 bug
|
|
52
53
|
// @see https://github.com/graphql/dataloader/issues/249
|
|
53
54
|
var FileFetcherImpl = /*#__PURE__*/function () {
|
|
54
|
-
function FileFetcherImpl(
|
|
55
|
+
function FileFetcherImpl(mediaApi) {
|
|
55
56
|
var _this = this;
|
|
57
|
+
var store = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _mediaState.mediaStore;
|
|
56
58
|
(0, _classCallCheck2.default)(this, FileFetcherImpl);
|
|
59
|
+
(0, _defineProperty2.default)(this, "getErrorFileState", function (error, id, occurrenceKey) {
|
|
60
|
+
return typeof error === 'string' ? {
|
|
61
|
+
status: 'error',
|
|
62
|
+
id: id,
|
|
63
|
+
reason: error,
|
|
64
|
+
occurrenceKey: occurrenceKey,
|
|
65
|
+
message: error
|
|
66
|
+
} : {
|
|
67
|
+
status: 'error',
|
|
68
|
+
id: id,
|
|
69
|
+
reason: error === null || error === void 0 ? void 0 : error.reason,
|
|
70
|
+
details: error === null || error === void 0 ? void 0 : error.attributes,
|
|
71
|
+
occurrenceKey: occurrenceKey,
|
|
72
|
+
message: error === null || error === void 0 ? void 0 : error.message
|
|
73
|
+
};
|
|
74
|
+
});
|
|
75
|
+
(0, _defineProperty2.default)(this, "setFileState", function (id, fileState) {
|
|
76
|
+
_this.store.setState(function (state) {
|
|
77
|
+
state.files[id] = fileState;
|
|
78
|
+
});
|
|
79
|
+
});
|
|
57
80
|
// TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
|
|
58
81
|
(0, _defineProperty2.default)(this, "createDownloadFileStream", function (id, collectionName, occurrenceKey) {
|
|
59
82
|
var subject = (0, _createMediaSubject.createMediaSubject)();
|
|
@@ -93,7 +116,7 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
93
116
|
occurrenceKey: occurrenceKey
|
|
94
117
|
});
|
|
95
118
|
case 7:
|
|
96
|
-
fileState = (0,
|
|
119
|
+
fileState = (0, _fileState2.mapMediaItemToFileState)(id, response);
|
|
97
120
|
subject.next(fileState);
|
|
98
121
|
_context.t0 = fileState.status;
|
|
99
122
|
_context.next = _context.t0 === 'processing' ? 12 : _context.t0 === 'processed' ? 14 : 16;
|
|
@@ -148,8 +171,9 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
148
171
|
preview: preview
|
|
149
172
|
};
|
|
150
173
|
});
|
|
151
|
-
this.
|
|
152
|
-
this.
|
|
174
|
+
this.mediaApi = mediaApi;
|
|
175
|
+
this.store = store;
|
|
176
|
+
this.dataloader = (0, _createFileDataLoader.createFileDataloader)(mediaApi);
|
|
153
177
|
}
|
|
154
178
|
(0, _createClass2.default)(FileFetcherImpl, [{
|
|
155
179
|
key: "getFileState",
|
|
@@ -160,14 +184,34 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
160
184
|
occurrenceKey = options.occurrenceKey;
|
|
161
185
|
if (!(0, _uuidValidate.default)(id)) {
|
|
162
186
|
var subject = (0, _createMediaSubject.createMediaSubject)();
|
|
163
|
-
|
|
187
|
+
var err = new _error.FileFetcherError('invalidFileId', id, {
|
|
164
188
|
collectionName: collectionName,
|
|
165
189
|
occurrenceKey: occurrenceKey
|
|
166
|
-
})
|
|
190
|
+
});
|
|
191
|
+
var errorFileState = {
|
|
192
|
+
status: 'error',
|
|
193
|
+
id: id,
|
|
194
|
+
reason: err === null || err === void 0 ? void 0 : err.reason,
|
|
195
|
+
message: err === null || err === void 0 ? void 0 : err.message,
|
|
196
|
+
occurrenceKey: occurrenceKey,
|
|
197
|
+
details: err === null || err === void 0 ? void 0 : err.attributes
|
|
198
|
+
};
|
|
199
|
+
subject.error(err);
|
|
200
|
+
this.setFileState(id, errorFileState);
|
|
167
201
|
return (0, _mediaSubscribable.fromObservable)(subject);
|
|
168
202
|
}
|
|
169
203
|
return (0, _mediaSubscribable.fromObservable)((0, _fileStreamsCache.getFileStreamsCache)().getOrInsert(id, function () {
|
|
170
|
-
|
|
204
|
+
var subject = _this2.createDownloadFileStream(id, collectionName);
|
|
205
|
+
subject.subscribe({
|
|
206
|
+
next: function next(fileState) {
|
|
207
|
+
_this2.setFileState(id, fileState);
|
|
208
|
+
},
|
|
209
|
+
error: function error(err) {
|
|
210
|
+
var errorFileState = _this2.getErrorFileState(err, id, occurrenceKey);
|
|
211
|
+
_this2.setFileState(id, errorFileState);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
return subject;
|
|
171
215
|
}));
|
|
172
216
|
}
|
|
173
217
|
}, {
|
|
@@ -178,17 +222,17 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
178
222
|
}, {
|
|
179
223
|
key: "getArtifactURL",
|
|
180
224
|
value: function getArtifactURL(artifacts, artifactName, collectionName) {
|
|
181
|
-
return this.
|
|
225
|
+
return this.mediaApi.getArtifactURL(artifacts, artifactName, collectionName);
|
|
182
226
|
}
|
|
183
227
|
}, {
|
|
184
228
|
key: "getFileBinaryURL",
|
|
185
229
|
value: function getFileBinaryURL(id, collectionName) {
|
|
186
|
-
return this.
|
|
230
|
+
return this.mediaApi.getFileBinaryURL(id, collectionName);
|
|
187
231
|
}
|
|
188
232
|
}, {
|
|
189
233
|
key: "touchFiles",
|
|
190
234
|
value: function touchFiles(descriptors, collection, traceContext) {
|
|
191
|
-
return this.
|
|
235
|
+
return this.mediaApi.touchFiles({
|
|
192
236
|
descriptors: descriptors
|
|
193
237
|
}, {
|
|
194
238
|
collection: collection
|
|
@@ -274,6 +318,7 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
274
318
|
subject.next(fileState);
|
|
275
319
|
// we save it into the cache as soon as possible, in case someone subscribes
|
|
276
320
|
(0, _fileStreamsCache.getFileStreamsCache)().set(id, subject);
|
|
321
|
+
this.setFileState(id, fileState);
|
|
277
322
|
return _context4.abrupt("return", new Promise( /*#__PURE__*/function () {
|
|
278
323
|
var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(resolve, reject) {
|
|
279
324
|
var blob, type, size, file, mediaType, dimensions;
|
|
@@ -329,7 +374,7 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
329
374
|
return _ref4.apply(this, arguments);
|
|
330
375
|
};
|
|
331
376
|
}()));
|
|
332
|
-
case
|
|
377
|
+
case 11:
|
|
333
378
|
case "end":
|
|
334
379
|
return _context4.stop();
|
|
335
380
|
}
|
|
@@ -352,22 +397,37 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
352
397
|
var subject = (0, _createMediaSubject.createMediaSubject)();
|
|
353
398
|
(0, _fileStreamsCache.getFileStreamsCache)().set(id, subject);
|
|
354
399
|
var onProgress = function onProgress(progress) {
|
|
355
|
-
|
|
400
|
+
var fileState = _objectSpread(_objectSpread({
|
|
356
401
|
status: 'uploading'
|
|
357
402
|
}, stateBase), {}, {
|
|
358
403
|
progress: progress
|
|
359
|
-
})
|
|
404
|
+
});
|
|
405
|
+
subject.next(fileState);
|
|
406
|
+
_this4.setFileState(id, fileState);
|
|
360
407
|
};
|
|
361
408
|
var processingSubscription = new _Subscription.Subscription();
|
|
362
409
|
var onUploadFinish = function onUploadFinish(error) {
|
|
363
410
|
if (error) {
|
|
411
|
+
var errorFileState = _this4.getErrorFileState(error, id, occurrenceKey);
|
|
412
|
+
_this4.setFileState(id, errorFileState);
|
|
364
413
|
return subject.error(error);
|
|
365
414
|
}
|
|
366
415
|
processingSubscription = _this4.createDownloadFileStream(id, collection, occurrenceKey).pipe((0, _map.map)(function (remoteFileState) {
|
|
367
416
|
return _objectSpread(_objectSpread(_objectSpread({}, stateBase), remoteFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(remoteFileState, stateBase.mediaType));
|
|
368
|
-
})).subscribe(
|
|
417
|
+
})).subscribe({
|
|
418
|
+
next: function next(fileState) {
|
|
419
|
+
subject.next(fileState);
|
|
420
|
+
_this4.setFileState(id, fileState);
|
|
421
|
+
},
|
|
422
|
+
error: function error(err) {
|
|
423
|
+
var errorFileState = _this4.getErrorFileState(err, id, occurrenceKey);
|
|
424
|
+
subject.error(err);
|
|
425
|
+
_this4.setFileState(id, errorFileState);
|
|
426
|
+
},
|
|
427
|
+
complete: subject.complete
|
|
428
|
+
});
|
|
369
429
|
};
|
|
370
|
-
var _uploadFile = (0, _uploader.uploadFile)(file, this.
|
|
430
|
+
var _uploadFile = (0, _uploader.uploadFile)(file, this.mediaApi, upfrontId, {
|
|
371
431
|
onUploadFinish: onUploadFinish,
|
|
372
432
|
onProgress: onProgress
|
|
373
433
|
}, traceContext),
|
|
@@ -384,8 +444,6 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
384
444
|
setTimeout(onProgress, 0, 0);
|
|
385
445
|
return (0, _mediaSubscribable.fromObservable)(subject);
|
|
386
446
|
}
|
|
387
|
-
|
|
388
|
-
// TODO: ----- ADD TICKET
|
|
389
447
|
}, {
|
|
390
448
|
key: "downloadBinary",
|
|
391
449
|
value: function () {
|
|
@@ -400,7 +458,7 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
400
458
|
name = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : 'download';
|
|
401
459
|
collectionName = _args5.length > 2 ? _args5[2] : undefined;
|
|
402
460
|
_context5.next = 4;
|
|
403
|
-
return this.
|
|
461
|
+
return this.mediaApi.getFileBinaryURL(id, collectionName);
|
|
404
462
|
case 4:
|
|
405
463
|
url = _context5.sent;
|
|
406
464
|
(0, _downloadUrl.downloadUrl)(url, {
|
|
@@ -426,6 +484,7 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
426
484
|
key: "copyFile",
|
|
427
485
|
value: function () {
|
|
428
486
|
var _copyFile = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(source, destination) {
|
|
487
|
+
var _this5 = this;
|
|
429
488
|
var options,
|
|
430
489
|
traceContext,
|
|
431
490
|
authProvider,
|
|
@@ -453,7 +512,12 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
453
512
|
fileCache,
|
|
454
513
|
subject,
|
|
455
514
|
previewOverride,
|
|
515
|
+
fileState,
|
|
516
|
+
_fileState,
|
|
456
517
|
_fileCache,
|
|
518
|
+
replaceFileState,
|
|
519
|
+
key,
|
|
520
|
+
errorFileState,
|
|
457
521
|
_args6 = arguments;
|
|
458
522
|
return _regenerator.default.wrap(function _callee6$(_context6) {
|
|
459
523
|
while (1) switch (_context6.prev = _context6.next) {
|
|
@@ -500,15 +564,15 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
500
564
|
copiedId = copiedFileWithMimeType.id, copiedMimeType = copiedFileWithMimeType.mimeType; // backend may return an "unknown" mediaType just after the copy
|
|
501
565
|
// it's better to deduce it from "copiedMimeType" using getMediaTypeFromMimeType()
|
|
502
566
|
mediaType = copiedMimeType ? (0, _mediaTypeUtils.getMediaTypeFromMimeType)(copiedMimeType) : 'unknown';
|
|
503
|
-
copiedFileState = (0,
|
|
567
|
+
copiedFileState = (0, _fileState2.mapMediaFileToFileState)({
|
|
504
568
|
data: copiedFileWithMimeType
|
|
505
569
|
});
|
|
506
570
|
fileCache = cache.get(copiedId);
|
|
507
571
|
subject = fileCache || (0, _createMediaSubject.createMediaSubject)(); // if we were passed a "preview", we propagate it into the copiedFileState
|
|
508
|
-
previewOverride = !(0,
|
|
572
|
+
previewOverride = !(0, _fileState2.isErrorFileState)(copiedFileState) && !!preview ? {
|
|
509
573
|
preview: preview
|
|
510
574
|
} : {};
|
|
511
|
-
_context6.t2 = !(0,
|
|
575
|
+
_context6.t2 = !(0, _fileState2.isFinalFileState)(copiedFileState) &&
|
|
512
576
|
// mimeType should always be returned by "copyFileWithToken"
|
|
513
577
|
// but in case it's not, we don't want to penalize "copyFile"
|
|
514
578
|
copiedMimeType;
|
|
@@ -522,53 +586,65 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
522
586
|
_context6.t2 = _context6.sent;
|
|
523
587
|
case 31:
|
|
524
588
|
if (!_context6.t2) {
|
|
525
|
-
_context6.next =
|
|
589
|
+
_context6.next = 38;
|
|
526
590
|
break;
|
|
527
591
|
}
|
|
528
|
-
|
|
592
|
+
fileState = _objectSpread(_objectSpread(_objectSpread({}, copiedFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(copiedFileState, mediaType)), previewOverride);
|
|
593
|
+
subject.next(fileState);
|
|
594
|
+
this.setFileState(copiedId, fileState);
|
|
529
595
|
processingSubscription = this.createDownloadFileStream(copiedId, destinationCollectionName, occurrenceKey).subscribe({
|
|
530
596
|
next: function next(remoteFileState) {
|
|
531
|
-
|
|
597
|
+
var fileState = _objectSpread(_objectSpread(_objectSpread({}, remoteFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(remoteFileState, mediaType)), !(0, _fileState2.isErrorFileState)(remoteFileState) && previewOverride);
|
|
598
|
+
_this5.setFileState(copiedId, fileState);
|
|
599
|
+
return subject.next(fileState);
|
|
532
600
|
},
|
|
533
601
|
error: function error(err) {
|
|
602
|
+
var errorFileState = _this5.getErrorFileState(err, id, occurrenceKey);
|
|
603
|
+
_this5.setFileState(copiedId, errorFileState);
|
|
534
604
|
return subject.error(err);
|
|
535
605
|
},
|
|
536
606
|
complete: function complete() {
|
|
537
607
|
return subject.complete();
|
|
538
608
|
}
|
|
539
609
|
});
|
|
540
|
-
_context6.next =
|
|
610
|
+
_context6.next = 39;
|
|
541
611
|
break;
|
|
542
|
-
case
|
|
543
|
-
if (!(0,
|
|
544
|
-
|
|
612
|
+
case 38:
|
|
613
|
+
if (!(0, _fileState2.isProcessingFileState)(copiedFileState)) {
|
|
614
|
+
_fileState = _objectSpread(_objectSpread({}, copiedFileState), !(0, _fileState2.isErrorFileState)(copiedFileState) && previewOverride);
|
|
615
|
+
subject.next(_fileState);
|
|
616
|
+
this.setFileState(copiedId, _fileState);
|
|
545
617
|
}
|
|
546
|
-
case
|
|
618
|
+
case 39:
|
|
547
619
|
if (!cache.has(copiedId)) {
|
|
548
620
|
(0, _fileStreamsCache.getFileStreamsCache)().set(copiedId, subject);
|
|
549
621
|
}
|
|
550
622
|
return _context6.abrupt("return", copiedFile);
|
|
551
|
-
case
|
|
552
|
-
_context6.prev =
|
|
623
|
+
case 43:
|
|
624
|
+
_context6.prev = 43;
|
|
553
625
|
_context6.t3 = _context6["catch"](14);
|
|
554
626
|
if (processingSubscription) {
|
|
555
627
|
processingSubscription.unsubscribe();
|
|
556
628
|
}
|
|
557
629
|
if (replaceFileId) {
|
|
558
630
|
_fileCache = cache.get(replaceFileId);
|
|
631
|
+
replaceFileState = this.store.getState().files[replaceFileId];
|
|
559
632
|
if (_fileCache) {
|
|
560
633
|
_fileCache.error(_context6.t3);
|
|
561
634
|
} else {
|
|
562
635
|
// Create a new subject with the error state for new subscriptions
|
|
563
636
|
cache.set(id, (0, _createMediaSubject.createMediaSubject)(_context6.t3));
|
|
564
637
|
}
|
|
638
|
+
key = replaceFileState ? replaceFileId : id;
|
|
639
|
+
errorFileState = this.getErrorFileState(_context6.t3, id, occurrenceKey);
|
|
640
|
+
this.setFileState(key, errorFileState);
|
|
565
641
|
}
|
|
566
642
|
throw _context6.t3;
|
|
567
|
-
case
|
|
643
|
+
case 48:
|
|
568
644
|
case "end":
|
|
569
645
|
return _context6.stop();
|
|
570
646
|
}
|
|
571
|
-
}, _callee6, this, [[14,
|
|
647
|
+
}, _callee6, this, [[14, 43]]);
|
|
572
648
|
}));
|
|
573
649
|
function copyFile(_x9, _x10) {
|
|
574
650
|
return _copyFile.apply(this, arguments);
|
|
@@ -14,6 +14,7 @@ var _eventemitter = require("eventemitter2");
|
|
|
14
14
|
var _mediaStore = require("./media-store");
|
|
15
15
|
var _fileFetcher = require("./file-fetcher");
|
|
16
16
|
var _stargateClient = require("./stargate-client");
|
|
17
|
+
var _mediaState = require("@atlaskit/media-state");
|
|
17
18
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
18
19
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
20
|
var MediaClient = /*#__PURE__*/function () {
|
|
@@ -21,20 +22,31 @@ var MediaClient = /*#__PURE__*/function () {
|
|
|
21
22
|
|
|
22
23
|
// Deprecated value introduced for backward compatibility with Context
|
|
23
24
|
|
|
24
|
-
function MediaClient(mediaClientConfig
|
|
25
|
+
function MediaClient(mediaClientConfig) {
|
|
26
|
+
var store = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _mediaState.mediaStore;
|
|
27
|
+
var mediaApi = arguments.length > 2 ? arguments[2] : undefined;
|
|
25
28
|
(0, _classCallCheck2.default)(this, MediaClient);
|
|
26
29
|
this.mediaClientConfig = mediaClientConfig;
|
|
27
|
-
this.
|
|
28
|
-
this.mediaStore = new _mediaStore.MediaStore({
|
|
30
|
+
this.store = store;
|
|
31
|
+
this.mediaStore = mediaApi !== null && mediaApi !== void 0 ? mediaApi : new _mediaStore.MediaStore({
|
|
29
32
|
authProvider: mediaClientConfig.authProvider,
|
|
30
33
|
initialAuth: mediaClientConfig.initialAuth
|
|
31
|
-
}
|
|
34
|
+
});
|
|
32
35
|
this.config = mediaClientConfig;
|
|
33
|
-
this.file = new _fileFetcher.FileFetcherImpl(this.mediaStore);
|
|
36
|
+
this.file = new _fileFetcher.FileFetcherImpl(this.mediaStore, this.store);
|
|
34
37
|
this.eventEmitter = new _eventemitter.EventEmitter2();
|
|
35
38
|
this.stargate = new _stargateClient.StargateClient(mediaClientConfig.stargateBaseUrl);
|
|
36
39
|
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
37
44
|
(0, _createClass2.default)(MediaClient, [{
|
|
45
|
+
key: "__DO_NOT_USE__getMediaStore",
|
|
46
|
+
value: function __DO_NOT_USE__getMediaStore() {
|
|
47
|
+
return this.store;
|
|
48
|
+
}
|
|
49
|
+
}, {
|
|
38
50
|
key: "getImage",
|
|
39
51
|
value: function getImage(id, params, controller, fetchMaxRes, traceContext) {
|
|
40
52
|
return this.mediaStore.getImage(id, params, controller, fetchMaxRes, traceContext);
|
|
@@ -91,7 +103,7 @@ var MediaClient = /*#__PURE__*/function () {
|
|
|
91
103
|
});
|
|
92
104
|
case 4:
|
|
93
105
|
module = _context2.sent;
|
|
94
|
-
this.mobileUpload = new module.MobileUploadImpl(this.mediaStore);
|
|
106
|
+
this.mobileUpload = new module.MobileUploadImpl(this.mediaStore, this.store);
|
|
95
107
|
return _context2.abrupt("return", this.mobileUpload);
|
|
96
108
|
case 7:
|
|
97
109
|
case "end":
|
|
@@ -51,7 +51,7 @@ var jsonHeaders = {
|
|
|
51
51
|
'Content-Type': 'application/json'
|
|
52
52
|
};
|
|
53
53
|
var MediaStore = /*#__PURE__*/function () {
|
|
54
|
-
function MediaStore(config
|
|
54
|
+
function MediaStore(config) {
|
|
55
55
|
var _this = this;
|
|
56
56
|
(0, _classCallCheck2.default)(this, MediaStore);
|
|
57
57
|
(0, _defineProperty2.default)(this, "resolveAuth", function (authContext) {
|
|
@@ -61,7 +61,6 @@ var MediaStore = /*#__PURE__*/function () {
|
|
|
61
61
|
return (0, _resolveAuth.resolveInitialAuth)(_this.config.initialAuth);
|
|
62
62
|
});
|
|
63
63
|
this.config = config;
|
|
64
|
-
this.featureFlags = featureFlags;
|
|
65
64
|
}
|
|
66
65
|
(0, _createClass2.default)(MediaStore, [{
|
|
67
66
|
key: "removeCollectionFile",
|
|
@@ -7,19 +7,46 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.MobileUploadImpl = void 0;
|
|
8
8
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
9
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
11
|
var _mediaCommon = require("@atlaskit/media-common");
|
|
12
|
+
var _mediaState = require("@atlaskit/media-state");
|
|
11
13
|
var _fileStreamsCache = require("../file-streams-cache");
|
|
12
14
|
var _createFileDataLoader = require("../utils/createFileDataLoader");
|
|
13
15
|
var _mobileUpload = require("../utils/mobileUpload");
|
|
14
16
|
var MobileUploadImpl = /*#__PURE__*/function () {
|
|
15
|
-
function MobileUploadImpl(
|
|
17
|
+
function MobileUploadImpl(mediaApi) {
|
|
18
|
+
var _this = this;
|
|
19
|
+
var store = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _mediaState.mediaStore;
|
|
16
20
|
(0, _classCallCheck2.default)(this, MobileUploadImpl);
|
|
17
|
-
|
|
21
|
+
(0, _defineProperty2.default)(this, "getErrorFileState", function (error, id, occurrenceKey) {
|
|
22
|
+
return typeof error === 'string' ? {
|
|
23
|
+
status: 'error',
|
|
24
|
+
id: id,
|
|
25
|
+
reason: error,
|
|
26
|
+
occurrenceKey: occurrenceKey,
|
|
27
|
+
message: error
|
|
28
|
+
} : {
|
|
29
|
+
status: 'error',
|
|
30
|
+
id: id,
|
|
31
|
+
reason: error === null || error === void 0 ? void 0 : error.reason,
|
|
32
|
+
details: error === null || error === void 0 ? void 0 : error.attributes,
|
|
33
|
+
occurrenceKey: occurrenceKey,
|
|
34
|
+
message: error === null || error === void 0 ? void 0 : error.message
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
(0, _defineProperty2.default)(this, "setFileState", function (id, fileState) {
|
|
38
|
+
_this.store.setState(function (state) {
|
|
39
|
+
state.files[id] = fileState;
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
this.store = store;
|
|
43
|
+
this.dataloader = (0, _createFileDataLoader.createFileDataloader)(mediaApi);
|
|
18
44
|
this.servicesCache = (0, _mobileUpload.createServicesCache)();
|
|
19
45
|
}
|
|
20
46
|
(0, _createClass2.default)(MobileUploadImpl, [{
|
|
21
47
|
key: "notifyUploadStart",
|
|
22
48
|
value: function notifyUploadStart(event) {
|
|
49
|
+
var _this2 = this;
|
|
23
50
|
var fileId = event.fileId,
|
|
24
51
|
collectionName = event.collectionName,
|
|
25
52
|
occurrenceKey = event.occurrenceKey,
|
|
@@ -43,6 +70,15 @@ var MobileUploadImpl = /*#__PURE__*/function () {
|
|
|
43
70
|
};
|
|
44
71
|
var service = (0, _mobileUpload.createMobileUploadService)((0, _mobileUpload.createMobileUploadStateMachine)(this.dataloader, initialState, collectionName));
|
|
45
72
|
var subject = (0, _mobileUpload.createMobileFileStateSubject)(service);
|
|
73
|
+
subject.subscribe({
|
|
74
|
+
next: function next(fileState) {
|
|
75
|
+
_this2.setFileState(fileId, fileState);
|
|
76
|
+
},
|
|
77
|
+
error: function error(err) {
|
|
78
|
+
var errorFileState = _this2.getErrorFileState(err, fileId, occurrenceKey);
|
|
79
|
+
_this2.setFileState(fileId, errorFileState);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
46
82
|
this.servicesCache.set(fileId, service);
|
|
47
83
|
(0, _fileStreamsCache.getFileStreamsCache)().set(fileId, subject);
|
|
48
84
|
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -135,6 +135,12 @@ Object.defineProperty(exports, "getDimensionsFromBlob", {
|
|
|
135
135
|
return _getDimensionsFromBlob.getDimensionsFromBlob;
|
|
136
136
|
}
|
|
137
137
|
});
|
|
138
|
+
Object.defineProperty(exports, "getFileStreamsCache", {
|
|
139
|
+
enumerable: true,
|
|
140
|
+
get: function get() {
|
|
141
|
+
return _fileStreamsCache.getFileStreamsCache;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
138
144
|
Object.defineProperty(exports, "getMediaClient", {
|
|
139
145
|
enumerable: true,
|
|
140
146
|
get: function get() {
|
|
@@ -384,6 +390,7 @@ var _globalMediaEventEmitter = require("./globalMediaEventEmitter");
|
|
|
384
390
|
var _url = require("./utils/url");
|
|
385
391
|
var _mediaSubscribable = require("./utils/mediaSubscribable");
|
|
386
392
|
var _constants = require("./constants");
|
|
393
|
+
var _fileStreamsCache = require("./file-streams-cache");
|
|
387
394
|
var _mediaTypeUtils = require("@atlaskit/media-common/mediaTypeUtils");
|
|
388
395
|
// TODO MEX-659 Remove these exports when all the usages from media-client are replaced with media-common.
|
|
389
396
|
|
|
@@ -17,25 +17,17 @@ var _mediaClient = require("../client/media-client");
|
|
|
17
17
|
var _excluded = ["mediaClientConfig"];
|
|
18
18
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
19
19
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
20
|
-
var NO_FLAGS = 'NO_FLAGS';
|
|
21
20
|
var mediaClientsMap = new Map();
|
|
22
|
-
var getMediaClient = function getMediaClient(mediaClientConfig
|
|
23
|
-
var
|
|
24
|
-
var flagsMapKey = featureFlags || NO_FLAGS;
|
|
25
|
-
var mediaClient = (_mediaClientsMap$get = mediaClientsMap.get(mediaClientConfig)) === null || _mediaClientsMap$get === void 0 ? void 0 : _mediaClientsMap$get.get(flagsMapKey);
|
|
21
|
+
var getMediaClient = function getMediaClient(mediaClientConfig) {
|
|
22
|
+
var mediaClient = mediaClientsMap.get(mediaClientConfig);
|
|
26
23
|
if (!mediaClient) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
subMap = new Map();
|
|
30
|
-
mediaClientsMap.set(mediaClientConfig, subMap);
|
|
31
|
-
}
|
|
32
|
-
mediaClient = new _mediaClient.MediaClient(mediaClientConfig, featureFlags);
|
|
33
|
-
subMap.set(flagsMapKey, mediaClient);
|
|
24
|
+
mediaClient = new _mediaClient.MediaClient(mediaClientConfig);
|
|
25
|
+
mediaClientsMap.set(mediaClientConfig, mediaClient);
|
|
34
26
|
}
|
|
35
27
|
return mediaClient;
|
|
36
28
|
};
|
|
37
29
|
exports.getMediaClient = getMediaClient;
|
|
38
|
-
var createEmptyMediaClient = function createEmptyMediaClient(
|
|
30
|
+
var createEmptyMediaClient = function createEmptyMediaClient() {
|
|
39
31
|
var emptyConfig = {
|
|
40
32
|
authProvider: function authProvider() {
|
|
41
33
|
return Promise.resolve({
|
|
@@ -45,9 +37,9 @@ var createEmptyMediaClient = function createEmptyMediaClient(featureFlags) {
|
|
|
45
37
|
});
|
|
46
38
|
}
|
|
47
39
|
};
|
|
48
|
-
return new _mediaClient.MediaClient(emptyConfig
|
|
40
|
+
return new _mediaClient.MediaClient(emptyConfig);
|
|
49
41
|
};
|
|
50
|
-
var withMediaClient = function withMediaClient(Component
|
|
42
|
+
var withMediaClient = function withMediaClient(Component) {
|
|
51
43
|
return /*#__PURE__*/function (_React$Component) {
|
|
52
44
|
(0, _inherits2.default)(_class, _React$Component);
|
|
53
45
|
var _super = _createSuper(_class);
|
|
@@ -62,7 +54,7 @@ var withMediaClient = function withMediaClient(Component, featureFlags) {
|
|
|
62
54
|
var _this$props = this.props,
|
|
63
55
|
mediaClientConfig = _this$props.mediaClientConfig,
|
|
64
56
|
otherProps = (0, _objectWithoutProperties2.default)(_this$props, _excluded);
|
|
65
|
-
var mediaClient = !mediaClientConfig ? createEmptyMediaClient(
|
|
57
|
+
var mediaClient = !mediaClientConfig ? createEmptyMediaClient() : getMediaClient(mediaClientConfig);
|
|
66
58
|
return /*#__PURE__*/_react.default.createElement(Component, (0, _extends2.default)({}, otherProps, {
|
|
67
59
|
mediaClient: mediaClient
|
|
68
60
|
}));
|