@atlaskit/media-client 20.0.0 → 20.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/client/collection-fetcher.js +4 -44
- package/dist/cjs/client/file-fetcher/error.js +3 -19
- package/dist/cjs/client/file-fetcher/index.js +152 -167
- package/dist/cjs/client/media-client.js +3 -27
- package/dist/cjs/client/media-store/error.js +1 -17
- package/dist/cjs/client/media-store/index.js +13 -103
- package/dist/cjs/client/media-store/resolveAuth.js +2 -23
- package/dist/cjs/client/mobile-upload.js +9 -22
- package/dist/cjs/client/stargate-client.js +0 -12
- package/dist/cjs/constants.js +0 -3
- package/dist/cjs/file-streams-cache.js +0 -11
- package/dist/cjs/globalMediaEventEmitter.js +0 -3
- package/dist/cjs/identifier.js +0 -8
- package/dist/cjs/index.js +0 -38
- package/dist/cjs/models/artifacts.js +0 -4
- package/dist/cjs/models/auth-headers.js +0 -2
- package/dist/cjs/models/auth-query-parameters.js +0 -2
- package/dist/cjs/models/errors/helpers.js +0 -2
- package/dist/cjs/models/errors/index.js +4 -20
- package/dist/cjs/models/file-state.js +10 -36
- package/dist/cjs/models/media.js +2 -8
- package/dist/cjs/upload-controller.js +0 -6
- package/dist/cjs/uploader/calculateChunkSize.js +1 -10
- package/dist/cjs/uploader/error.js +3 -19
- package/dist/cjs/uploader/index.js +3 -43
- package/dist/cjs/utils/checkWebpSupport.js +3 -7
- package/dist/cjs/utils/convertBase64ToBlob.js +0 -5
- package/dist/cjs/utils/createFileDataLoader.js +4 -28
- package/dist/cjs/utils/createMediaSubject.js +0 -4
- package/dist/cjs/utils/detectEmptyFile.js +8 -15
- package/dist/cjs/utils/getDimensionsFromBlob.js +0 -14
- package/dist/cjs/utils/getImageDimensionsFromBlob.js +0 -4
- package/dist/cjs/utils/getMediaTypeFromUploadableFile.js +0 -3
- package/dist/cjs/utils/getVideoDimensionsFromBlob.js +2 -8
- package/dist/cjs/utils/hashing/hasherCreator.js +0 -20
- package/dist/cjs/utils/hashing/simpleHasher.js +0 -12
- package/dist/cjs/utils/hashing/workerHasher.js +3 -24
- package/dist/cjs/utils/imageResizeModeToFileImageMode.js +0 -2
- package/dist/cjs/utils/isImageRemote.js +0 -5
- package/dist/cjs/utils/mediaSubscribable/fromObservable.js +2 -4
- package/dist/cjs/utils/mediaSubscribable/index.js +0 -2
- package/dist/cjs/utils/mediaSubscribable/toPromise.js +1 -3
- package/dist/cjs/utils/mobileUpload/error.js +3 -19
- package/dist/cjs/utils/mobileUpload/helpers.js +2 -26
- package/dist/cjs/utils/mobileUpload/index.js +0 -4
- package/dist/cjs/utils/mobileUpload/servicesCache.js +0 -2
- package/dist/cjs/utils/mobileUpload/stateMachine/index.js +0 -22
- package/dist/cjs/utils/mobileUpload/stateMachine/states/processing.js +0 -2
- package/dist/cjs/utils/mobileUpload/stateMachine/states/uploading.js +0 -7
- package/dist/cjs/utils/overrideMediaTypeIfUnknown.js +0 -4
- package/dist/cjs/utils/polling/errors.js +1 -17
- package/dist/cjs/utils/polling/index.js +1 -30
- package/dist/cjs/utils/request/errors.js +8 -24
- package/dist/cjs/utils/request/helpers.js +19 -103
- package/dist/cjs/utils/request/index.js +15 -26
- package/dist/cjs/utils/safeUnsubscribe.js +0 -2
- package/dist/cjs/utils/setTimeoutPromise.js +0 -4
- package/dist/cjs/utils/shouldFetchRemoteFileStates.js +0 -21
- package/dist/cjs/utils/url.js +4 -27
- package/dist/cjs/utils/with-media-client-hoc.js +12 -28
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/client/collection-fetcher.js +6 -18
- package/dist/es2019/client/file-fetcher/error.js +0 -2
- package/dist/es2019/client/file-fetcher/index.js +138 -70
- package/dist/es2019/client/media-client.js +4 -14
- package/dist/es2019/client/media-store/error.js +0 -2
- package/dist/es2019/client/media-store/index.js +37 -52
- package/dist/es2019/client/media-store/resolveAuth.js +1 -5
- package/dist/es2019/client/mobile-upload.js +0 -8
- package/dist/es2019/client/stargate-client.js +0 -3
- package/dist/es2019/constants.js +0 -1
- package/dist/es2019/file-streams-cache.js +0 -11
- package/dist/es2019/globalMediaEventEmitter.js +0 -4
- package/dist/es2019/index.js +4 -11
- package/dist/es2019/models/artifacts.js +0 -2
- package/dist/es2019/models/errors/index.js +5 -4
- package/dist/es2019/models/file-state.js +6 -7
- package/dist/es2019/models/media.js +2 -3
- package/dist/es2019/upload-controller.js +0 -3
- package/dist/es2019/uploader/calculateChunkSize.js +1 -4
- package/dist/es2019/uploader/error.js +0 -2
- package/dist/es2019/uploader/index.js +0 -13
- package/dist/es2019/utils/checkWebpSupport.js +3 -4
- package/dist/es2019/utils/convertBase64ToBlob.js +0 -2
- package/dist/es2019/utils/createFileDataLoader.js +6 -9
- package/dist/es2019/utils/createMediaSubject.js +0 -2
- package/dist/es2019/utils/detectEmptyFile.js +1 -5
- package/dist/es2019/utils/getDimensionsFromBlob.js +0 -3
- package/dist/es2019/utils/getImageDimensionsFromBlob.js +0 -2
- package/dist/es2019/utils/getVideoDimensionsFromBlob.js +2 -1
- package/dist/es2019/utils/hashing/hasherCreator.js +0 -2
- package/dist/es2019/utils/hashing/simpleHasher.js +0 -3
- package/dist/es2019/utils/hashing/workerHasher.js +1 -16
- package/dist/es2019/utils/isImageRemote.js +0 -2
- package/dist/es2019/utils/mediaSubscribable/fromObservable.js +2 -1
- package/dist/es2019/utils/mediaSubscribable/toPromise.js +1 -1
- package/dist/es2019/utils/mobileUpload/error.js +0 -2
- package/dist/es2019/utils/mobileUpload/helpers.js +2 -7
- package/dist/es2019/utils/mobileUpload/stateMachine/index.js +0 -2
- package/dist/es2019/utils/mobileUpload/stateMachine/states/uploading.js +2 -1
- package/dist/es2019/utils/overrideMediaTypeIfUnknown.js +0 -1
- package/dist/es2019/utils/polling/errors.js +0 -2
- package/dist/es2019/utils/polling/index.js +3 -20
- package/dist/es2019/utils/request/errors.js +0 -2
- package/dist/es2019/utils/request/helpers.js +24 -35
- package/dist/es2019/utils/request/index.js +2 -2
- package/dist/es2019/utils/shouldFetchRemoteFileStates.js +1 -5
- package/dist/es2019/utils/url.js +6 -14
- package/dist/es2019/utils/with-media-client-hoc.js +10 -7
- package/dist/es2019/version.json +1 -1
- package/dist/esm/client/collection-fetcher.js +4 -34
- package/dist/esm/client/file-fetcher/error.js +3 -12
- package/dist/esm/client/file-fetcher/index.js +154 -137
- package/dist/esm/client/media-client.js +4 -17
- package/dist/esm/client/media-store/error.js +1 -10
- package/dist/esm/client/media-store/index.js +13 -89
- package/dist/esm/client/media-store/resolveAuth.js +2 -13
- package/dist/esm/client/mobile-upload.js +9 -15
- package/dist/esm/client/stargate-client.js +0 -7
- package/dist/esm/constants.js +0 -1
- package/dist/esm/file-streams-cache.js +0 -6
- package/dist/esm/globalMediaEventEmitter.js +0 -1
- package/dist/esm/index.js +4 -11
- package/dist/esm/models/artifacts.js +0 -2
- package/dist/esm/models/errors/index.js +5 -12
- package/dist/esm/models/file-state.js +10 -17
- package/dist/esm/models/media.js +2 -3
- package/dist/esm/upload-controller.js +0 -2
- package/dist/esm/uploader/calculateChunkSize.js +1 -4
- package/dist/esm/uploader/error.js +3 -12
- package/dist/esm/uploader/index.js +3 -32
- package/dist/esm/utils/checkWebpSupport.js +3 -4
- package/dist/esm/utils/convertBase64ToBlob.js +0 -3
- package/dist/esm/utils/createFileDataLoader.js +4 -18
- package/dist/esm/utils/createMediaSubject.js +0 -2
- package/dist/esm/utils/detectEmptyFile.js +8 -12
- package/dist/esm/utils/getDimensionsFromBlob.js +0 -7
- package/dist/esm/utils/getImageDimensionsFromBlob.js +0 -2
- package/dist/esm/utils/getVideoDimensionsFromBlob.js +2 -3
- package/dist/esm/utils/hashing/hasherCreator.js +0 -9
- package/dist/esm/utils/hashing/simpleHasher.js +0 -4
- package/dist/esm/utils/hashing/workerHasher.js +3 -18
- package/dist/esm/utils/isImageRemote.js +0 -3
- package/dist/esm/utils/mediaSubscribable/fromObservable.js +2 -1
- package/dist/esm/utils/mediaSubscribable/toPromise.js +1 -1
- package/dist/esm/utils/mobileUpload/error.js +3 -12
- package/dist/esm/utils/mobileUpload/helpers.js +2 -11
- package/dist/esm/utils/mobileUpload/stateMachine/index.js +0 -6
- package/dist/esm/utils/mobileUpload/stateMachine/states/uploading.js +0 -3
- package/dist/esm/utils/overrideMediaTypeIfUnknown.js +0 -1
- package/dist/esm/utils/polling/errors.js +1 -10
- package/dist/esm/utils/polling/index.js +1 -27
- package/dist/esm/utils/request/errors.js +8 -17
- package/dist/esm/utils/request/helpers.js +22 -76
- package/dist/esm/utils/request/index.js +15 -20
- package/dist/esm/utils/shouldFetchRemoteFileStates.js +1 -15
- package/dist/esm/utils/url.js +4 -18
- package/dist/esm/utils/with-media-client-hoc.js +12 -17
- package/dist/esm/version.json +1 -1
- package/dist/types/client/file-fetcher/index.d.ts +6 -2
- package/package.json +8 -6
- package/report.api.md +4 -1
package/dist/cjs/utils/url.js
CHANGED
|
@@ -1,52 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.objectToQueryString = exports.isMediaBlobUrl = exports.getAttrsFromUrl = exports.addFileAttrsToUrl = void 0;
|
|
9
|
-
|
|
10
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
-
|
|
12
9
|
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; }
|
|
13
|
-
|
|
14
10
|
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; }
|
|
15
|
-
|
|
16
11
|
var mediaBlobUrlIdentifier = 'media-blob-url';
|
|
17
|
-
|
|
18
12
|
var isMediaBlobUrl = function isMediaBlobUrl(url) {
|
|
19
13
|
return url.indexOf("".concat(mediaBlobUrlIdentifier, "=true")) > -1;
|
|
20
14
|
};
|
|
21
|
-
|
|
22
15
|
exports.isMediaBlobUrl = isMediaBlobUrl;
|
|
23
|
-
|
|
24
16
|
var getNumberFromParams = function getNumberFromParams(params, name) {
|
|
25
17
|
var value = params.get(name);
|
|
26
18
|
return typeof value === 'string' && !isNaN(parseInt(value)) ? parseInt(value) : undefined;
|
|
27
19
|
};
|
|
28
|
-
|
|
29
20
|
var getStringFromParams = function getStringFromParams(params, name) {
|
|
30
21
|
var value = params.get(name);
|
|
31
|
-
|
|
32
22
|
if (!value) {
|
|
33
23
|
return;
|
|
34
24
|
}
|
|
35
|
-
|
|
36
25
|
return decodeURIComponent(value);
|
|
37
26
|
};
|
|
38
|
-
|
|
39
27
|
var getAttrsFromUrl = function getAttrsFromUrl(blobUrl) {
|
|
40
28
|
var url = new URL(blobUrl);
|
|
41
29
|
var hash = url.hash.replace('#', '');
|
|
42
30
|
var params = new URLSearchParams(hash);
|
|
43
31
|
var id = params.get('id');
|
|
44
|
-
var contextId = params.get('contextId');
|
|
45
|
-
|
|
32
|
+
var contextId = params.get('contextId');
|
|
33
|
+
// check if we have the required params
|
|
46
34
|
if (!id || !contextId) {
|
|
47
35
|
return;
|
|
48
36
|
}
|
|
49
|
-
|
|
50
37
|
return {
|
|
51
38
|
id: id,
|
|
52
39
|
contextId: contextId,
|
|
@@ -59,39 +46,29 @@ var getAttrsFromUrl = function getAttrsFromUrl(blobUrl) {
|
|
|
59
46
|
mimeType: getStringFromParams(params, 'mimeType')
|
|
60
47
|
};
|
|
61
48
|
};
|
|
62
|
-
|
|
63
49
|
exports.getAttrsFromUrl = getAttrsFromUrl;
|
|
64
|
-
|
|
65
50
|
var objectToQueryString = function objectToQueryString(json) {
|
|
66
51
|
return Object.keys(json).filter(function (attrName) {
|
|
67
52
|
return typeof json[attrName] !== 'undefined' && json[attrName] !== null;
|
|
68
53
|
}).map(function (key) {
|
|
69
54
|
var value = json[key];
|
|
70
|
-
|
|
71
55
|
if (typeof value === 'undefined' || value === null) {
|
|
72
56
|
return;
|
|
73
57
|
}
|
|
74
|
-
|
|
75
58
|
return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value.toString()));
|
|
76
59
|
}).join('&');
|
|
77
60
|
};
|
|
78
|
-
|
|
79
61
|
exports.objectToQueryString = objectToQueryString;
|
|
80
|
-
|
|
81
62
|
var addFileAttrsToUrl = function addFileAttrsToUrl(url, fileAttrs) {
|
|
82
63
|
var isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
83
|
-
|
|
84
64
|
if (isSafari) {
|
|
85
65
|
return url;
|
|
86
66
|
}
|
|
87
|
-
|
|
88
67
|
var mediaIdentifierAttr = (0, _defineProperty2.default)({}, mediaBlobUrlIdentifier, 'true');
|
|
89
|
-
|
|
90
68
|
var mergedAttrs = _objectSpread(_objectSpread({}, mediaIdentifierAttr), fileAttrs);
|
|
69
|
+
var queryAttrs = objectToQueryString(mergedAttrs);
|
|
91
70
|
|
|
92
|
-
|
|
93
|
-
|
|
71
|
+
// we can't use '?' separator for blob url params
|
|
94
72
|
return "".concat(url, "#").concat(queryAttrs);
|
|
95
73
|
};
|
|
96
|
-
|
|
97
74
|
exports.addFileAttrsToUrl = addFileAttrsToUrl;
|
|
@@ -1,51 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.withMediaClient = exports.getMediaClient = void 0;
|
|
9
|
-
|
|
10
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
-
|
|
12
9
|
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
13
|
-
|
|
14
10
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
15
|
-
|
|
16
11
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
17
|
-
|
|
18
12
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
19
|
-
|
|
20
13
|
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
21
|
-
|
|
22
14
|
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
23
|
-
|
|
24
15
|
var _react = _interopRequireDefault(require("react"));
|
|
25
|
-
|
|
26
16
|
var _mediaClient = require("../client/media-client");
|
|
27
|
-
|
|
28
17
|
var _excluded = ["mediaClientConfig"];
|
|
29
|
-
|
|
30
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); }; }
|
|
31
|
-
|
|
32
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; } }
|
|
33
|
-
|
|
20
|
+
var NO_FLAGS = 'NO_FLAGS';
|
|
34
21
|
var mediaClientsMap = new Map();
|
|
35
|
-
|
|
36
22
|
var getMediaClient = function getMediaClient(mediaClientConfig, featureFlags) {
|
|
37
|
-
var
|
|
38
|
-
|
|
23
|
+
var _mediaClientsMap$get;
|
|
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);
|
|
39
26
|
if (!mediaClient) {
|
|
27
|
+
var subMap = mediaClientsMap.get(mediaClientConfig);
|
|
28
|
+
if (!subMap) {
|
|
29
|
+
subMap = new Map();
|
|
30
|
+
mediaClientsMap.set(mediaClientConfig, subMap);
|
|
31
|
+
}
|
|
40
32
|
mediaClient = new _mediaClient.MediaClient(mediaClientConfig, featureFlags);
|
|
41
|
-
|
|
33
|
+
subMap.set(flagsMapKey, mediaClient);
|
|
42
34
|
}
|
|
43
|
-
|
|
44
35
|
return mediaClient;
|
|
45
36
|
};
|
|
46
|
-
|
|
47
37
|
exports.getMediaClient = getMediaClient;
|
|
48
|
-
|
|
49
38
|
var createEmptyMediaClient = function createEmptyMediaClient(featureFlags) {
|
|
50
39
|
var emptyConfig = {
|
|
51
40
|
authProvider: function authProvider() {
|
|
@@ -58,25 +47,21 @@ var createEmptyMediaClient = function createEmptyMediaClient(featureFlags) {
|
|
|
58
47
|
};
|
|
59
48
|
return new _mediaClient.MediaClient(emptyConfig, featureFlags);
|
|
60
49
|
};
|
|
61
|
-
|
|
62
50
|
var withMediaClient = function withMediaClient(Component, featureFlags) {
|
|
63
51
|
return /*#__PURE__*/function (_React$Component) {
|
|
64
52
|
(0, _inherits2.default)(_class, _React$Component);
|
|
65
|
-
|
|
66
53
|
var _super = _createSuper(_class);
|
|
67
|
-
|
|
68
54
|
function _class() {
|
|
69
55
|
(0, _classCallCheck2.default)(this, _class);
|
|
70
56
|
return _super.apply(this, arguments);
|
|
71
57
|
}
|
|
72
|
-
|
|
73
58
|
(0, _createClass2.default)(_class, [{
|
|
74
59
|
key: "render",
|
|
75
60
|
value: function render() {
|
|
76
61
|
// TODO MPT-315: clean up after we move mediaClientConfig into FileIdentifier
|
|
77
62
|
var _this$props = this.props,
|
|
78
|
-
|
|
79
|
-
|
|
63
|
+
mediaClientConfig = _this$props.mediaClientConfig,
|
|
64
|
+
otherProps = (0, _objectWithoutProperties2.default)(_this$props, _excluded);
|
|
80
65
|
var mediaClient = !mediaClientConfig ? createEmptyMediaClient(featureFlags) : getMediaClient(mediaClientConfig, featureFlags);
|
|
81
66
|
return /*#__PURE__*/_react.default.createElement(Component, (0, _extends2.default)({}, otherProps, {
|
|
82
67
|
mediaClient: mediaClient
|
|
@@ -86,5 +71,4 @@ var withMediaClient = function withMediaClient(Component, featureFlags) {
|
|
|
86
71
|
return _class;
|
|
87
72
|
}(_react.default.Component);
|
|
88
73
|
};
|
|
89
|
-
|
|
90
74
|
exports.withMediaClient = withMediaClient;
|
package/dist/cjs/version.json
CHANGED
|
@@ -3,18 +3,15 @@ import { getFileStreamsCache } from '../file-streams-cache';
|
|
|
3
3
|
import { mapMediaFileToFileState } from '../models/file-state';
|
|
4
4
|
import { fromObservable } from '../utils/mediaSubscribable';
|
|
5
5
|
export const collectionCache = {};
|
|
6
|
-
|
|
7
6
|
const createCacheEntry = () => ({
|
|
8
7
|
items: [],
|
|
9
8
|
subject: new ReplaySubject(1),
|
|
10
9
|
isLoadingNextPage: false
|
|
11
10
|
});
|
|
12
|
-
|
|
13
11
|
export class CollectionFetcher {
|
|
14
12
|
constructor(mediaStore) {
|
|
15
13
|
this.mediaStore = mediaStore;
|
|
16
14
|
}
|
|
17
|
-
|
|
18
15
|
createFileStateObserver(id, details) {
|
|
19
16
|
const subject = new ReplaySubject(1);
|
|
20
17
|
const mediaFile = {
|
|
@@ -27,71 +24,63 @@ export class CollectionFetcher {
|
|
|
27
24
|
subject.next(fileState);
|
|
28
25
|
return subject;
|
|
29
26
|
}
|
|
30
|
-
|
|
31
27
|
populateCache(items) {
|
|
32
28
|
items.forEach(item => {
|
|
33
29
|
const fileStream = this.createFileStateObserver(item.id, item.details);
|
|
34
30
|
getFileStreamsCache().set(item.id, fileStream);
|
|
35
31
|
});
|
|
36
32
|
}
|
|
37
|
-
|
|
38
33
|
removeFromCache(id, collectionName) {
|
|
39
34
|
const collectionCacheIndex = collectionCache[collectionName].items.findIndex(item => item.id === id);
|
|
40
|
-
|
|
41
35
|
if (collectionCacheIndex === -1) {
|
|
42
36
|
return;
|
|
43
37
|
}
|
|
44
|
-
|
|
45
38
|
getFileStreamsCache().remove(id);
|
|
46
39
|
collectionCache[collectionName].items.splice(collectionCacheIndex, 1);
|
|
47
40
|
}
|
|
48
|
-
|
|
49
41
|
getItems(collectionName, params, traceContext) {
|
|
50
42
|
if (!collectionCache[collectionName]) {
|
|
51
43
|
collectionCache[collectionName] = createCacheEntry();
|
|
52
44
|
}
|
|
53
|
-
|
|
54
45
|
const collection = collectionCache[collectionName];
|
|
55
46
|
const subject = collection.subject;
|
|
56
|
-
this.mediaStore.getCollectionItems(collectionName, {
|
|
47
|
+
this.mediaStore.getCollectionItems(collectionName, {
|
|
48
|
+
...params,
|
|
57
49
|
details: 'full'
|
|
58
50
|
}, traceContext).then(items => {
|
|
59
51
|
const {
|
|
60
52
|
contents,
|
|
61
53
|
nextInclusiveStartKey
|
|
62
54
|
} = items.data;
|
|
63
|
-
this.populateCache(contents);
|
|
55
|
+
this.populateCache(contents);
|
|
56
|
+
// It's hard to merge two together, so we just take what's came from the server.
|
|
64
57
|
// Since we load only one page > 2 pages will be ditched from the cache.
|
|
65
|
-
|
|
66
58
|
collection.items = items.data.contents;
|
|
67
59
|
collection.nextInclusiveStartKey = nextInclusiveStartKey;
|
|
68
60
|
subject.next(collection.items);
|
|
69
61
|
}).catch(error => subject.error(error));
|
|
70
62
|
return fromObservable(subject);
|
|
71
63
|
}
|
|
72
|
-
|
|
73
64
|
async removeFile(id, collectionName, occurrenceKey, traceContext) {
|
|
74
65
|
await this.mediaStore.removeCollectionFile(id, collectionName, occurrenceKey, traceContext);
|
|
75
66
|
this.removeFromCache(id, collectionName);
|
|
76
67
|
const collection = collectionCache[collectionName];
|
|
77
68
|
collection.subject.next(collection.items);
|
|
78
69
|
}
|
|
79
|
-
|
|
80
70
|
async loadNextPage(collectionName, params, traceContext) {
|
|
81
71
|
const collection = collectionCache[collectionName];
|
|
82
72
|
const isLoading = collection ? collection.isLoadingNextPage : false;
|
|
83
|
-
|
|
84
73
|
if (!collection || !collection.nextInclusiveStartKey || isLoading) {
|
|
85
74
|
return;
|
|
86
75
|
}
|
|
87
|
-
|
|
88
76
|
collection.isLoadingNextPage = true;
|
|
89
77
|
const {
|
|
90
78
|
nextInclusiveStartKey: inclusiveStartKey,
|
|
91
79
|
items: currentItems,
|
|
92
80
|
subject
|
|
93
81
|
} = collectionCache[collectionName];
|
|
94
|
-
const response = await this.mediaStore.getCollectionItems(collectionName, {
|
|
82
|
+
const response = await this.mediaStore.getCollectionItems(collectionName, {
|
|
83
|
+
...params,
|
|
95
84
|
inclusiveStartKey,
|
|
96
85
|
details: 'full'
|
|
97
86
|
}, traceContext);
|
|
@@ -110,5 +99,4 @@ export class CollectionFetcher {
|
|
|
110
99
|
isLoadingNextPage: false
|
|
111
100
|
};
|
|
112
101
|
}
|
|
113
|
-
|
|
114
102
|
}
|
|
@@ -6,7 +6,6 @@ export class FileFetcherError extends BaseMediaClientError {
|
|
|
6
6
|
this.id = id;
|
|
7
7
|
this.metadata = metadata;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
9
|
get attributes() {
|
|
11
10
|
const {
|
|
12
11
|
reason,
|
|
@@ -23,7 +22,6 @@ export class FileFetcherError extends BaseMediaClientError {
|
|
|
23
22
|
occurrenceKey
|
|
24
23
|
};
|
|
25
24
|
}
|
|
26
|
-
|
|
27
25
|
}
|
|
28
26
|
export function isFileFetcherError(err) {
|
|
29
27
|
return err instanceof FileFetcherError;
|