@atlaskit/media-client 22.0.1 → 22.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.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/client/file-fetcher/index.js +3 -103
- package/dist/cjs/client/media-client.js +1 -1
- package/dist/cjs/client/media-store/index.js +13 -80
- package/dist/cjs/utils/shouldFetchRemoteFileStates.js +0 -5
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/client/file-fetcher/index.js +3 -104
- package/dist/es2019/client/media-client.js +1 -1
- package/dist/es2019/client/media-store/index.js +5 -45
- package/dist/es2019/utils/shouldFetchRemoteFileStates.js +0 -4
- package/dist/es2019/version.json +1 -1
- package/dist/esm/client/file-fetcher/index.js +4 -104
- package/dist/esm/client/media-client.js +1 -1
- package/dist/esm/client/media-store/index.js +13 -80
- package/dist/esm/utils/shouldFetchRemoteFileStates.js +0 -4
- package/dist/esm/version.json +1 -1
- package/dist/types/client/file-fetcher/error.d.ts +1 -1
- package/dist/types/client/file-fetcher/index.d.ts +4 -7
- package/dist/types/client/media-store/index.d.ts +1 -2
- package/dist/types/models/errors/types.d.ts +1 -1
- package/dist/types/utils/shouldFetchRemoteFileStates.d.ts +0 -2
- package/dist/types-ts4.5/client/__mocks__/collection-fetcher.d.ts +8 -0
- package/dist/types-ts4.5/client/__mocks__/file-fetcher.d.ts +10 -0
- package/dist/types-ts4.5/client/__mocks__/media-client.d.ts +11 -0
- package/dist/types-ts4.5/client/events.d.ts +14 -0
- package/dist/types-ts4.5/client/file-fetcher/error.d.ts +29 -0
- package/dist/types-ts4.5/client/file-fetcher/index.d.ts +58 -0
- package/dist/types-ts4.5/client/media-client.d.ts +27 -0
- package/dist/types-ts4.5/client/media-store/error.d.ts +16 -0
- package/dist/types-ts4.5/client/media-store/index.d.ts +169 -0
- package/dist/types-ts4.5/client/media-store/resolveAuth.d.ts +4 -0
- package/dist/types-ts4.5/client/mobile-upload.d.ts +11 -0
- package/dist/types-ts4.5/client/stargate-client.d.ts +15 -0
- package/dist/types-ts4.5/constants.d.ts +6 -0
- package/dist/types-ts4.5/file-streams-cache.d.ts +15 -0
- package/dist/types-ts4.5/globalMediaEventEmitter.d.ts +6 -0
- package/dist/types-ts4.5/identifier.d.ts +15 -0
- package/dist/types-ts4.5/index.d.ts +87 -0
- package/dist/types-ts4.5/models/artifacts.d.ts +12 -0
- package/dist/types-ts4.5/models/auth-headers.d.ts +11 -0
- package/dist/types-ts4.5/models/auth-query-parameters.d.ts +11 -0
- package/dist/types-ts4.5/models/errors/helpers.d.ts +6 -0
- package/dist/types-ts4.5/models/errors/index.d.ts +11 -0
- package/dist/types-ts4.5/models/errors/types.d.ts +15 -0
- package/dist/types-ts4.5/models/file-state.d.ts +94 -0
- package/dist/types-ts4.5/models/item.d.ts +25 -0
- package/dist/types-ts4.5/models/media.d.ts +48 -0
- package/dist/types-ts4.5/models/mobile-upload.d.ts +28 -0
- package/dist/types-ts4.5/upload-controller.d.ts +7 -0
- package/dist/types-ts4.5/uploader/calculateChunkSize.d.ts +11 -0
- package/dist/types-ts4.5/uploader/error.d.ts +29 -0
- package/dist/types-ts4.5/uploader/index.d.ts +22 -0
- package/dist/types-ts4.5/utils/checkWebpSupport.d.ts +1 -0
- package/dist/types-ts4.5/utils/convertBase64ToBlob.d.ts +1 -0
- package/dist/types-ts4.5/utils/createFileDataLoader.d.ts +30 -0
- package/dist/types-ts4.5/utils/createMediaSubject.d.ts +3 -0
- package/dist/types-ts4.5/utils/detectEmptyFile.d.ts +16 -0
- package/dist/types-ts4.5/utils/getDimensionsFromBlob.d.ts +6 -0
- package/dist/types-ts4.5/utils/getImageDimensionsFromBlob.d.ts +5 -0
- package/dist/types-ts4.5/utils/getMediaTypeFromUploadableFile.d.ts +3 -0
- package/dist/types-ts4.5/utils/getVideoDimensionsFromBlob.d.ts +5 -0
- package/dist/types-ts4.5/utils/hashing/hasher.d.ts +3 -0
- package/dist/types-ts4.5/utils/hashing/hasherCreator.d.ts +3 -0
- package/dist/types-ts4.5/utils/hashing/simpleHasher.d.ts +4 -0
- package/dist/types-ts4.5/utils/hashing/workerHasher.d.ts +16 -0
- package/dist/types-ts4.5/utils/imageResizeModeToFileImageMode.d.ts +3 -0
- package/dist/types-ts4.5/utils/isImageRemote.d.ts +1 -0
- package/dist/types-ts4.5/utils/mediaSubscribable/fromObservable.d.ts +5 -0
- package/dist/types-ts4.5/utils/mediaSubscribable/index.d.ts +3 -0
- package/dist/types-ts4.5/utils/mediaSubscribable/toPromise.d.ts +10 -0
- package/dist/types-ts4.5/utils/mediaSubscribable/types.d.ts +17 -0
- package/dist/types-ts4.5/utils/mobileUpload/error.d.ts +29 -0
- package/dist/types-ts4.5/utils/mobileUpload/helpers.d.ts +8 -0
- package/dist/types-ts4.5/utils/mobileUpload/index.d.ts +5 -0
- package/dist/types-ts4.5/utils/mobileUpload/servicesCache.d.ts +4 -0
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/index.d.ts +7 -0
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/error.d.ts +3 -0
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/processed.d.ts +3 -0
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/processing.d.ts +3 -0
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/processingFailed.d.ts +3 -0
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/uploading.d.ts +3 -0
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/types.d.ts +69 -0
- package/dist/types-ts4.5/utils/overrideMediaTypeIfUnknown.d.ts +5 -0
- package/dist/types-ts4.5/utils/polling/errors.d.ts +12 -0
- package/dist/types-ts4.5/utils/polling/index.d.ts +33 -0
- package/dist/types-ts4.5/utils/polling/types.d.ts +7 -0
- package/dist/types-ts4.5/utils/request/errors.d.ts +20 -0
- package/dist/types-ts4.5/utils/request/helpers.d.ts +46 -0
- package/dist/types-ts4.5/utils/request/index.d.ts +5 -0
- package/dist/types-ts4.5/utils/request/types.d.ts +46 -0
- package/dist/types-ts4.5/utils/safeUnsubscribe.d.ts +2 -0
- package/dist/types-ts4.5/utils/setTimeoutPromise.d.ts +2 -0
- package/dist/types-ts4.5/utils/shouldFetchRemoteFileStates.d.ts +14 -0
- package/dist/types-ts4.5/utils/url.d.ts +17 -0
- package/dist/types-ts4.5/utils/with-media-client-hoc.d.ts +16 -0
- package/package.json +4 -4
- package/report.api.md +11 -15
- package/dist/cjs/utils/parseJwt.js +0 -52
- package/dist/es2019/utils/parseJwt.js +0 -46
- package/dist/esm/utils/parseJwt.js +0 -46
- package/dist/types/utils/parseJwt.d.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/media-client
|
|
2
2
|
|
|
3
|
+
## 22.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`b098a252236`](https://bitbucket.org/atlassian/atlassian-frontend/commits/b098a252236) - Add emptyFileName as a reason to FileFetcherError.
|
|
8
|
+
- [`e725edbb0d9`](https://bitbucket.org/atlassian/atlassian-frontend/commits/e725edbb0d9) - Media Client now fetch remote file state regardless of file browser support (removed feature flag, permanent change)
|
|
9
|
+
- [`9425ed86eb7`](https://bitbucket.org/atlassian/atlassian-frontend/commits/9425ed86eb7) - File size limit is now verified in the backend, no longer the frontend
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 22.0.2
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- [`9d00501a414`](https://bitbucket.org/atlassian/atlassian-frontend/commits/9d00501a414) - Ensure legacy types are published for TS 4.5-4.8
|
|
17
|
+
- Updated dependencies
|
|
18
|
+
|
|
3
19
|
## 22.0.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -23,9 +23,7 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
|
|
|
23
23
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
24
24
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
25
25
|
var _Subscription = require("rxjs/Subscription");
|
|
26
|
-
var _of = require("rxjs/observable/of");
|
|
27
26
|
var _map = require("rxjs/operators/map");
|
|
28
|
-
var _concatMap = require("rxjs/operators/concatMap");
|
|
29
27
|
var _v = _interopRequireDefault(require("uuid/v4"));
|
|
30
28
|
require("setimmediate");
|
|
31
29
|
var _mediaCore = require("@atlaskit/media-core");
|
|
@@ -49,12 +47,11 @@ var _mediaTypeUtils = require("@atlaskit/media-common/mediaTypeUtils");
|
|
|
49
47
|
var _shouldFetchRemoteFileStates = require("../../utils/shouldFetchRemoteFileStates");
|
|
50
48
|
var _polling = require("../../utils/polling");
|
|
51
49
|
var _detectEmptyFile = require("../../utils/detectEmptyFile");
|
|
52
|
-
var _mediaCommon = require("@atlaskit/media-common");
|
|
53
50
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
54
51
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } // import setimmediate to temporary fix dataloader 2.0.0 bug
|
|
55
52
|
// @see https://github.com/graphql/dataloader/issues/249
|
|
56
53
|
var FileFetcherImpl = /*#__PURE__*/function () {
|
|
57
|
-
function FileFetcherImpl(mediaStore
|
|
54
|
+
function FileFetcherImpl(mediaStore) {
|
|
58
55
|
var _this = this;
|
|
59
56
|
(0, _classCallCheck2.default)(this, FileFetcherImpl);
|
|
60
57
|
// TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
|
|
@@ -152,7 +149,6 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
152
149
|
};
|
|
153
150
|
});
|
|
154
151
|
this.mediaStore = mediaStore;
|
|
155
|
-
this.featureFlags = featureFlags;
|
|
156
152
|
this.dataloader = (0, _createFileDataLoader.createFileDataloader)(mediaStore);
|
|
157
153
|
}
|
|
158
154
|
(0, _createClass2.default)(FileFetcherImpl, [{
|
|
@@ -344,10 +340,8 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
344
340
|
return uploadExternal;
|
|
345
341
|
}()
|
|
346
342
|
}, {
|
|
347
|
-
key: "
|
|
348
|
-
value:
|
|
349
|
-
// TODO: make this the public upload method when the FF is removed
|
|
350
|
-
function uploadAwlaysPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext) {
|
|
343
|
+
key: "upload",
|
|
344
|
+
value: function upload(file, controller, uploadableFileUpfrontIds, traceContext) {
|
|
351
345
|
var _this4 = this;
|
|
352
346
|
var collection = file.collection;
|
|
353
347
|
var upfrontId = uploadableFileUpfrontIds || this.generateUploadableFileUpfrontIds(collection, traceContext);
|
|
@@ -389,100 +383,6 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
389
383
|
setTimeout(onProgress, 0, 0);
|
|
390
384
|
return (0, _mediaSubscribable.fromObservable)(subject);
|
|
391
385
|
}
|
|
392
|
-
}, {
|
|
393
|
-
key: "uploadConditionallyPullFileStates",
|
|
394
|
-
value: function uploadConditionallyPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext) {
|
|
395
|
-
var _this5 = this;
|
|
396
|
-
if (typeof file.content === 'string') {
|
|
397
|
-
file.content = (0, _convertBase64ToBlob.convertBase64ToBlob)(file.content);
|
|
398
|
-
}
|
|
399
|
-
var content = file.content,
|
|
400
|
-
_file$name2 = file.name,
|
|
401
|
-
name = _file$name2 === void 0 ? '' : _file$name2,
|
|
402
|
-
collection = file.collection;
|
|
403
|
-
if (!uploadableFileUpfrontIds) {
|
|
404
|
-
uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
|
|
405
|
-
}
|
|
406
|
-
var id = uploadableFileUpfrontIds.id;
|
|
407
|
-
var occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
|
|
408
|
-
var mimeType = '';
|
|
409
|
-
var size = 0;
|
|
410
|
-
var preview;
|
|
411
|
-
// TODO [MSW-796]: get file size for base64
|
|
412
|
-
var mediaType = (0, _getMediaTypeFromUploadableFile.getMediaTypeFromUploadableFile)(file);
|
|
413
|
-
var subject = (0, _createMediaSubject.createMediaSubject)();
|
|
414
|
-
var processingSubscription = new _Subscription.Subscription();
|
|
415
|
-
if (content instanceof Blob) {
|
|
416
|
-
size = content.size;
|
|
417
|
-
mimeType = content.type;
|
|
418
|
-
if ((0, _mediaTypeUtils.isMimeTypeSupportedByBrowser)(content.type)) {
|
|
419
|
-
preview = {
|
|
420
|
-
value: content,
|
|
421
|
-
origin: 'local'
|
|
422
|
-
};
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
var stateBase = {
|
|
426
|
-
id: id,
|
|
427
|
-
occurrenceKey: occurrenceKey,
|
|
428
|
-
name: name,
|
|
429
|
-
size: size,
|
|
430
|
-
mediaType: mediaType,
|
|
431
|
-
mimeType: mimeType,
|
|
432
|
-
preview: preview
|
|
433
|
-
};
|
|
434
|
-
var onProgress = function onProgress(progress) {
|
|
435
|
-
subject.next(_objectSpread(_objectSpread({
|
|
436
|
-
status: 'uploading'
|
|
437
|
-
}, stateBase), {}, {
|
|
438
|
-
progress: progress
|
|
439
|
-
}));
|
|
440
|
-
};
|
|
441
|
-
var onUploadFinish = function onUploadFinish(error) {
|
|
442
|
-
if (error) {
|
|
443
|
-
return subject.error(error);
|
|
444
|
-
}
|
|
445
|
-
processingSubscription.add((0, _shouldFetchRemoteFileStates.shouldFetchRemoteFileStatesObservable)(mediaType, mimeType, preview).pipe((0, _concatMap.concatMap)(function (shouldFetchRemoteFileStates) {
|
|
446
|
-
if (shouldFetchRemoteFileStates) {
|
|
447
|
-
return _this5.createDownloadFileStream(id, collection, occurrenceKey).pipe((0, _map.map)(function (remoteFileState) {
|
|
448
|
-
return _objectSpread(_objectSpread(_objectSpread({}, stateBase), remoteFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(remoteFileState, mediaType));
|
|
449
|
-
}));
|
|
450
|
-
}
|
|
451
|
-
return (0, _of.of)(_objectSpread({
|
|
452
|
-
status: 'processing',
|
|
453
|
-
representations: {}
|
|
454
|
-
}, stateBase));
|
|
455
|
-
})).subscribe(subject));
|
|
456
|
-
};
|
|
457
|
-
var _uploadFile2 = (0, _uploader.uploadFile)(file, this.mediaStore, uploadableFileUpfrontIds, {
|
|
458
|
-
onUploadFinish: onUploadFinish,
|
|
459
|
-
onProgress: onProgress
|
|
460
|
-
}, traceContext),
|
|
461
|
-
cancel = _uploadFile2.cancel;
|
|
462
|
-
(0, _fileStreamsCache.getFileStreamsCache)().set(id, subject);
|
|
463
|
-
|
|
464
|
-
// We should report progress asynchronously, since this is what consumer expects
|
|
465
|
-
// (otherwise in newUploadService file-converting event will be emitted before files-added)
|
|
466
|
-
setTimeout(function () {
|
|
467
|
-
onProgress(0);
|
|
468
|
-
}, 0);
|
|
469
|
-
if (controller) {
|
|
470
|
-
controller.setAbort(function () {
|
|
471
|
-
cancel();
|
|
472
|
-
processingSubscription.unsubscribe();
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
return (0, _mediaSubscribable.fromObservable)(subject);
|
|
476
|
-
}
|
|
477
|
-
}, {
|
|
478
|
-
key: "upload",
|
|
479
|
-
value: function upload(file, controller, uploadableFileUpfrontIds, traceContext, featureFlags) {
|
|
480
|
-
var shouldAlwaysFetchFileState = (0, _mediaCommon.getMediaFeatureFlag)('fetchFileStateAfterUpload', featureFlags || this.featureFlags);
|
|
481
|
-
if (shouldAlwaysFetchFileState) {
|
|
482
|
-
return this.uploadAwlaysPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext);
|
|
483
|
-
}
|
|
484
|
-
return this.uploadConditionallyPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext);
|
|
485
|
-
}
|
|
486
386
|
|
|
487
387
|
// TODO: ----- ADD TICKET
|
|
488
388
|
}, {
|
|
@@ -30,7 +30,7 @@ var MediaClient = /*#__PURE__*/function () {
|
|
|
30
30
|
initialAuth: mediaClientConfig.initialAuth
|
|
31
31
|
}, featureFlags);
|
|
32
32
|
this.config = mediaClientConfig;
|
|
33
|
-
this.file = new _fileFetcher.FileFetcherImpl(this.mediaStore
|
|
33
|
+
this.file = new _fileFetcher.FileFetcherImpl(this.mediaStore);
|
|
34
34
|
this.eventEmitter = new _eventemitter.EventEmitter2();
|
|
35
35
|
this.stargate = new _stargateClient.StargateClient(mediaClientConfig.stargateBaseUrl);
|
|
36
36
|
}
|
|
@@ -18,10 +18,7 @@ Object.defineProperty(exports, "isMediaStoreError", {
|
|
|
18
18
|
return _error.isMediaStoreError;
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
22
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
23
21
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
24
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
25
22
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
26
23
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
27
24
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
@@ -32,9 +29,7 @@ var _artifacts = require("../../models/artifacts");
|
|
|
32
29
|
var _request3 = require("../../utils/request");
|
|
33
30
|
var _helpers = require("../../utils/request/helpers");
|
|
34
31
|
var _resolveAuth = require("./resolveAuth");
|
|
35
|
-
var _parseJwt = _interopRequireDefault(require("../../utils/parseJwt"));
|
|
36
32
|
var _error = require("./error");
|
|
37
|
-
var _excluded = ["size"];
|
|
38
33
|
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; }
|
|
39
34
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
40
35
|
var MEDIA_API_REGION = 'media-api-region';
|
|
@@ -234,17 +229,9 @@ var MediaStore = /*#__PURE__*/function () {
|
|
|
234
229
|
key: "touchFiles",
|
|
235
230
|
value: function () {
|
|
236
231
|
var _touchFiles = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(body) {
|
|
237
|
-
var _this2 = this;
|
|
238
232
|
var params,
|
|
239
233
|
traceContext,
|
|
240
234
|
metadata,
|
|
241
|
-
auth,
|
|
242
|
-
maxFileSize,
|
|
243
|
-
decoded,
|
|
244
|
-
_body$descriptors$red,
|
|
245
|
-
_body$descriptors$red2,
|
|
246
|
-
filteredDescriptors,
|
|
247
|
-
rejectedResponse,
|
|
248
235
|
options,
|
|
249
236
|
_args3 = arguments;
|
|
250
237
|
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
@@ -256,59 +243,16 @@ var MediaStore = /*#__PURE__*/function () {
|
|
|
256
243
|
method: 'POST',
|
|
257
244
|
endpoint: '/upload/createWithFiles'
|
|
258
245
|
};
|
|
259
|
-
_context3.next = 5;
|
|
260
|
-
return this.resolveAuth({
|
|
261
|
-
collectionName: params.collection
|
|
262
|
-
});
|
|
263
|
-
case 5:
|
|
264
|
-
auth = _context3.sent;
|
|
265
|
-
try {
|
|
266
|
-
decoded = (0, _parseJwt.default)(auth.token);
|
|
267
|
-
maxFileSize = decoded.fileSizeLimit;
|
|
268
|
-
} catch (error) {
|
|
269
|
-
// we're relying on the backend to throw an error when there's an invalid token
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// TODO MEX-2318: backend eventually will allow `size` in the body of this request, then some of this logic will need to be altered
|
|
273
|
-
_body$descriptors$red = body.descriptors.reduce(function (_ref, curr) {
|
|
274
|
-
var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
275
|
-
filtered = _ref2[0],
|
|
276
|
-
rejected = _ref2[1];
|
|
277
|
-
var size = curr.size,
|
|
278
|
-
descriptor = (0, _objectWithoutProperties2.default)(curr, _excluded);
|
|
279
|
-
if (maxFileSize && size && size > maxFileSize) {
|
|
280
|
-
return [filtered, [].concat((0, _toConsumableArray2.default)(rejected), [_this2.getRejectedResponseFromDescriptor(curr, maxFileSize)])];
|
|
281
|
-
}
|
|
282
|
-
return [[].concat((0, _toConsumableArray2.default)(filtered), [descriptor]), rejected];
|
|
283
|
-
}, [[], []]), _body$descriptors$red2 = (0, _slicedToArray2.default)(_body$descriptors$red, 2), filteredDescriptors = _body$descriptors$red2[0], rejectedResponse = _body$descriptors$red2[1];
|
|
284
246
|
options = _objectSpread(_objectSpread({}, metadata), {}, {
|
|
285
247
|
authContext: {
|
|
286
248
|
collectionName: params.collection
|
|
287
249
|
},
|
|
288
250
|
headers: jsonHeaders,
|
|
289
|
-
body: JSON.stringify(
|
|
290
|
-
|
|
291
|
-
})),
|
|
292
|
-
traceContext: traceContext,
|
|
293
|
-
resolvedAuth: auth
|
|
294
|
-
});
|
|
295
|
-
if (!(filteredDescriptors.length === 0)) {
|
|
296
|
-
_context3.next = 11;
|
|
297
|
-
break;
|
|
298
|
-
}
|
|
299
|
-
return _context3.abrupt("return", {
|
|
300
|
-
data: {
|
|
301
|
-
created: [],
|
|
302
|
-
rejected: rejectedResponse
|
|
303
|
-
}
|
|
251
|
+
body: JSON.stringify(body),
|
|
252
|
+
traceContext: traceContext
|
|
304
253
|
});
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
// TODO MEX-2318: backend eventually will include `rejected`, then this logic will need to be removed
|
|
308
|
-
res.data.rejected = rejectedResponse;
|
|
309
|
-
return res;
|
|
310
|
-
}));
|
|
311
|
-
case 12:
|
|
254
|
+
return _context3.abrupt("return", this.request('/upload/createWithFiles', options).then((0, _helpers.createMapResponseToJson)(metadata)));
|
|
255
|
+
case 5:
|
|
312
256
|
case "end":
|
|
313
257
|
return _context3.stop();
|
|
314
258
|
}
|
|
@@ -341,11 +285,11 @@ var MediaStore = /*#__PURE__*/function () {
|
|
|
341
285
|
key: "getFileImageURL",
|
|
342
286
|
value: function () {
|
|
343
287
|
var _getFileImageURL = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(id, params) {
|
|
344
|
-
var
|
|
288
|
+
var _ref, collectionName, auth;
|
|
345
289
|
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
346
290
|
while (1) switch (_context4.prev = _context4.next) {
|
|
347
291
|
case 0:
|
|
348
|
-
|
|
292
|
+
_ref = params || {}, collectionName = _ref.collection;
|
|
349
293
|
_context4.next = 3;
|
|
350
294
|
return this.resolveAuth({
|
|
351
295
|
collectionName: collectionName
|
|
@@ -631,7 +575,6 @@ var MediaStore = /*#__PURE__*/function () {
|
|
|
631
575
|
body,
|
|
632
576
|
clientOptions,
|
|
633
577
|
traceContext,
|
|
634
|
-
resolvedAuth,
|
|
635
578
|
auth,
|
|
636
579
|
extendedTraceContext,
|
|
637
580
|
response,
|
|
@@ -645,25 +588,15 @@ var MediaStore = /*#__PURE__*/function () {
|
|
|
645
588
|
authContext: {}
|
|
646
589
|
};
|
|
647
590
|
controller = _args11.length > 2 ? _args11[2] : undefined;
|
|
648
|
-
method = options.method, endpoint = options.endpoint, authContext = options.authContext, params = options.params, headers = options.headers, body = options.body, clientOptions = options.clientOptions, traceContext = options.traceContext
|
|
649
|
-
|
|
650
|
-
_context11.next = 7;
|
|
651
|
-
break;
|
|
652
|
-
}
|
|
653
|
-
_context11.t0 = resolvedAuth;
|
|
654
|
-
_context11.next = 10;
|
|
655
|
-
break;
|
|
656
|
-
case 7:
|
|
657
|
-
_context11.next = 9;
|
|
591
|
+
method = options.method, endpoint = options.endpoint, authContext = options.authContext, params = options.params, headers = options.headers, body = options.body, clientOptions = options.clientOptions, traceContext = options.traceContext;
|
|
592
|
+
_context11.next = 5;
|
|
658
593
|
return this.resolveAuth(authContext);
|
|
659
|
-
case
|
|
660
|
-
|
|
661
|
-
case 10:
|
|
662
|
-
auth = _context11.t0;
|
|
594
|
+
case 5:
|
|
595
|
+
auth = _context11.sent;
|
|
663
596
|
extendedTraceContext = traceContext ? _objectSpread(_objectSpread({}, traceContext), {}, {
|
|
664
597
|
spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || (0, _mediaCommon.getRandomHex)(8)
|
|
665
598
|
}) : undefined;
|
|
666
|
-
_context11.next =
|
|
599
|
+
_context11.next = 9;
|
|
667
600
|
return (0, _request3.request)("".concat(auth.baseUrl).concat(path), {
|
|
668
601
|
method: method,
|
|
669
602
|
endpoint: endpoint,
|
|
@@ -674,12 +607,12 @@ var MediaStore = /*#__PURE__*/function () {
|
|
|
674
607
|
clientOptions: clientOptions,
|
|
675
608
|
traceContext: extendedTraceContext
|
|
676
609
|
}, controller);
|
|
677
|
-
case
|
|
610
|
+
case 9:
|
|
678
611
|
response = _context11.sent;
|
|
679
612
|
setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
|
|
680
613
|
setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
|
|
681
614
|
return _context11.abrupt("return", response);
|
|
682
|
-
case
|
|
615
|
+
case 13:
|
|
683
616
|
case "end":
|
|
684
617
|
return _context11.stop();
|
|
685
618
|
}
|
|
@@ -5,10 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.shouldFetchRemoteFileStates = shouldFetchRemoteFileStates;
|
|
8
|
-
exports.shouldFetchRemoteFileStatesObservable = shouldFetchRemoteFileStatesObservable;
|
|
9
8
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
10
9
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
-
var _from = require("rxjs/observable/from");
|
|
12
10
|
var _mediaTypeUtils = require("@atlaskit/media-common/mediaTypeUtils");
|
|
13
11
|
var _getVideoDimensionsFromBlob = require("./getVideoDimensionsFromBlob");
|
|
14
12
|
/**
|
|
@@ -72,7 +70,4 @@ function _shouldFetchRemoteFileStates() {
|
|
|
72
70
|
}, _callee, null, [[8, 17]]);
|
|
73
71
|
}));
|
|
74
72
|
return _shouldFetchRemoteFileStates.apply(this, arguments);
|
|
75
|
-
}
|
|
76
|
-
function shouldFetchRemoteFileStatesObservable(mediaType, mimeType, preview) {
|
|
77
|
-
return (0, _from.from)(shouldFetchRemoteFileStates(mediaType, mimeType, preview));
|
|
78
73
|
}
|
package/dist/cjs/version.json
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
2
|
import { Subscription } from 'rxjs/Subscription';
|
|
3
|
-
import { of } from 'rxjs/observable/of';
|
|
4
3
|
import { map } from 'rxjs/operators/map';
|
|
5
|
-
import { concatMap } from 'rxjs/operators/concatMap';
|
|
6
4
|
import uuid from 'uuid/v4';
|
|
7
5
|
// import setimmediate to temporary fix dataloader 2.0.0 bug
|
|
8
6
|
// @see https://github.com/graphql/dataloader/issues/249
|
|
@@ -25,13 +23,12 @@ import { toPromise, fromObservable } from '../../utils/mediaSubscribable';
|
|
|
25
23
|
import { getDimensionsFromBlob } from '../../utils/getDimensionsFromBlob';
|
|
26
24
|
import { createMediaSubject } from '../../utils/createMediaSubject';
|
|
27
25
|
import { isMimeTypeSupportedByBrowser, getMediaTypeFromMimeType } from '@atlaskit/media-common/mediaTypeUtils';
|
|
28
|
-
import { shouldFetchRemoteFileStates
|
|
26
|
+
import { shouldFetchRemoteFileStates } from '../../utils/shouldFetchRemoteFileStates';
|
|
29
27
|
import { PollingFunction } from '../../utils/polling';
|
|
30
28
|
import { isEmptyFile } from '../../utils/detectEmptyFile';
|
|
31
|
-
import { getMediaFeatureFlag } from '@atlaskit/media-common';
|
|
32
29
|
export { isFileFetcherError, FileFetcherError } from './error';
|
|
33
30
|
export class FileFetcherImpl {
|
|
34
|
-
constructor(mediaStore
|
|
31
|
+
constructor(mediaStore) {
|
|
35
32
|
// TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
|
|
36
33
|
_defineProperty(this, "createDownloadFileStream", (id, collectionName, occurrenceKey) => {
|
|
37
34
|
const subject = createMediaSubject();
|
|
@@ -109,7 +106,6 @@ export class FileFetcherImpl {
|
|
|
109
106
|
};
|
|
110
107
|
});
|
|
111
108
|
this.mediaStore = mediaStore;
|
|
112
|
-
this.featureFlags = featureFlags;
|
|
113
109
|
this.dataloader = createFileDataloader(mediaStore);
|
|
114
110
|
}
|
|
115
111
|
getFileState(id, options = {}) {
|
|
@@ -230,8 +226,7 @@ export class FileFetcherImpl {
|
|
|
230
226
|
});
|
|
231
227
|
});
|
|
232
228
|
}
|
|
233
|
-
|
|
234
|
-
uploadAwlaysPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext) {
|
|
229
|
+
upload(file, controller, uploadableFileUpfrontIds, traceContext) {
|
|
235
230
|
const {
|
|
236
231
|
collection
|
|
237
232
|
} = file;
|
|
@@ -280,102 +275,6 @@ export class FileFetcherImpl {
|
|
|
280
275
|
setTimeout(onProgress, 0, 0);
|
|
281
276
|
return fromObservable(subject);
|
|
282
277
|
}
|
|
283
|
-
uploadConditionallyPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext) {
|
|
284
|
-
if (typeof file.content === 'string') {
|
|
285
|
-
file.content = convertBase64ToBlob(file.content);
|
|
286
|
-
}
|
|
287
|
-
const {
|
|
288
|
-
content,
|
|
289
|
-
name = '',
|
|
290
|
-
// name property is not available in base64 image
|
|
291
|
-
collection
|
|
292
|
-
} = file;
|
|
293
|
-
if (!uploadableFileUpfrontIds) {
|
|
294
|
-
uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
|
|
295
|
-
}
|
|
296
|
-
const id = uploadableFileUpfrontIds.id;
|
|
297
|
-
const occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
|
|
298
|
-
let mimeType = '';
|
|
299
|
-
let size = 0;
|
|
300
|
-
let preview;
|
|
301
|
-
// TODO [MSW-796]: get file size for base64
|
|
302
|
-
const mediaType = getMediaTypeFromUploadableFile(file);
|
|
303
|
-
const subject = createMediaSubject();
|
|
304
|
-
const processingSubscription = new Subscription();
|
|
305
|
-
if (content instanceof Blob) {
|
|
306
|
-
size = content.size;
|
|
307
|
-
mimeType = content.type;
|
|
308
|
-
if (isMimeTypeSupportedByBrowser(content.type)) {
|
|
309
|
-
preview = {
|
|
310
|
-
value: content,
|
|
311
|
-
origin: 'local'
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
const stateBase = {
|
|
316
|
-
id,
|
|
317
|
-
occurrenceKey,
|
|
318
|
-
name,
|
|
319
|
-
size,
|
|
320
|
-
mediaType,
|
|
321
|
-
mimeType,
|
|
322
|
-
preview
|
|
323
|
-
};
|
|
324
|
-
const onProgress = progress => {
|
|
325
|
-
subject.next({
|
|
326
|
-
status: 'uploading',
|
|
327
|
-
...stateBase,
|
|
328
|
-
progress
|
|
329
|
-
});
|
|
330
|
-
};
|
|
331
|
-
const onUploadFinish = error => {
|
|
332
|
-
if (error) {
|
|
333
|
-
return subject.error(error);
|
|
334
|
-
}
|
|
335
|
-
processingSubscription.add(shouldFetchRemoteFileStatesObservable(mediaType, mimeType, preview).pipe(concatMap(shouldFetchRemoteFileStates => {
|
|
336
|
-
if (shouldFetchRemoteFileStates) {
|
|
337
|
-
return this.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(remoteFileState => ({
|
|
338
|
-
// merges base state with remote state
|
|
339
|
-
...stateBase,
|
|
340
|
-
...remoteFileState,
|
|
341
|
-
...overrideMediaTypeIfUnknown(remoteFileState, mediaType)
|
|
342
|
-
})));
|
|
343
|
-
}
|
|
344
|
-
return of({
|
|
345
|
-
status: 'processing',
|
|
346
|
-
representations: {},
|
|
347
|
-
...stateBase
|
|
348
|
-
});
|
|
349
|
-
})).subscribe(subject));
|
|
350
|
-
};
|
|
351
|
-
const {
|
|
352
|
-
cancel
|
|
353
|
-
} = uploadFile(file, this.mediaStore, uploadableFileUpfrontIds, {
|
|
354
|
-
onUploadFinish,
|
|
355
|
-
onProgress
|
|
356
|
-
}, traceContext);
|
|
357
|
-
getFileStreamsCache().set(id, subject);
|
|
358
|
-
|
|
359
|
-
// We should report progress asynchronously, since this is what consumer expects
|
|
360
|
-
// (otherwise in newUploadService file-converting event will be emitted before files-added)
|
|
361
|
-
setTimeout(() => {
|
|
362
|
-
onProgress(0);
|
|
363
|
-
}, 0);
|
|
364
|
-
if (controller) {
|
|
365
|
-
controller.setAbort(() => {
|
|
366
|
-
cancel();
|
|
367
|
-
processingSubscription.unsubscribe();
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
return fromObservable(subject);
|
|
371
|
-
}
|
|
372
|
-
upload(file, controller, uploadableFileUpfrontIds, traceContext, featureFlags) {
|
|
373
|
-
const shouldAlwaysFetchFileState = getMediaFeatureFlag('fetchFileStateAfterUpload', featureFlags || this.featureFlags);
|
|
374
|
-
if (shouldAlwaysFetchFileState) {
|
|
375
|
-
return this.uploadAwlaysPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext);
|
|
376
|
-
}
|
|
377
|
-
return this.uploadConditionallyPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext);
|
|
378
|
-
}
|
|
379
278
|
|
|
380
279
|
// TODO: ----- ADD TICKET
|
|
381
280
|
async downloadBinary(id, name = 'download', collectionName) {
|
|
@@ -15,7 +15,7 @@ export class MediaClient {
|
|
|
15
15
|
initialAuth: mediaClientConfig.initialAuth
|
|
16
16
|
}, featureFlags);
|
|
17
17
|
this.config = mediaClientConfig;
|
|
18
|
-
this.file = new FileFetcherImpl(this.mediaStore
|
|
18
|
+
this.file = new FileFetcherImpl(this.mediaStore);
|
|
19
19
|
this.eventEmitter = new EventEmitter2();
|
|
20
20
|
this.stargate = new StargateClient(mediaClientConfig.stargateBaseUrl);
|
|
21
21
|
}
|
|
@@ -5,7 +5,6 @@ import { getArtifactUrl } from '../../models/artifacts';
|
|
|
5
5
|
import { request } from '../../utils/request';
|
|
6
6
|
import { createUrl, createMapResponseToJson, createMapResponseToBlob } from '../../utils/request/helpers';
|
|
7
7
|
import { resolveAuth, resolveInitialAuth } from './resolveAuth';
|
|
8
|
-
import parseJwt from '../../utils/parseJwt';
|
|
9
8
|
export { MediaStoreError, isMediaStoreError } from './error';
|
|
10
9
|
const MEDIA_API_REGION = 'media-api-region';
|
|
11
10
|
const MEDIA_API_ENVIRONMENT = 'media-api-environment';
|
|
@@ -158,54 +157,16 @@ export class MediaStore {
|
|
|
158
157
|
method: 'POST',
|
|
159
158
|
endpoint: '/upload/createWithFiles'
|
|
160
159
|
};
|
|
161
|
-
const auth = await this.resolveAuth({
|
|
162
|
-
collectionName: params.collection
|
|
163
|
-
});
|
|
164
|
-
let maxFileSize;
|
|
165
|
-
try {
|
|
166
|
-
const decoded = parseJwt(auth.token);
|
|
167
|
-
maxFileSize = decoded.fileSizeLimit;
|
|
168
|
-
} catch (error) {
|
|
169
|
-
// we're relying on the backend to throw an error when there's an invalid token
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// TODO MEX-2318: backend eventually will allow `size` in the body of this request, then some of this logic will need to be altered
|
|
173
|
-
const [filteredDescriptors, rejectedResponse] = body.descriptors.reduce(([filtered, rejected], curr) => {
|
|
174
|
-
const {
|
|
175
|
-
size,
|
|
176
|
-
...descriptor
|
|
177
|
-
} = curr;
|
|
178
|
-
if (maxFileSize && size && size > maxFileSize) {
|
|
179
|
-
return [filtered, [...rejected, this.getRejectedResponseFromDescriptor(curr, maxFileSize)]];
|
|
180
|
-
}
|
|
181
|
-
return [[...filtered, descriptor], rejected];
|
|
182
|
-
}, [[], []]);
|
|
183
160
|
const options = {
|
|
184
161
|
...metadata,
|
|
185
162
|
authContext: {
|
|
186
163
|
collectionName: params.collection
|
|
187
164
|
},
|
|
188
165
|
headers: jsonHeaders,
|
|
189
|
-
body: JSON.stringify(
|
|
190
|
-
|
|
191
|
-
descriptors: filteredDescriptors
|
|
192
|
-
}),
|
|
193
|
-
traceContext,
|
|
194
|
-
resolvedAuth: auth
|
|
166
|
+
body: JSON.stringify(body),
|
|
167
|
+
traceContext
|
|
195
168
|
};
|
|
196
|
-
|
|
197
|
-
return {
|
|
198
|
-
data: {
|
|
199
|
-
created: [],
|
|
200
|
-
rejected: rejectedResponse
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
return this.request('/upload/createWithFiles', options).then(createMapResponseToJson(metadata)).then(res => {
|
|
205
|
-
// TODO MEX-2318: backend eventually will include `rejected`, then this logic will need to be removed
|
|
206
|
-
res.data.rejected = rejectedResponse;
|
|
207
|
-
return res;
|
|
208
|
-
});
|
|
169
|
+
return this.request('/upload/createWithFiles', options).then(createMapResponseToJson(metadata));
|
|
209
170
|
}
|
|
210
171
|
getFile(fileId, params = {}, traceContext) {
|
|
211
172
|
const metadata = {
|
|
@@ -384,10 +345,9 @@ export class MediaStore {
|
|
|
384
345
|
headers,
|
|
385
346
|
body,
|
|
386
347
|
clientOptions,
|
|
387
|
-
traceContext
|
|
388
|
-
resolvedAuth
|
|
348
|
+
traceContext
|
|
389
349
|
} = options;
|
|
390
|
-
const auth =
|
|
350
|
+
const auth = await this.resolveAuth(authContext);
|
|
391
351
|
const extendedTraceContext = traceContext ? {
|
|
392
352
|
...traceContext,
|
|
393
353
|
spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || getRandomHex(8)
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { from } from 'rxjs/observable/from';
|
|
2
1
|
import { isMimeTypeSupportedByBrowser, isMimeTypeSupportedByServer } from '@atlaskit/media-common/mediaTypeUtils';
|
|
3
2
|
import { getVideoDimensionsFromBlob } from './getVideoDimensionsFromBlob';
|
|
4
3
|
|
|
@@ -35,7 +34,4 @@ export async function shouldFetchRemoteFileStates(mediaType, mimeType, preview)
|
|
|
35
34
|
}
|
|
36
35
|
}
|
|
37
36
|
return false;
|
|
38
|
-
}
|
|
39
|
-
export function shouldFetchRemoteFileStatesObservable(mediaType, mimeType, preview) {
|
|
40
|
-
return from(shouldFetchRemoteFileStates(mediaType, mimeType, preview));
|
|
41
37
|
}
|
package/dist/es2019/version.json
CHANGED