@atlaskit/media-client 23.2.0 → 24.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +93 -74
- package/dist/cjs/client/file-fetcher/error.js +1 -2
- package/dist/cjs/client/file-fetcher/index.js +113 -38
- package/dist/cjs/client/media-client.js +20 -9
- package/dist/cjs/client/media-store/error.js +1 -2
- package/dist/cjs/client/media-store/index.js +5 -9
- package/dist/cjs/client/media-store/resolveAuth.js +4 -7
- package/dist/cjs/client/mobile-upload.js +40 -5
- package/dist/cjs/client/stargate-client.js +2 -3
- package/dist/cjs/constants.js +6 -12
- package/dist/cjs/file-streams-cache.js +3 -5
- package/dist/cjs/globalMediaEventEmitter.js +2 -3
- package/dist/cjs/identifier.js +4 -7
- package/dist/cjs/index.js +17 -20
- package/dist/cjs/models/artifacts.js +2 -3
- package/dist/cjs/models/errors/index.js +2 -3
- package/dist/cjs/models/file-state.js +10 -19
- package/dist/cjs/models/media.js +3 -5
- package/dist/cjs/test-helpers/authProvider.js +2 -3
- package/dist/cjs/test-helpers/collectionNames.js +5 -10
- package/dist/cjs/test-helpers/exampleMediaItems.js +48 -91
- package/dist/cjs/test-helpers/fakeMediaClient.js +3 -5
- package/dist/cjs/test-helpers/index.js +1 -2
- package/dist/cjs/test-helpers/mediaClientProvider.js +7 -13
- package/dist/cjs/test-helpers/mediaPickerAuthProvider.js +4 -7
- package/dist/cjs/upload-controller.js +2 -3
- package/dist/cjs/uploader/calculateChunkSize.js +4 -5
- package/dist/cjs/uploader/error.js +1 -2
- package/dist/cjs/uploader/index.js +3 -4
- package/dist/cjs/utils/checkWebpSupport.js +2 -3
- package/dist/cjs/utils/convertBase64ToBlob.js +2 -3
- package/dist/cjs/utils/createFileDataLoader.js +2 -4
- package/dist/cjs/utils/detectEmptyFile.js +2 -2
- package/dist/cjs/utils/getDimensionsFromBlob.js +2 -3
- package/dist/cjs/utils/getImageDimensionsFromBlob.js +2 -3
- package/dist/cjs/utils/getMediaTypeFromUploadableFile.js +2 -3
- package/dist/cjs/utils/getVideoDimensionsFromBlob.js +2 -3
- package/dist/cjs/utils/hashing/hasherCreator.js +3 -5
- package/dist/cjs/utils/hashing/simpleHasher.js +4 -4
- package/dist/cjs/utils/hashing/workerHasher.js +2 -3
- package/dist/cjs/utils/imageResizeModeToFileImageMode.js +2 -3
- package/dist/cjs/utils/isImageRemote.js +2 -3
- package/dist/cjs/utils/mediaSubscribable/toPromise.js +2 -3
- package/dist/cjs/utils/mobileUpload/error.js +1 -2
- package/dist/cjs/utils/mobileUpload/helpers.js +3 -5
- package/dist/cjs/utils/mobileUpload/stateMachine/index.js +1 -2
- package/dist/cjs/utils/mobileUpload/stateMachine/states/error.js +2 -3
- package/dist/cjs/utils/mobileUpload/stateMachine/states/processed.js +2 -3
- package/dist/cjs/utils/mobileUpload/stateMachine/states/processing.js +2 -3
- package/dist/cjs/utils/mobileUpload/stateMachine/states/processingFailed.js +2 -3
- package/dist/cjs/utils/mobileUpload/stateMachine/states/uploading.js +2 -3
- package/dist/cjs/utils/overrideMediaTypeIfUnknown.js +2 -3
- package/dist/cjs/utils/polling/errors.js +1 -2
- package/dist/cjs/utils/polling/index.js +3 -5
- package/dist/cjs/utils/request/errors.js +1 -2
- package/dist/cjs/utils/request/helpers.js +4 -5
- package/dist/cjs/utils/safeUnsubscribe.js +2 -3
- package/dist/cjs/utils/setTimeoutPromise.js +3 -5
- package/dist/cjs/utils/url.js +5 -9
- package/dist/cjs/utils/with-media-client-hoc.js +9 -19
- 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/hashing/simpleHasher.js +2 -1
- package/dist/es2019/utils/request/helpers.js +1 -1
- package/dist/es2019/utils/with-media-client-hoc.js +8 -16
- package/dist/esm/client/file-fetcher/index.js +107 -31
- 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/uploader/index.js +2 -2
- package/dist/esm/utils/hashing/simpleHasher.js +2 -1
- package/dist/esm/utils/request/helpers.js +1 -1
- 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/package.json +5 -3
- package/report.api.md +51 -168
- package/dist/types-ts4.5/client/__mocks__/collection-fetcher.d.ts +0 -8
- package/dist/types-ts4.5/client/__mocks__/file-fetcher.d.ts +0 -10
- package/dist/types-ts4.5/client/__mocks__/media-client.d.ts +0 -11
- package/dist/types-ts4.5/client/events.d.ts +0 -14
- package/dist/types-ts4.5/client/file-fetcher/error.d.ts +0 -29
- package/dist/types-ts4.5/client/file-fetcher/index.d.ts +0 -58
- package/dist/types-ts4.5/client/media-client.d.ts +0 -27
- package/dist/types-ts4.5/client/media-store/error.d.ts +0 -16
- package/dist/types-ts4.5/client/media-store/index.d.ts +0 -169
- package/dist/types-ts4.5/client/media-store/resolveAuth.d.ts +0 -4
- package/dist/types-ts4.5/client/mobile-upload.d.ts +0 -11
- package/dist/types-ts4.5/client/stargate-client.d.ts +0 -15
- package/dist/types-ts4.5/constants.d.ts +0 -6
- package/dist/types-ts4.5/file-streams-cache.d.ts +0 -15
- package/dist/types-ts4.5/globalMediaEventEmitter.d.ts +0 -6
- package/dist/types-ts4.5/identifier.d.ts +0 -15
- package/dist/types-ts4.5/index.d.ts +0 -87
- package/dist/types-ts4.5/models/artifacts.d.ts +0 -15
- package/dist/types-ts4.5/models/auth-headers.d.ts +0 -11
- package/dist/types-ts4.5/models/auth-query-parameters.d.ts +0 -11
- package/dist/types-ts4.5/models/errors/helpers.d.ts +0 -6
- package/dist/types-ts4.5/models/errors/index.d.ts +0 -11
- package/dist/types-ts4.5/models/errors/types.d.ts +0 -15
- package/dist/types-ts4.5/models/file-state.d.ts +0 -94
- package/dist/types-ts4.5/models/item.d.ts +0 -25
- package/dist/types-ts4.5/models/media.d.ts +0 -48
- package/dist/types-ts4.5/models/mobile-upload.d.ts +0 -28
- package/dist/types-ts4.5/test-helpers/_numbers.d.ts +0 -1
- package/dist/types-ts4.5/test-helpers/authProvider.d.ts +0 -6
- package/dist/types-ts4.5/test-helpers/collectionNames.d.ts +0 -5
- package/dist/types-ts4.5/test-helpers/exampleMediaItems.d.ts +0 -53
- package/dist/types-ts4.5/test-helpers/fakeMediaClient.d.ts +0 -4
- package/dist/types-ts4.5/test-helpers/index.d.ts +0 -7
- package/dist/types-ts4.5/test-helpers/mediaClientProvider.d.ts +0 -23
- package/dist/types-ts4.5/test-helpers/mediaPickerAuthProvider.d.ts +0 -5
- package/dist/types-ts4.5/upload-controller.d.ts +0 -7
- package/dist/types-ts4.5/uploader/calculateChunkSize.d.ts +0 -11
- package/dist/types-ts4.5/uploader/error.d.ts +0 -29
- package/dist/types-ts4.5/uploader/index.d.ts +0 -23
- package/dist/types-ts4.5/utils/checkWebpSupport.d.ts +0 -1
- package/dist/types-ts4.5/utils/convertBase64ToBlob.d.ts +0 -1
- package/dist/types-ts4.5/utils/createFileDataLoader.d.ts +0 -30
- package/dist/types-ts4.5/utils/createMediaSubject.d.ts +0 -3
- package/dist/types-ts4.5/utils/detectEmptyFile.d.ts +0 -16
- package/dist/types-ts4.5/utils/getDimensionsFromBlob.d.ts +0 -6
- package/dist/types-ts4.5/utils/getImageDimensionsFromBlob.d.ts +0 -5
- package/dist/types-ts4.5/utils/getMediaTypeFromUploadableFile.d.ts +0 -3
- package/dist/types-ts4.5/utils/getVideoDimensionsFromBlob.d.ts +0 -5
- package/dist/types-ts4.5/utils/hashing/hasher.d.ts +0 -3
- package/dist/types-ts4.5/utils/hashing/hasherCreator.d.ts +0 -3
- package/dist/types-ts4.5/utils/hashing/simpleHasher.d.ts +0 -4
- package/dist/types-ts4.5/utils/hashing/workerHasher.d.ts +0 -16
- package/dist/types-ts4.5/utils/imageResizeModeToFileImageMode.d.ts +0 -3
- package/dist/types-ts4.5/utils/isImageRemote.d.ts +0 -1
- package/dist/types-ts4.5/utils/mediaSubscribable/fromObservable.d.ts +0 -5
- package/dist/types-ts4.5/utils/mediaSubscribable/index.d.ts +0 -3
- package/dist/types-ts4.5/utils/mediaSubscribable/toPromise.d.ts +0 -10
- package/dist/types-ts4.5/utils/mediaSubscribable/types.d.ts +0 -17
- package/dist/types-ts4.5/utils/mobileUpload/error.d.ts +0 -29
- package/dist/types-ts4.5/utils/mobileUpload/helpers.d.ts +0 -8
- package/dist/types-ts4.5/utils/mobileUpload/index.d.ts +0 -5
- package/dist/types-ts4.5/utils/mobileUpload/servicesCache.d.ts +0 -4
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/index.d.ts +0 -7
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/error.d.ts +0 -3
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/processed.d.ts +0 -3
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/processing.d.ts +0 -3
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/processingFailed.d.ts +0 -3
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/states/uploading.d.ts +0 -3
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/types.d.ts +0 -69
- package/dist/types-ts4.5/utils/overrideMediaTypeIfUnknown.d.ts +0 -5
- package/dist/types-ts4.5/utils/polling/errors.d.ts +0 -12
- package/dist/types-ts4.5/utils/polling/index.d.ts +0 -33
- package/dist/types-ts4.5/utils/polling/types.d.ts +0 -7
- package/dist/types-ts4.5/utils/request/errors.d.ts +0 -20
- package/dist/types-ts4.5/utils/request/helpers.d.ts +0 -46
- package/dist/types-ts4.5/utils/request/index.d.ts +0 -5
- package/dist/types-ts4.5/utils/request/types.d.ts +0 -46
- package/dist/types-ts4.5/utils/safeUnsubscribe.d.ts +0 -2
- package/dist/types-ts4.5/utils/setTimeoutPromise.d.ts +0 -2
- package/dist/types-ts4.5/utils/shouldFetchRemoteFileStates.d.ts +0 -14
- package/dist/types-ts4.5/utils/url.d.ts +0 -17
- package/dist/types-ts4.5/utils/with-media-client-hoc.d.ts +0 -16
- package/tmp/api-report-tmp.d.ts +0 -1334
|
@@ -14,7 +14,7 @@ var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/ge
|
|
|
14
14
|
var _errors = require("../../models/errors");
|
|
15
15
|
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); }; }
|
|
16
16
|
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; } }
|
|
17
|
-
var RequestError = /*#__PURE__*/function (_BaseMediaClientError) {
|
|
17
|
+
var RequestError = exports.RequestError = /*#__PURE__*/function (_BaseMediaClientError) {
|
|
18
18
|
(0, _inherits2.default)(RequestError, _BaseMediaClientError);
|
|
19
19
|
var _super = _createSuper(RequestError);
|
|
20
20
|
function RequestError(reason, metadata, innerError) {
|
|
@@ -55,7 +55,6 @@ var RequestError = /*#__PURE__*/function (_BaseMediaClientError) {
|
|
|
55
55
|
}]);
|
|
56
56
|
return RequestError;
|
|
57
57
|
}(_errors.BaseMediaClientError);
|
|
58
|
-
exports.RequestError = RequestError;
|
|
59
58
|
function isRequestError(err) {
|
|
60
59
|
return err instanceof RequestError;
|
|
61
60
|
}
|
|
@@ -35,7 +35,7 @@ var _errors = require("./errors");
|
|
|
35
35
|
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; }
|
|
36
36
|
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; }
|
|
37
37
|
function clientTimeoutPromise(timeout) {
|
|
38
|
-
return new Promise(function (
|
|
38
|
+
return new Promise(function (_, reject) {
|
|
39
39
|
setTimeout(reject, timeout, new _errors.RequestError('clientTimeoutRequest'));
|
|
40
40
|
});
|
|
41
41
|
}
|
|
@@ -55,14 +55,13 @@ function isFetchNetworkError(err) {
|
|
|
55
55
|
function isRateLimitedError(error) {
|
|
56
56
|
return !!error && (0, _errors.isRequestError)(error) && error.attributes.statusCode === 429 || !!error && !!error.message && error.message.includes('429');
|
|
57
57
|
}
|
|
58
|
-
var ZipkinHeaderKeys = {
|
|
58
|
+
var ZipkinHeaderKeys = exports.ZipkinHeaderKeys = {
|
|
59
59
|
traceId: 'x-b3-traceid',
|
|
60
60
|
spanId: 'x-b3-spanid',
|
|
61
61
|
parentSpanId: 'x-b3-parentspanid',
|
|
62
62
|
sampled: 'x-b3-sampled',
|
|
63
63
|
flags: 'x-b3-flags'
|
|
64
64
|
};
|
|
65
|
-
exports.ZipkinHeaderKeys = ZipkinHeaderKeys;
|
|
66
65
|
var mapTraceIdToRequestHeaders = function mapTraceIdToRequestHeaders(traceContext) {
|
|
67
66
|
var _ref;
|
|
68
67
|
return traceContext ? (_ref = {}, (0, _defineProperty2.default)(_ref, ZipkinHeaderKeys.traceId, traceContext.traceId), (0, _defineProperty2.default)(_ref, ZipkinHeaderKeys.spanId, traceContext.spanId), _ref) : {};
|
|
@@ -238,14 +237,14 @@ function createMapResponseToBlob(metadata) {
|
|
|
238
237
|
};
|
|
239
238
|
}();
|
|
240
239
|
}
|
|
241
|
-
var DEFAULT_RETRY_OPTIONS = {
|
|
240
|
+
var DEFAULT_RETRY_OPTIONS = exports.DEFAULT_RETRY_OPTIONS = {
|
|
242
241
|
startTimeoutInMs: 1000,
|
|
243
242
|
// 1 second is generally a good timeout to start
|
|
244
243
|
maxAttempts: 5,
|
|
245
244
|
// Current test delay is 60s, so retries should finish before if a promise takes < 1s
|
|
246
245
|
factor: 2 // Good for polling, which is out main use case
|
|
247
246
|
};
|
|
248
|
-
|
|
247
|
+
|
|
249
248
|
function cloneRequestError(error, extraMetadata) {
|
|
250
249
|
var reason = error.reason,
|
|
251
250
|
metadata = error.metadata,
|
|
@@ -5,11 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.safeUnsubscribe = void 0;
|
|
7
7
|
// TODO: remove this in next major version
|
|
8
|
-
var safeUnsubscribe = function safeUnsubscribe(subscription) {
|
|
8
|
+
var safeUnsubscribe = exports.safeUnsubscribe = function safeUnsubscribe(subscription) {
|
|
9
9
|
// eslint-disable-next-line no-console
|
|
10
10
|
console.warn('safeUnsubscribe() is deprecated and will be removed in the next media-client major version');
|
|
11
11
|
setTimeout(function () {
|
|
12
12
|
return subscription && subscription.unsubscribe();
|
|
13
13
|
}, 0);
|
|
14
|
-
};
|
|
15
|
-
exports.safeUnsubscribe = safeUnsubscribe;
|
|
14
|
+
};
|
|
@@ -4,15 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.resolveTimeout = exports.rejectTimeout = void 0;
|
|
7
|
-
var resolveTimeout = function resolveTimeout(timeout, resolveWith) {
|
|
7
|
+
var resolveTimeout = exports.resolveTimeout = function resolveTimeout(timeout, resolveWith) {
|
|
8
8
|
return new Promise(function (resolve, _reject) {
|
|
9
9
|
setTimeout(resolve, timeout, resolveWith);
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
|
-
exports.
|
|
13
|
-
var rejectTimeout = function rejectTimeout(timeout, rejectWith) {
|
|
12
|
+
var rejectTimeout = exports.rejectTimeout = function rejectTimeout(timeout, rejectWith) {
|
|
14
13
|
return new Promise(function (_resolve, reject) {
|
|
15
14
|
setTimeout(reject, timeout, rejectWith);
|
|
16
15
|
});
|
|
17
|
-
};
|
|
18
|
-
exports.rejectTimeout = rejectTimeout;
|
|
16
|
+
};
|
package/dist/cjs/utils/url.js
CHANGED
|
@@ -9,10 +9,9 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
|
9
9
|
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; }
|
|
10
10
|
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; }
|
|
11
11
|
var mediaBlobUrlIdentifier = 'media-blob-url';
|
|
12
|
-
var isMediaBlobUrl = function isMediaBlobUrl(url) {
|
|
12
|
+
var isMediaBlobUrl = exports.isMediaBlobUrl = function isMediaBlobUrl(url) {
|
|
13
13
|
return url.indexOf("".concat(mediaBlobUrlIdentifier, "=true")) > -1;
|
|
14
14
|
};
|
|
15
|
-
exports.isMediaBlobUrl = isMediaBlobUrl;
|
|
16
15
|
var getNumberFromParams = function getNumberFromParams(params, name) {
|
|
17
16
|
var value = params.get(name);
|
|
18
17
|
return typeof value === 'string' && !isNaN(parseInt(value)) ? parseInt(value) : undefined;
|
|
@@ -24,7 +23,7 @@ var getStringFromParams = function getStringFromParams(params, name) {
|
|
|
24
23
|
}
|
|
25
24
|
return decodeURIComponent(value);
|
|
26
25
|
};
|
|
27
|
-
var getAttrsFromUrl = function getAttrsFromUrl(blobUrl) {
|
|
26
|
+
var getAttrsFromUrl = exports.getAttrsFromUrl = function getAttrsFromUrl(blobUrl) {
|
|
28
27
|
var url = new URL(blobUrl);
|
|
29
28
|
var hash = url.hash.replace('#', '');
|
|
30
29
|
var params = new URLSearchParams(hash);
|
|
@@ -46,8 +45,7 @@ var getAttrsFromUrl = function getAttrsFromUrl(blobUrl) {
|
|
|
46
45
|
mimeType: getStringFromParams(params, 'mimeType')
|
|
47
46
|
};
|
|
48
47
|
};
|
|
49
|
-
exports.
|
|
50
|
-
var objectToQueryString = function objectToQueryString(json) {
|
|
48
|
+
var objectToQueryString = exports.objectToQueryString = function objectToQueryString(json) {
|
|
51
49
|
return Object.keys(json).filter(function (attrName) {
|
|
52
50
|
return typeof json[attrName] !== 'undefined' && json[attrName] !== null;
|
|
53
51
|
}).map(function (key) {
|
|
@@ -58,8 +56,7 @@ var objectToQueryString = function objectToQueryString(json) {
|
|
|
58
56
|
return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value.toString()));
|
|
59
57
|
}).join('&');
|
|
60
58
|
};
|
|
61
|
-
exports.
|
|
62
|
-
var addFileAttrsToUrl = function addFileAttrsToUrl(url, fileAttrs) {
|
|
59
|
+
var addFileAttrsToUrl = exports.addFileAttrsToUrl = function addFileAttrsToUrl(url, fileAttrs) {
|
|
63
60
|
var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
64
61
|
if (isSafari) {
|
|
65
62
|
return url;
|
|
@@ -70,5 +67,4 @@ var addFileAttrsToUrl = function addFileAttrsToUrl(url, fileAttrs) {
|
|
|
70
67
|
|
|
71
68
|
// we can't use '?' separator for blob url params
|
|
72
69
|
return "".concat(url, "#").concat(queryAttrs);
|
|
73
|
-
};
|
|
74
|
-
exports.addFileAttrsToUrl = addFileAttrsToUrl;
|
|
70
|
+
};
|
|
@@ -17,25 +17,16 @@ 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 = exports.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
|
-
|
|
38
|
-
var createEmptyMediaClient = function createEmptyMediaClient(featureFlags) {
|
|
29
|
+
var createEmptyMediaClient = function createEmptyMediaClient() {
|
|
39
30
|
var emptyConfig = {
|
|
40
31
|
authProvider: function authProvider() {
|
|
41
32
|
return Promise.resolve({
|
|
@@ -45,9 +36,9 @@ var createEmptyMediaClient = function createEmptyMediaClient(featureFlags) {
|
|
|
45
36
|
});
|
|
46
37
|
}
|
|
47
38
|
};
|
|
48
|
-
return new _mediaClient.MediaClient(emptyConfig
|
|
39
|
+
return new _mediaClient.MediaClient(emptyConfig);
|
|
49
40
|
};
|
|
50
|
-
var withMediaClient = function withMediaClient(Component
|
|
41
|
+
var withMediaClient = exports.withMediaClient = function withMediaClient(Component) {
|
|
51
42
|
return /*#__PURE__*/function (_React$Component) {
|
|
52
43
|
(0, _inherits2.default)(_class, _React$Component);
|
|
53
44
|
var _super = _createSuper(_class);
|
|
@@ -62,7 +53,7 @@ var withMediaClient = function withMediaClient(Component, featureFlags) {
|
|
|
62
53
|
var _this$props = this.props,
|
|
63
54
|
mediaClientConfig = _this$props.mediaClientConfig,
|
|
64
55
|
otherProps = (0, _objectWithoutProperties2.default)(_this$props, _excluded);
|
|
65
|
-
var mediaClient = !mediaClientConfig ? createEmptyMediaClient(
|
|
56
|
+
var mediaClient = !mediaClientConfig ? createEmptyMediaClient() : getMediaClient(mediaClientConfig);
|
|
66
57
|
return /*#__PURE__*/_react.default.createElement(Component, (0, _extends2.default)({}, otherProps, {
|
|
67
58
|
mediaClient: mediaClient
|
|
68
59
|
}));
|
|
@@ -70,5 +61,4 @@ var withMediaClient = function withMediaClient(Component, featureFlags) {
|
|
|
70
61
|
}]);
|
|
71
62
|
return _class;
|
|
72
63
|
}(_react.default.Component);
|
|
73
|
-
};
|
|
74
|
-
exports.withMediaClient = withMediaClient;
|
|
64
|
+
};
|
|
@@ -7,7 +7,7 @@ import uuid from 'uuid/v4';
|
|
|
7
7
|
import 'setimmediate';
|
|
8
8
|
import { authToOwner } from '@atlaskit/media-core';
|
|
9
9
|
import { downloadUrl } from '@atlaskit/media-common/downloadUrl';
|
|
10
|
-
import { MediaStore } from '../media-store';
|
|
10
|
+
import { MediaStore as MediaApi } from '../media-store';
|
|
11
11
|
import { isErrorFileState, isFinalFileState, isProcessingFileState, mapMediaFileToFileState, mapMediaItemToFileState } from '../../models/file-state';
|
|
12
12
|
import { FileFetcherError } from './error';
|
|
13
13
|
import { uploadFile } from '../../uploader';
|
|
@@ -26,9 +26,29 @@ import { isMimeTypeSupportedByBrowser, getMediaTypeFromMimeType } from '@atlaski
|
|
|
26
26
|
import { shouldFetchRemoteFileStates } from '../../utils/shouldFetchRemoteFileStates';
|
|
27
27
|
import { PollingFunction } from '../../utils/polling';
|
|
28
28
|
import { isEmptyFile } from '../../utils/detectEmptyFile';
|
|
29
|
+
import { mediaStore } from '@atlaskit/media-state';
|
|
29
30
|
export { isFileFetcherError, FileFetcherError } from './error';
|
|
30
31
|
export class FileFetcherImpl {
|
|
31
|
-
constructor(mediaStore) {
|
|
32
|
+
constructor(mediaApi, store = mediaStore) {
|
|
33
|
+
_defineProperty(this, "getErrorFileState", (error, id, occurrenceKey) => typeof error === 'string' ? {
|
|
34
|
+
status: 'error',
|
|
35
|
+
id,
|
|
36
|
+
reason: error,
|
|
37
|
+
occurrenceKey,
|
|
38
|
+
message: error
|
|
39
|
+
} : {
|
|
40
|
+
status: 'error',
|
|
41
|
+
id,
|
|
42
|
+
reason: error === null || error === void 0 ? void 0 : error.reason,
|
|
43
|
+
details: error === null || error === void 0 ? void 0 : error.attributes,
|
|
44
|
+
occurrenceKey,
|
|
45
|
+
message: error === null || error === void 0 ? void 0 : error.message
|
|
46
|
+
});
|
|
47
|
+
_defineProperty(this, "setFileState", (id, fileState) => {
|
|
48
|
+
this.store.setState(state => {
|
|
49
|
+
state.files[id] = fileState;
|
|
50
|
+
});
|
|
51
|
+
});
|
|
32
52
|
// TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
|
|
33
53
|
_defineProperty(this, "createDownloadFileStream", (id, collectionName, occurrenceKey) => {
|
|
34
54
|
const subject = createMediaSubject();
|
|
@@ -105,8 +125,9 @@ export class FileFetcherImpl {
|
|
|
105
125
|
preview
|
|
106
126
|
};
|
|
107
127
|
});
|
|
108
|
-
this.
|
|
109
|
-
this.
|
|
128
|
+
this.mediaApi = mediaApi;
|
|
129
|
+
this.store = store;
|
|
130
|
+
this.dataloader = createFileDataloader(mediaApi);
|
|
110
131
|
}
|
|
111
132
|
getFileState(id, options = {}) {
|
|
112
133
|
const {
|
|
@@ -115,25 +136,47 @@ export class FileFetcherImpl {
|
|
|
115
136
|
} = options;
|
|
116
137
|
if (!isValidId(id)) {
|
|
117
138
|
const subject = createMediaSubject();
|
|
118
|
-
|
|
139
|
+
const err = new FileFetcherError('invalidFileId', id, {
|
|
119
140
|
collectionName,
|
|
120
141
|
occurrenceKey
|
|
121
|
-
})
|
|
142
|
+
});
|
|
143
|
+
const errorFileState = {
|
|
144
|
+
status: 'error',
|
|
145
|
+
id,
|
|
146
|
+
reason: err === null || err === void 0 ? void 0 : err.reason,
|
|
147
|
+
message: err === null || err === void 0 ? void 0 : err.message,
|
|
148
|
+
occurrenceKey,
|
|
149
|
+
details: err === null || err === void 0 ? void 0 : err.attributes
|
|
150
|
+
};
|
|
151
|
+
subject.error(err);
|
|
152
|
+
this.setFileState(id, errorFileState);
|
|
122
153
|
return fromObservable(subject);
|
|
123
154
|
}
|
|
124
|
-
return fromObservable(getFileStreamsCache().getOrInsert(id, () =>
|
|
155
|
+
return fromObservable(getFileStreamsCache().getOrInsert(id, () => {
|
|
156
|
+
const subject = this.createDownloadFileStream(id, collectionName);
|
|
157
|
+
subject.subscribe({
|
|
158
|
+
next: fileState => {
|
|
159
|
+
this.setFileState(id, fileState);
|
|
160
|
+
},
|
|
161
|
+
error: err => {
|
|
162
|
+
const errorFileState = this.getErrorFileState(err, id, occurrenceKey);
|
|
163
|
+
this.setFileState(id, errorFileState);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
return subject;
|
|
167
|
+
}));
|
|
125
168
|
}
|
|
126
169
|
getCurrentState(id, options) {
|
|
127
170
|
return toPromise(this.getFileState(id, options));
|
|
128
171
|
}
|
|
129
172
|
getArtifactURL(artifacts, artifactName, collectionName) {
|
|
130
|
-
return this.
|
|
173
|
+
return this.mediaApi.getArtifactURL(artifacts, artifactName, collectionName);
|
|
131
174
|
}
|
|
132
175
|
getFileBinaryURL(id, collectionName) {
|
|
133
|
-
return this.
|
|
176
|
+
return this.mediaApi.getFileBinaryURL(id, collectionName);
|
|
134
177
|
}
|
|
135
178
|
touchFiles(descriptors, collection, traceContext) {
|
|
136
|
-
return this.
|
|
179
|
+
return this.mediaApi.touchFiles({
|
|
137
180
|
descriptors
|
|
138
181
|
}, {
|
|
139
182
|
collection
|
|
@@ -189,6 +232,7 @@ export class FileFetcherImpl {
|
|
|
189
232
|
subject.next(fileState);
|
|
190
233
|
// we save it into the cache as soon as possible, in case someone subscribes
|
|
191
234
|
getFileStreamsCache().set(id, subject);
|
|
235
|
+
this.setFileState(id, fileState);
|
|
192
236
|
return new Promise(async (resolve, reject) => {
|
|
193
237
|
const blob = await deferredBlob;
|
|
194
238
|
if (!blob) {
|
|
@@ -240,15 +284,19 @@ export class FileFetcherImpl {
|
|
|
240
284
|
const subject = createMediaSubject();
|
|
241
285
|
getFileStreamsCache().set(id, subject);
|
|
242
286
|
const onProgress = progress => {
|
|
243
|
-
|
|
287
|
+
const fileState = {
|
|
244
288
|
status: 'uploading',
|
|
245
289
|
...stateBase,
|
|
246
290
|
progress
|
|
247
|
-
}
|
|
291
|
+
};
|
|
292
|
+
subject.next(fileState);
|
|
293
|
+
this.setFileState(id, fileState);
|
|
248
294
|
};
|
|
249
295
|
let processingSubscription = new Subscription();
|
|
250
296
|
const onUploadFinish = error => {
|
|
251
297
|
if (error) {
|
|
298
|
+
const errorFileState = this.getErrorFileState(error, id, occurrenceKey);
|
|
299
|
+
this.setFileState(id, errorFileState);
|
|
252
300
|
return subject.error(error);
|
|
253
301
|
}
|
|
254
302
|
processingSubscription = this.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(remoteFileState => ({
|
|
@@ -256,11 +304,22 @@ export class FileFetcherImpl {
|
|
|
256
304
|
...stateBase,
|
|
257
305
|
...remoteFileState,
|
|
258
306
|
...overrideMediaTypeIfUnknown(remoteFileState, stateBase.mediaType)
|
|
259
|
-
}))).subscribe(
|
|
307
|
+
}))).subscribe({
|
|
308
|
+
next: fileState => {
|
|
309
|
+
subject.next(fileState);
|
|
310
|
+
this.setFileState(id, fileState);
|
|
311
|
+
},
|
|
312
|
+
error: err => {
|
|
313
|
+
const errorFileState = this.getErrorFileState(err, id, occurrenceKey);
|
|
314
|
+
subject.error(err);
|
|
315
|
+
this.setFileState(id, errorFileState);
|
|
316
|
+
},
|
|
317
|
+
complete: subject.complete
|
|
318
|
+
});
|
|
260
319
|
};
|
|
261
320
|
const {
|
|
262
321
|
cancel
|
|
263
|
-
} = uploadFile(file, this.
|
|
322
|
+
} = uploadFile(file, this.mediaApi, upfrontId, {
|
|
264
323
|
onUploadFinish,
|
|
265
324
|
onProgress
|
|
266
325
|
}, traceContext);
|
|
@@ -276,10 +335,8 @@ export class FileFetcherImpl {
|
|
|
276
335
|
setTimeout(onProgress, 0, 0);
|
|
277
336
|
return fromObservable(subject);
|
|
278
337
|
}
|
|
279
|
-
|
|
280
|
-
// TODO: ----- ADD TICKET
|
|
281
338
|
async downloadBinary(id, name = 'download', collectionName) {
|
|
282
|
-
const url = await this.
|
|
339
|
+
const url = await this.mediaApi.getFileBinaryURL(id, collectionName);
|
|
283
340
|
downloadUrl(url, {
|
|
284
341
|
name
|
|
285
342
|
});
|
|
@@ -305,7 +362,7 @@ export class FileFetcherImpl {
|
|
|
305
362
|
preview,
|
|
306
363
|
mimeType
|
|
307
364
|
} = options;
|
|
308
|
-
const mediaStore = destination.mediaStore || new
|
|
365
|
+
const mediaStore = destination.mediaStore || new MediaApi({
|
|
309
366
|
authProvider: destinationAuthProvider
|
|
310
367
|
});
|
|
311
368
|
const owner = authToOwner(await authProvider({
|
|
@@ -359,25 +416,37 @@ export class FileFetcherImpl {
|
|
|
359
416
|
// mimeType should always be returned by "copyFileWithToken"
|
|
360
417
|
// but in case it's not, we don't want to penalize "copyFile"
|
|
361
418
|
copiedMimeType && (await shouldFetchRemoteFileStates(mediaType, copiedMimeType, preview))) {
|
|
362
|
-
|
|
419
|
+
const fileState = {
|
|
363
420
|
...copiedFileState,
|
|
364
421
|
...overrideMediaTypeIfUnknown(copiedFileState, mediaType),
|
|
365
422
|
...previewOverride
|
|
366
|
-
}
|
|
423
|
+
};
|
|
424
|
+
subject.next(fileState);
|
|
425
|
+
this.setFileState(copiedId, fileState);
|
|
367
426
|
processingSubscription = this.createDownloadFileStream(copiedId, destinationCollectionName, occurrenceKey).subscribe({
|
|
368
|
-
next: remoteFileState =>
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
427
|
+
next: remoteFileState => {
|
|
428
|
+
const fileState = {
|
|
429
|
+
...remoteFileState,
|
|
430
|
+
...overrideMediaTypeIfUnknown(remoteFileState, mediaType),
|
|
431
|
+
...(!isErrorFileState(remoteFileState) && previewOverride)
|
|
432
|
+
};
|
|
433
|
+
this.setFileState(copiedId, fileState);
|
|
434
|
+
return subject.next(fileState);
|
|
435
|
+
},
|
|
436
|
+
error: err => {
|
|
437
|
+
const errorFileState = this.getErrorFileState(err, id, occurrenceKey);
|
|
438
|
+
this.setFileState(copiedId, errorFileState);
|
|
439
|
+
return subject.error(err);
|
|
440
|
+
},
|
|
374
441
|
complete: () => subject.complete()
|
|
375
442
|
});
|
|
376
443
|
} else if (!isProcessingFileState(copiedFileState)) {
|
|
377
|
-
|
|
444
|
+
const fileState = {
|
|
378
445
|
...copiedFileState,
|
|
379
446
|
...(!isErrorFileState(copiedFileState) && previewOverride)
|
|
380
|
-
}
|
|
447
|
+
};
|
|
448
|
+
subject.next(fileState);
|
|
449
|
+
this.setFileState(copiedId, fileState);
|
|
381
450
|
}
|
|
382
451
|
if (!cache.has(copiedId)) {
|
|
383
452
|
getFileStreamsCache().set(copiedId, subject);
|
|
@@ -389,12 +458,16 @@ export class FileFetcherImpl {
|
|
|
389
458
|
}
|
|
390
459
|
if (replaceFileId) {
|
|
391
460
|
const fileCache = cache.get(replaceFileId);
|
|
461
|
+
const replaceFileState = this.store.getState().files[replaceFileId];
|
|
392
462
|
if (fileCache) {
|
|
393
463
|
fileCache.error(error);
|
|
394
464
|
} else {
|
|
395
465
|
// Create a new subject with the error state for new subscriptions
|
|
396
466
|
cache.set(id, createMediaSubject(error));
|
|
397
467
|
}
|
|
468
|
+
const key = replaceFileState ? replaceFileId : id;
|
|
469
|
+
const errorFileState = this.getErrorFileState(error, id, occurrenceKey);
|
|
470
|
+
this.setFileState(key, errorFileState);
|
|
398
471
|
}
|
|
399
472
|
throw error;
|
|
400
473
|
}
|
|
@@ -1,24 +1,32 @@
|
|
|
1
1
|
import { EventEmitter2 } from 'eventemitter2';
|
|
2
|
-
import { MediaStore } from './media-store';
|
|
2
|
+
import { MediaStore as MediaApi } from './media-store';
|
|
3
3
|
import { FileFetcherImpl } from './file-fetcher';
|
|
4
4
|
import { StargateClient } from './stargate-client';
|
|
5
|
+
import { mediaStore } from '@atlaskit/media-state';
|
|
5
6
|
export class MediaClient {
|
|
6
7
|
// mobile upload is lazily loaded
|
|
7
8
|
|
|
8
9
|
// Deprecated value introduced for backward compatibility with Context
|
|
9
10
|
|
|
10
|
-
constructor(mediaClientConfig,
|
|
11
|
+
constructor(mediaClientConfig, store = mediaStore, mediaApi) {
|
|
11
12
|
this.mediaClientConfig = mediaClientConfig;
|
|
12
|
-
this.
|
|
13
|
-
this.mediaStore = new
|
|
13
|
+
this.store = store;
|
|
14
|
+
this.mediaStore = mediaApi !== null && mediaApi !== void 0 ? mediaApi : new MediaApi({
|
|
14
15
|
authProvider: mediaClientConfig.authProvider,
|
|
15
16
|
initialAuth: mediaClientConfig.initialAuth
|
|
16
|
-
}
|
|
17
|
+
});
|
|
17
18
|
this.config = mediaClientConfig;
|
|
18
|
-
this.file = new FileFetcherImpl(this.mediaStore);
|
|
19
|
+
this.file = new FileFetcherImpl(this.mediaStore, this.store);
|
|
19
20
|
this.eventEmitter = new EventEmitter2();
|
|
20
21
|
this.stargate = new StargateClient(mediaClientConfig.stargateBaseUrl);
|
|
21
22
|
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @internal
|
|
26
|
+
*/
|
|
27
|
+
__DO_NOT_USE__getMediaStore() {
|
|
28
|
+
return this.store;
|
|
29
|
+
}
|
|
22
30
|
getImage(id, params, controller, fetchMaxRes, traceContext) {
|
|
23
31
|
return this.mediaStore.getImage(id, params, controller, fetchMaxRes, traceContext);
|
|
24
32
|
}
|
|
@@ -36,7 +44,7 @@ export class MediaClient {
|
|
|
36
44
|
return this.mobileUpload;
|
|
37
45
|
}
|
|
38
46
|
const module = await import( /* webpackChunkName: "@atlaskit-internal_media-client-mobile-upload" */'./mobile-upload');
|
|
39
|
-
this.mobileUpload = new module.MobileUploadImpl(this.mediaStore);
|
|
47
|
+
this.mobileUpload = new module.MobileUploadImpl(this.mediaStore, this.store);
|
|
40
48
|
return this.mobileUpload;
|
|
41
49
|
}
|
|
42
50
|
async removeFileFromCollection(id, collectionName, occurrenceKey, traceContext) {
|
|
@@ -28,11 +28,10 @@ const jsonHeaders = {
|
|
|
28
28
|
'Content-Type': 'application/json'
|
|
29
29
|
};
|
|
30
30
|
export class MediaStore {
|
|
31
|
-
constructor(config
|
|
31
|
+
constructor(config) {
|
|
32
32
|
_defineProperty(this, "resolveAuth", authContext => resolveAuth(this.config.authProvider, authContext));
|
|
33
33
|
_defineProperty(this, "resolveInitialAuth", () => resolveInitialAuth(this.config.initialAuth));
|
|
34
34
|
this.config = config;
|
|
35
|
-
this.featureFlags = featureFlags;
|
|
36
35
|
}
|
|
37
36
|
async removeCollectionFile(id, collectionName, occurrenceKey, traceContext) {
|
|
38
37
|
const metadata = {
|
|
@@ -1,10 +1,32 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
1
2
|
import { getMediaTypeFromMimeType } from '@atlaskit/media-common';
|
|
3
|
+
import { mediaStore } from '@atlaskit/media-state';
|
|
2
4
|
import { getFileStreamsCache } from '../file-streams-cache';
|
|
3
5
|
import { createFileDataloader } from '../utils/createFileDataLoader';
|
|
4
6
|
import { createServicesCache, createMobileUploadStateMachine, createMobileUploadService, createMobileFileStateSubject } from '../utils/mobileUpload';
|
|
5
7
|
export class MobileUploadImpl {
|
|
6
|
-
constructor(mediaStore) {
|
|
7
|
-
this
|
|
8
|
+
constructor(mediaApi, store = mediaStore) {
|
|
9
|
+
_defineProperty(this, "getErrorFileState", (error, id, occurrenceKey) => typeof error === 'string' ? {
|
|
10
|
+
status: 'error',
|
|
11
|
+
id,
|
|
12
|
+
reason: error,
|
|
13
|
+
occurrenceKey,
|
|
14
|
+
message: error
|
|
15
|
+
} : {
|
|
16
|
+
status: 'error',
|
|
17
|
+
id,
|
|
18
|
+
reason: error === null || error === void 0 ? void 0 : error.reason,
|
|
19
|
+
details: error === null || error === void 0 ? void 0 : error.attributes,
|
|
20
|
+
occurrenceKey,
|
|
21
|
+
message: error === null || error === void 0 ? void 0 : error.message
|
|
22
|
+
});
|
|
23
|
+
_defineProperty(this, "setFileState", (id, fileState) => {
|
|
24
|
+
this.store.setState(state => {
|
|
25
|
+
state.files[id] = fileState;
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
this.store = store;
|
|
29
|
+
this.dataloader = createFileDataloader(mediaApi);
|
|
8
30
|
this.servicesCache = createServicesCache();
|
|
9
31
|
}
|
|
10
32
|
notifyUploadStart(event) {
|
|
@@ -33,6 +55,15 @@ export class MobileUploadImpl {
|
|
|
33
55
|
};
|
|
34
56
|
const service = createMobileUploadService(createMobileUploadStateMachine(this.dataloader, initialState, collectionName));
|
|
35
57
|
const subject = createMobileFileStateSubject(service);
|
|
58
|
+
subject.subscribe({
|
|
59
|
+
next: fileState => {
|
|
60
|
+
this.setFileState(fileId, fileState);
|
|
61
|
+
},
|
|
62
|
+
error: err => {
|
|
63
|
+
const errorFileState = this.getErrorFileState(err, fileId, occurrenceKey);
|
|
64
|
+
this.setFileState(fileId, errorFileState);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
36
67
|
this.servicesCache.set(fileId, service);
|
|
37
68
|
getFileStreamsCache().set(fileId, subject);
|
|
38
69
|
}
|
package/dist/es2019/index.js
CHANGED
|
@@ -24,6 +24,7 @@ export { globalMediaEventEmitter } from './globalMediaEventEmitter';
|
|
|
24
24
|
export { isMediaBlobUrl, getAttrsFromUrl, addFileAttrsToUrl, objectToQueryString } from './utils/url';
|
|
25
25
|
export { createMediaSubscribable, fromObservable } from './utils/mediaSubscribable';
|
|
26
26
|
export { RECENTS_COLLECTION, MAX_RESOLUTION } from './constants';
|
|
27
|
+
export { getFileStreamsCache } from './file-streams-cache';
|
|
27
28
|
|
|
28
29
|
// TODO MEX-659 Remove these exports when all the usages from media-client are replaced with media-common.
|
|
29
30
|
|
|
@@ -5,7 +5,8 @@ export class SimpleHasher {
|
|
|
5
5
|
const reader = new FileReader();
|
|
6
6
|
reader.readAsArrayBuffer(blob);
|
|
7
7
|
reader.onload = () => {
|
|
8
|
-
|
|
8
|
+
var _reader$result;
|
|
9
|
+
resolve(Rusha.createHash().update((_reader$result = reader.result) !== null && _reader$result !== void 0 ? _reader$result : '').digest('hex'));
|
|
9
10
|
};
|
|
10
11
|
reader.onerror = reject;
|
|
11
12
|
});
|
|
@@ -2,7 +2,7 @@ import { isClientBasedAuth } from '@atlaskit/media-core';
|
|
|
2
2
|
import { mapAuthToQueryParameters } from '../../models/auth-query-parameters';
|
|
3
3
|
import { RequestError, isRequestError } from './errors';
|
|
4
4
|
export function clientTimeoutPromise(timeout) {
|
|
5
|
-
return new Promise((
|
|
5
|
+
return new Promise((_, reject) => {
|
|
6
6
|
setTimeout(reject, timeout, new RequestError('clientTimeoutRequest'));
|
|
7
7
|
});
|
|
8
8
|
}
|
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { MediaClient } from '../client/media-client';
|
|
4
|
-
const NO_FLAGS = 'NO_FLAGS';
|
|
5
4
|
const mediaClientsMap = new Map();
|
|
6
|
-
export const getMediaClient =
|
|
7
|
-
|
|
8
|
-
const flagsMapKey = featureFlags || NO_FLAGS;
|
|
9
|
-
let mediaClient = (_mediaClientsMap$get = mediaClientsMap.get(mediaClientConfig)) === null || _mediaClientsMap$get === void 0 ? void 0 : _mediaClientsMap$get.get(flagsMapKey);
|
|
5
|
+
export const getMediaClient = mediaClientConfig => {
|
|
6
|
+
let mediaClient = mediaClientsMap.get(mediaClientConfig);
|
|
10
7
|
if (!mediaClient) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
subMap = new Map();
|
|
14
|
-
mediaClientsMap.set(mediaClientConfig, subMap);
|
|
15
|
-
}
|
|
16
|
-
mediaClient = new MediaClient(mediaClientConfig, featureFlags);
|
|
17
|
-
subMap.set(flagsMapKey, mediaClient);
|
|
8
|
+
mediaClient = new MediaClient(mediaClientConfig);
|
|
9
|
+
mediaClientsMap.set(mediaClientConfig, mediaClient);
|
|
18
10
|
}
|
|
19
11
|
return mediaClient;
|
|
20
12
|
};
|
|
21
|
-
const createEmptyMediaClient =
|
|
13
|
+
const createEmptyMediaClient = () => {
|
|
22
14
|
const emptyConfig = {
|
|
23
15
|
authProvider: () => Promise.resolve({
|
|
24
16
|
clientId: '',
|
|
@@ -26,9 +18,9 @@ const createEmptyMediaClient = featureFlags => {
|
|
|
26
18
|
baseUrl: ''
|
|
27
19
|
})
|
|
28
20
|
};
|
|
29
|
-
return new MediaClient(emptyConfig
|
|
21
|
+
return new MediaClient(emptyConfig);
|
|
30
22
|
};
|
|
31
|
-
export const withMediaClient =
|
|
23
|
+
export const withMediaClient = Component => {
|
|
32
24
|
return class extends React.Component {
|
|
33
25
|
render() {
|
|
34
26
|
// TODO MPT-315: clean up after we move mediaClientConfig into FileIdentifier
|
|
@@ -36,7 +28,7 @@ export const withMediaClient = (Component, featureFlags) => {
|
|
|
36
28
|
mediaClientConfig,
|
|
37
29
|
...otherProps
|
|
38
30
|
} = this.props;
|
|
39
|
-
const mediaClient = !mediaClientConfig ? createEmptyMediaClient(
|
|
31
|
+
const mediaClient = !mediaClientConfig ? createEmptyMediaClient() : getMediaClient(mediaClientConfig);
|
|
40
32
|
return /*#__PURE__*/React.createElement(Component, _extends({}, otherProps, {
|
|
41
33
|
mediaClient: mediaClient
|
|
42
34
|
}));
|