@atlaskit/media-client 26.1.1 → 26.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/dist/cjs/client/media-client.js +3 -1
- package/dist/cjs/client/media-store/MediaStore.js +19 -8
- package/dist/cjs/index.js +8 -1
- package/dist/cjs/uploader/index.js +10 -8
- package/dist/cjs/utils/hashing/hasherCreator.js +41 -20
- package/dist/cjs/utils/hashing/sha256SimpleHasher.js +30 -0
- package/dist/es2019/client/media-client.js +3 -1
- package/dist/es2019/client/media-store/MediaStore.js +15 -8
- package/dist/es2019/index.js +2 -1
- package/dist/es2019/uploader/index.js +3 -3
- package/dist/es2019/utils/hashing/hasherCreator.js +13 -2
- package/dist/es2019/utils/hashing/sha256SimpleHasher.js +14 -0
- package/dist/esm/client/media-client.js +3 -1
- package/dist/esm/client/media-store/MediaStore.js +19 -8
- package/dist/esm/index.js +2 -1
- package/dist/esm/uploader/index.js +10 -8
- package/dist/esm/utils/hashing/hasherCreator.js +39 -20
- package/dist/esm/utils/hashing/sha256SimpleHasher.js +23 -0
- package/dist/types/client/media-store/MediaStore.d.ts +3 -0
- package/dist/types/client/media-store/types.d.ts +3 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/utils/hashing/hasherCreator.d.ts +2 -1
- package/dist/types/utils/hashing/sha256SimpleHasher.d.ts +4 -0
- package/dist/types-ts4.5/client/media-store/MediaStore.d.ts +3 -0
- package/dist/types-ts4.5/client/media-store/types.d.ts +3 -1
- package/dist/types-ts4.5/index.d.ts +1 -0
- package/dist/types-ts4.5/utils/hashing/hasherCreator.d.ts +2 -1
- package/dist/types-ts4.5/utils/hashing/sha256SimpleHasher.d.ts +4 -0
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @atlaskit/media-client
|
|
2
2
|
|
|
3
|
+
## 26.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#70414](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/70414) [`2125e318f970`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/2125e318f970) - Adding the option to use SHA256 for file uploads to ensure Media is FedRAMP compliant. If not specified the system will default to SHA1 to preserve backwards compatibiilty.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
13
|
+
## 26.1.2
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- [#71336](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/71336) [`9abd05a91e25`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9abd05a91e25) - Fixed image load performance issue where setting max age in getFileImageURL params to undefined would override the default
|
|
18
|
+
|
|
3
19
|
## 26.1.1
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
|
@@ -11,6 +11,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
|
11
11
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
12
12
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
13
|
var _eventemitter = require("eventemitter2");
|
|
14
|
+
var _mediaCore = require("@atlaskit/media-core");
|
|
14
15
|
var _mediaStore = require("./media-store");
|
|
15
16
|
var _fileFetcher = require("./file-fetcher");
|
|
16
17
|
var _stargateClient = require("./stargate-client");
|
|
@@ -30,7 +31,8 @@ var MediaClient = exports.MediaClient = /*#__PURE__*/function () {
|
|
|
30
31
|
this.store = store;
|
|
31
32
|
this.mediaStore = mediaApi !== null && mediaApi !== void 0 ? mediaApi : new _mediaStore.MediaStore({
|
|
32
33
|
authProvider: mediaClientConfig.authProvider,
|
|
33
|
-
initialAuth: mediaClientConfig.initialAuth
|
|
34
|
+
initialAuth: mediaClientConfig.initialAuth,
|
|
35
|
+
chunkHashAlgorithm: mediaClientConfig.useSha256ForUploads ? _mediaCore.ChunkHashAlgorithm.Sha256 : _mediaCore.ChunkHashAlgorithm.Sha1
|
|
34
36
|
});
|
|
35
37
|
this.config = mediaClientConfig;
|
|
36
38
|
this.file = new _fileFetcher.FileFetcherImpl(this.mediaStore, this.store);
|
|
@@ -16,18 +16,19 @@ var _artifacts = require("../../models/artifacts");
|
|
|
16
16
|
var _request3 = require("../../utils/request");
|
|
17
17
|
var _helpers = require("../../utils/request/helpers");
|
|
18
18
|
var _resolveAuth = require("./resolveAuth");
|
|
19
|
+
var _mediaCore = require("@atlaskit/media-core");
|
|
19
20
|
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; }
|
|
20
21
|
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; }
|
|
21
22
|
var MEDIA_API_REGION = 'media-api-region';
|
|
22
23
|
var MEDIA_API_ENVIRONMENT = 'media-api-environment';
|
|
23
|
-
var defaultImageOptions = {
|
|
24
|
-
'max-age': _constants.FILE_CACHE_MAX_AGE,
|
|
25
|
-
allowAnimated: true,
|
|
26
|
-
mode: 'crop'
|
|
27
|
-
};
|
|
28
24
|
var extendImageParams = function extendImageParams(params) {
|
|
25
|
+
var _params$maxAge, _params$allowAnimated, _params$mode;
|
|
29
26
|
var fetchMaxRes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
30
|
-
return _objectSpread(_objectSpread(
|
|
27
|
+
return _objectSpread(_objectSpread({}, params), {}, {
|
|
28
|
+
'max-age': (_params$maxAge = params === null || params === void 0 ? void 0 : params['max-age']) !== null && _params$maxAge !== void 0 ? _params$maxAge : _constants.FILE_CACHE_MAX_AGE,
|
|
29
|
+
allowAnimated: (_params$allowAnimated = params === null || params === void 0 ? void 0 : params.allowAnimated) !== null && _params$allowAnimated !== void 0 ? _params$allowAnimated : true,
|
|
30
|
+
mode: (_params$mode = params === null || params === void 0 ? void 0 : params.mode) !== null && _params$mode !== void 0 ? _params$mode : 'crop'
|
|
31
|
+
}, fetchMaxRes ? {
|
|
31
32
|
width: _constants.MAX_RESOLUTION,
|
|
32
33
|
height: _constants.MAX_RESOLUTION
|
|
33
34
|
} : {});
|
|
@@ -47,6 +48,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
|
|
|
47
48
|
return (0, _resolveAuth.resolveInitialAuth)(_this.config.initialAuth);
|
|
48
49
|
});
|
|
49
50
|
this.config = config;
|
|
51
|
+
this._chunkHashAlgorithm = config.chunkHashAlgorithm || _mediaCore.ChunkHashAlgorithm.Sha1;
|
|
50
52
|
}
|
|
51
53
|
(0, _createClass2.default)(MediaStore, [{
|
|
52
54
|
key: "removeCollectionFile",
|
|
@@ -109,7 +111,8 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
|
|
|
109
111
|
collectionName: collectionName
|
|
110
112
|
},
|
|
111
113
|
params: {
|
|
112
|
-
createUpTo: createUpTo
|
|
114
|
+
createUpTo: createUpTo,
|
|
115
|
+
hashAlgorithm: this._chunkHashAlgorithm
|
|
113
116
|
},
|
|
114
117
|
headers: {
|
|
115
118
|
Accept: 'application/json'
|
|
@@ -212,7 +215,10 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
|
|
|
212
215
|
},
|
|
213
216
|
headers: jsonHeaders,
|
|
214
217
|
body: JSON.stringify(body),
|
|
215
|
-
traceContext: traceContext
|
|
218
|
+
traceContext: traceContext,
|
|
219
|
+
params: {
|
|
220
|
+
hashAlgorithm: this._chunkHashAlgorithm
|
|
221
|
+
}
|
|
216
222
|
});
|
|
217
223
|
return _context3.abrupt("return", this.request('/upload/createWithFiles', options).then((0, _helpers.createMapResponseToJson)(metadata)));
|
|
218
224
|
case 5:
|
|
@@ -586,6 +592,11 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
|
|
|
586
592
|
}
|
|
587
593
|
return request;
|
|
588
594
|
}()
|
|
595
|
+
}, {
|
|
596
|
+
key: "chunkHashAlgorithm",
|
|
597
|
+
get: function get() {
|
|
598
|
+
return this._chunkHashAlgorithm;
|
|
599
|
+
}
|
|
589
600
|
}]);
|
|
590
601
|
return MediaStore;
|
|
591
602
|
}();
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,6 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
Object.defineProperty(exports, "ChunkHashAlgorithm", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _mediaCore.ChunkHashAlgorithm;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
6
12
|
Object.defineProperty(exports, "FileFetcherError", {
|
|
7
13
|
enumerable: true,
|
|
8
14
|
get: function get() {
|
|
@@ -338,4 +344,5 @@ var _globalMediaEventEmitter = require("./globalMediaEventEmitter");
|
|
|
338
344
|
var _url = require("./utils/url");
|
|
339
345
|
var _mediaSubscribable = require("./utils/mediaSubscribable");
|
|
340
346
|
var _constants = require("./constants");
|
|
341
|
-
var _fileStreamsCache = require("./file-streams-cache");
|
|
347
|
+
var _fileStreamsCache = require("./file-streams-cache");
|
|
348
|
+
var _mediaCore = require("@atlaskit/media-core");
|
|
@@ -16,14 +16,14 @@ var _constants = require("../constants");
|
|
|
16
16
|
var _calculateChunkSize = require("./calculateChunkSize");
|
|
17
17
|
// TODO: Allow to pass multiple files
|
|
18
18
|
|
|
19
|
-
var
|
|
20
|
-
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(blob) {
|
|
19
|
+
var _hashingFunction = /*#__PURE__*/function () {
|
|
20
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(blob, hashAlgorithm) {
|
|
21
21
|
var hasher;
|
|
22
22
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
23
23
|
while (1) switch (_context.prev = _context.next) {
|
|
24
24
|
case 0:
|
|
25
25
|
_context.next = 2;
|
|
26
|
-
return (0, _hasherCreator.createHasher)();
|
|
26
|
+
return (0, _hasherCreator.createHasher)(hashAlgorithm);
|
|
27
27
|
case 2:
|
|
28
28
|
hasher = _context.sent;
|
|
29
29
|
return _context.abrupt("return", hasher.hash(blob));
|
|
@@ -33,7 +33,7 @@ var hashingFunction = /*#__PURE__*/function () {
|
|
|
33
33
|
}
|
|
34
34
|
}, _callee);
|
|
35
35
|
}));
|
|
36
|
-
return function hashingFunction(_x) {
|
|
36
|
+
return function hashingFunction(_x, _x2) {
|
|
37
37
|
return _ref.apply(this, arguments);
|
|
38
38
|
};
|
|
39
39
|
}();
|
|
@@ -63,7 +63,7 @@ var createUploadingFunction = function createUploadingFunction(store, deferredUp
|
|
|
63
63
|
}
|
|
64
64
|
}, _callee2);
|
|
65
65
|
}));
|
|
66
|
-
return function (
|
|
66
|
+
return function (_x3) {
|
|
67
67
|
return _ref2.apply(this, arguments);
|
|
68
68
|
};
|
|
69
69
|
}();
|
|
@@ -96,7 +96,7 @@ var createProcessingFunction = function createProcessingFunction(store, deferred
|
|
|
96
96
|
}
|
|
97
97
|
}, _callee3);
|
|
98
98
|
}));
|
|
99
|
-
return function (
|
|
99
|
+
return function (_x4) {
|
|
100
100
|
return _ref3.apply(this, arguments);
|
|
101
101
|
};
|
|
102
102
|
}();
|
|
@@ -132,7 +132,7 @@ var createFileFromUpload = /*#__PURE__*/function () {
|
|
|
132
132
|
}
|
|
133
133
|
}, _callee4);
|
|
134
134
|
}));
|
|
135
|
-
return function createFileFromUpload(
|
|
135
|
+
return function createFileFromUpload(_x5, _x6, _x7, _x8, _x9) {
|
|
136
136
|
return _ref4.apply(this, arguments);
|
|
137
137
|
};
|
|
138
138
|
}();
|
|
@@ -161,7 +161,9 @@ var uploadFile = exports.uploadFile = function uploadFile(file, store, uploadabl
|
|
|
161
161
|
};
|
|
162
162
|
}
|
|
163
163
|
var chunkinatorObservable = (0, _chunkinator.chunkinator)(content, {
|
|
164
|
-
hashingFunction: hashingFunction
|
|
164
|
+
hashingFunction: function hashingFunction(blob) {
|
|
165
|
+
return _hashingFunction(blob, store.chunkHashAlgorithm);
|
|
166
|
+
},
|
|
165
167
|
hashingConcurrency: 5,
|
|
166
168
|
chunkSize: chunkSize,
|
|
167
169
|
uploadingConcurrency: 3,
|
|
@@ -8,54 +8,75 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.destroyHasher = exports.createHasher = void 0;
|
|
9
9
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
10
10
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
+
var _mediaCore = require("@atlaskit/media-core");
|
|
11
12
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
12
13
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
14
|
var hasher = null;
|
|
15
|
+
var sha256Hasher = null;
|
|
14
16
|
var destroyHasher = exports.destroyHasher = function destroyHasher() {
|
|
15
17
|
return hasher = null;
|
|
16
18
|
};
|
|
17
19
|
var createHasher = exports.createHasher = /*#__PURE__*/function () {
|
|
18
|
-
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
19
|
-
var numWorkers, _yield$import,
|
|
20
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(algorithm) {
|
|
21
|
+
var numWorkers, _yield$import, SimpleHasher, _yield$import2, WorkerHasher, _yield$import3, _SimpleHasher;
|
|
20
22
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
21
23
|
while (1) switch (_context.prev = _context.next) {
|
|
22
24
|
case 0:
|
|
23
25
|
numWorkers = 3;
|
|
24
|
-
if (
|
|
25
|
-
_context.next =
|
|
26
|
+
if (!(algorithm === _mediaCore.ChunkHashAlgorithm.Sha256)) {
|
|
27
|
+
_context.next = 11;
|
|
28
|
+
break;
|
|
29
|
+
}
|
|
30
|
+
if (sha256Hasher) {
|
|
31
|
+
_context.next = 8;
|
|
26
32
|
break;
|
|
27
33
|
}
|
|
28
|
-
_context.prev = 2;
|
|
29
34
|
_context.next = 5;
|
|
30
35
|
return Promise.resolve().then(function () {
|
|
31
|
-
return _interopRequireWildcard(require('./
|
|
36
|
+
return _interopRequireWildcard(require('./sha256SimpleHasher'));
|
|
32
37
|
});
|
|
33
38
|
case 5:
|
|
34
39
|
_yield$import = _context.sent;
|
|
35
|
-
|
|
40
|
+
SimpleHasher = _yield$import.SimpleHasher;
|
|
41
|
+
sha256Hasher = new SimpleHasher();
|
|
42
|
+
case 8:
|
|
43
|
+
return _context.abrupt("return", sha256Hasher);
|
|
44
|
+
case 11:
|
|
45
|
+
if (hasher) {
|
|
46
|
+
_context.next = 27;
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
_context.prev = 12;
|
|
50
|
+
_context.next = 15;
|
|
51
|
+
return Promise.resolve().then(function () {
|
|
52
|
+
return _interopRequireWildcard(require('./workerHasher'));
|
|
53
|
+
});
|
|
54
|
+
case 15:
|
|
55
|
+
_yield$import2 = _context.sent;
|
|
56
|
+
WorkerHasher = _yield$import2.WorkerHasher;
|
|
36
57
|
hasher = new WorkerHasher(numWorkers);
|
|
37
|
-
_context.next =
|
|
58
|
+
_context.next = 27;
|
|
38
59
|
break;
|
|
39
|
-
case
|
|
40
|
-
_context.prev =
|
|
41
|
-
_context.t0 = _context["catch"](
|
|
42
|
-
_context.next =
|
|
60
|
+
case 20:
|
|
61
|
+
_context.prev = 20;
|
|
62
|
+
_context.t0 = _context["catch"](12);
|
|
63
|
+
_context.next = 24;
|
|
43
64
|
return Promise.resolve().then(function () {
|
|
44
65
|
return _interopRequireWildcard(require('./simpleHasher'));
|
|
45
66
|
});
|
|
46
|
-
case
|
|
47
|
-
_yield$
|
|
48
|
-
|
|
49
|
-
hasher = new
|
|
50
|
-
case
|
|
67
|
+
case 24:
|
|
68
|
+
_yield$import3 = _context.sent;
|
|
69
|
+
_SimpleHasher = _yield$import3.SimpleHasher;
|
|
70
|
+
hasher = new _SimpleHasher();
|
|
71
|
+
case 27:
|
|
51
72
|
return _context.abrupt("return", hasher);
|
|
52
|
-
case
|
|
73
|
+
case 28:
|
|
53
74
|
case "end":
|
|
54
75
|
return _context.stop();
|
|
55
76
|
}
|
|
56
|
-
}, _callee, null, [[
|
|
77
|
+
}, _callee, null, [[12, 20]]);
|
|
57
78
|
}));
|
|
58
|
-
return function createHasher() {
|
|
79
|
+
return function createHasher(_x) {
|
|
59
80
|
return _ref.apply(this, arguments);
|
|
60
81
|
};
|
|
61
82
|
}();
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.SimpleHasher = void 0;
|
|
8
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
|
+
var _jsSha = require("js-sha256");
|
|
11
|
+
var SimpleHasher = exports.SimpleHasher = /*#__PURE__*/function () {
|
|
12
|
+
function SimpleHasher() {
|
|
13
|
+
(0, _classCallCheck2.default)(this, SimpleHasher);
|
|
14
|
+
}
|
|
15
|
+
(0, _createClass2.default)(SimpleHasher, [{
|
|
16
|
+
key: "hash",
|
|
17
|
+
value: function hash(blob) {
|
|
18
|
+
return new Promise(function (resolve, reject) {
|
|
19
|
+
var reader = new FileReader();
|
|
20
|
+
reader.readAsArrayBuffer(blob);
|
|
21
|
+
reader.onload = function () {
|
|
22
|
+
var _reader$result;
|
|
23
|
+
resolve("sha256-".concat(_jsSha.sha256.create().update((_reader$result = reader.result) !== null && _reader$result !== void 0 ? _reader$result : '').hex()));
|
|
24
|
+
};
|
|
25
|
+
reader.onerror = reject;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}]);
|
|
29
|
+
return SimpleHasher;
|
|
30
|
+
}();
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventEmitter2 } from 'eventemitter2';
|
|
2
|
+
import { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
2
3
|
import { MediaStore as MediaApi } from './media-store';
|
|
3
4
|
import { FileFetcherImpl } from './file-fetcher';
|
|
4
5
|
import { StargateClient } from './stargate-client';
|
|
@@ -13,7 +14,8 @@ export class MediaClient {
|
|
|
13
14
|
this.store = store;
|
|
14
15
|
this.mediaStore = mediaApi !== null && mediaApi !== void 0 ? mediaApi : new MediaApi({
|
|
15
16
|
authProvider: mediaClientConfig.authProvider,
|
|
16
|
-
initialAuth: mediaClientConfig.initialAuth
|
|
17
|
+
initialAuth: mediaClientConfig.initialAuth,
|
|
18
|
+
chunkHashAlgorithm: mediaClientConfig.useSha256ForUploads ? ChunkHashAlgorithm.Sha256 : ChunkHashAlgorithm.Sha1
|
|
17
19
|
});
|
|
18
20
|
this.config = mediaClientConfig;
|
|
19
21
|
this.file = new FileFetcherImpl(this.mediaStore, this.store);
|
|
@@ -5,17 +5,16 @@ 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 { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
8
9
|
const MEDIA_API_REGION = 'media-api-region';
|
|
9
10
|
const MEDIA_API_ENVIRONMENT = 'media-api-environment';
|
|
10
|
-
const defaultImageOptions = {
|
|
11
|
-
'max-age': FILE_CACHE_MAX_AGE,
|
|
12
|
-
allowAnimated: true,
|
|
13
|
-
mode: 'crop'
|
|
14
|
-
};
|
|
15
11
|
const extendImageParams = (params, fetchMaxRes = false) => {
|
|
12
|
+
var _params$maxAge, _params$allowAnimated, _params$mode;
|
|
16
13
|
return {
|
|
17
|
-
...defaultImageOptions,
|
|
18
14
|
...params,
|
|
15
|
+
'max-age': (_params$maxAge = params === null || params === void 0 ? void 0 : params['max-age']) !== null && _params$maxAge !== void 0 ? _params$maxAge : FILE_CACHE_MAX_AGE,
|
|
16
|
+
allowAnimated: (_params$allowAnimated = params === null || params === void 0 ? void 0 : params.allowAnimated) !== null && _params$allowAnimated !== void 0 ? _params$allowAnimated : true,
|
|
17
|
+
mode: (_params$mode = params === null || params === void 0 ? void 0 : params.mode) !== null && _params$mode !== void 0 ? _params$mode : 'crop',
|
|
19
18
|
...(fetchMaxRes ? {
|
|
20
19
|
width: MAX_RESOLUTION,
|
|
21
20
|
height: MAX_RESOLUTION
|
|
@@ -31,6 +30,7 @@ export class MediaStore {
|
|
|
31
30
|
_defineProperty(this, "resolveAuth", authContext => resolveAuth(this.config.authProvider, authContext));
|
|
32
31
|
_defineProperty(this, "resolveInitialAuth", () => resolveInitialAuth(this.config.initialAuth));
|
|
33
32
|
this.config = config;
|
|
33
|
+
this._chunkHashAlgorithm = config.chunkHashAlgorithm || ChunkHashAlgorithm.Sha1;
|
|
34
34
|
}
|
|
35
35
|
async removeCollectionFile(id, collectionName, occurrenceKey, traceContext) {
|
|
36
36
|
const metadata = {
|
|
@@ -72,7 +72,8 @@ export class MediaStore {
|
|
|
72
72
|
collectionName
|
|
73
73
|
},
|
|
74
74
|
params: {
|
|
75
|
-
createUpTo
|
|
75
|
+
createUpTo,
|
|
76
|
+
hashAlgorithm: this._chunkHashAlgorithm
|
|
76
77
|
},
|
|
77
78
|
headers: {
|
|
78
79
|
Accept: 'application/json'
|
|
@@ -141,7 +142,10 @@ export class MediaStore {
|
|
|
141
142
|
},
|
|
142
143
|
headers: jsonHeaders,
|
|
143
144
|
body: JSON.stringify(body),
|
|
144
|
-
traceContext
|
|
145
|
+
traceContext,
|
|
146
|
+
params: {
|
|
147
|
+
hashAlgorithm: this._chunkHashAlgorithm
|
|
148
|
+
}
|
|
145
149
|
};
|
|
146
150
|
return this.request('/upload/createWithFiles', options).then(createMapResponseToJson(metadata));
|
|
147
151
|
}
|
|
@@ -343,6 +347,9 @@ export class MediaStore {
|
|
|
343
347
|
setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
|
|
344
348
|
return response;
|
|
345
349
|
}
|
|
350
|
+
get chunkHashAlgorithm() {
|
|
351
|
+
return this._chunkHashAlgorithm;
|
|
352
|
+
}
|
|
346
353
|
}
|
|
347
354
|
const getValueFromSessionStorage = key => {
|
|
348
355
|
return window && window.sessionStorage && window.sessionStorage.getItem(key) || undefined;
|
package/dist/es2019/index.js
CHANGED
|
@@ -21,4 +21,5 @@ export { globalMediaEventEmitter } from './globalMediaEventEmitter';
|
|
|
21
21
|
export { isMediaBlobUrl, getAttrsFromUrl, addFileAttrsToUrl, objectToQueryString } from './utils/url';
|
|
22
22
|
export { createMediaSubscribable, fromObservable } from './utils/mediaSubscribable';
|
|
23
23
|
export { RECENTS_COLLECTION, MAX_RESOLUTION } from './constants';
|
|
24
|
-
export { getFileStreamsCache } from './file-streams-cache';
|
|
24
|
+
export { getFileStreamsCache } from './file-streams-cache';
|
|
25
|
+
export { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
@@ -8,8 +8,8 @@ import { calculateChunkSize, fileSizeError } from './calculateChunkSize';
|
|
|
8
8
|
|
|
9
9
|
// TODO: Allow to pass multiple files
|
|
10
10
|
|
|
11
|
-
const hashingFunction = async blob => {
|
|
12
|
-
const hasher = await createHasher();
|
|
11
|
+
const hashingFunction = async (blob, hashAlgorithm) => {
|
|
12
|
+
const hasher = await createHasher(hashAlgorithm);
|
|
13
13
|
return hasher.hash(blob);
|
|
14
14
|
};
|
|
15
15
|
const createUploadingFunction = (store, deferredUploadId, collectionName, traceContext) => async chunk => {
|
|
@@ -82,7 +82,7 @@ export const uploadFile = (file, store, uploadableFileUpfrontIds, callbacks, tra
|
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
84
|
const chunkinatorObservable = chunkinator(content, {
|
|
85
|
-
hashingFunction,
|
|
85
|
+
hashingFunction: blob => hashingFunction(blob, store.chunkHashAlgorithm),
|
|
86
86
|
hashingConcurrency: 5,
|
|
87
87
|
chunkSize,
|
|
88
88
|
uploadingConcurrency: 3,
|
|
@@ -1,8 +1,19 @@
|
|
|
1
|
+
import { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
1
2
|
let hasher = null;
|
|
3
|
+
let sha256Hasher = null;
|
|
2
4
|
export const destroyHasher = () => hasher = null;
|
|
3
|
-
export const createHasher = async
|
|
5
|
+
export const createHasher = async algorithm => {
|
|
4
6
|
const numWorkers = 3;
|
|
5
|
-
if (
|
|
7
|
+
if (algorithm === ChunkHashAlgorithm.Sha256) {
|
|
8
|
+
if (!sha256Hasher) {
|
|
9
|
+
// TODO this needs to support worker sha256 hasher as well
|
|
10
|
+
const {
|
|
11
|
+
SimpleHasher
|
|
12
|
+
} = await import('./sha256SimpleHasher');
|
|
13
|
+
sha256Hasher = new SimpleHasher();
|
|
14
|
+
}
|
|
15
|
+
return sha256Hasher;
|
|
16
|
+
} else if (!hasher) {
|
|
6
17
|
try {
|
|
7
18
|
const {
|
|
8
19
|
WorkerHasher
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { sha256 } from 'js-sha256';
|
|
2
|
+
export class SimpleHasher {
|
|
3
|
+
hash(blob) {
|
|
4
|
+
return new Promise((resolve, reject) => {
|
|
5
|
+
const reader = new FileReader();
|
|
6
|
+
reader.readAsArrayBuffer(blob);
|
|
7
|
+
reader.onload = () => {
|
|
8
|
+
var _reader$result;
|
|
9
|
+
resolve(`sha256-${sha256.create().update((_reader$result = reader.result) !== null && _reader$result !== void 0 ? _reader$result : '').hex()}`);
|
|
10
|
+
};
|
|
11
|
+
reader.onerror = reject;
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -3,6 +3,7 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
|
3
3
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
4
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
5
|
import { EventEmitter2 } from 'eventemitter2';
|
|
6
|
+
import { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
6
7
|
import { MediaStore as MediaApi } from './media-store';
|
|
7
8
|
import { FileFetcherImpl } from './file-fetcher';
|
|
8
9
|
import { StargateClient } from './stargate-client';
|
|
@@ -20,7 +21,8 @@ export var MediaClient = /*#__PURE__*/function () {
|
|
|
20
21
|
this.store = store;
|
|
21
22
|
this.mediaStore = mediaApi !== null && mediaApi !== void 0 ? mediaApi : new MediaApi({
|
|
22
23
|
authProvider: mediaClientConfig.authProvider,
|
|
23
|
-
initialAuth: mediaClientConfig.initialAuth
|
|
24
|
+
initialAuth: mediaClientConfig.initialAuth,
|
|
25
|
+
chunkHashAlgorithm: mediaClientConfig.useSha256ForUploads ? ChunkHashAlgorithm.Sha256 : ChunkHashAlgorithm.Sha1
|
|
24
26
|
});
|
|
25
27
|
this.config = mediaClientConfig;
|
|
26
28
|
this.file = new FileFetcherImpl(this.mediaStore, this.store);
|
|
@@ -11,16 +11,17 @@ import { getArtifactUrl } from '../../models/artifacts';
|
|
|
11
11
|
import { request as _request } from '../../utils/request';
|
|
12
12
|
import { createUrl, createMapResponseToJson, createMapResponseToBlob } from '../../utils/request/helpers';
|
|
13
13
|
import { resolveAuth, resolveInitialAuth } from './resolveAuth';
|
|
14
|
+
import { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
14
15
|
var MEDIA_API_REGION = 'media-api-region';
|
|
15
16
|
var MEDIA_API_ENVIRONMENT = 'media-api-environment';
|
|
16
|
-
var defaultImageOptions = {
|
|
17
|
-
'max-age': FILE_CACHE_MAX_AGE,
|
|
18
|
-
allowAnimated: true,
|
|
19
|
-
mode: 'crop'
|
|
20
|
-
};
|
|
21
17
|
var extendImageParams = function extendImageParams(params) {
|
|
18
|
+
var _params$maxAge, _params$allowAnimated, _params$mode;
|
|
22
19
|
var fetchMaxRes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
23
|
-
return _objectSpread(_objectSpread(
|
|
20
|
+
return _objectSpread(_objectSpread({}, params), {}, {
|
|
21
|
+
'max-age': (_params$maxAge = params === null || params === void 0 ? void 0 : params['max-age']) !== null && _params$maxAge !== void 0 ? _params$maxAge : FILE_CACHE_MAX_AGE,
|
|
22
|
+
allowAnimated: (_params$allowAnimated = params === null || params === void 0 ? void 0 : params.allowAnimated) !== null && _params$allowAnimated !== void 0 ? _params$allowAnimated : true,
|
|
23
|
+
mode: (_params$mode = params === null || params === void 0 ? void 0 : params.mode) !== null && _params$mode !== void 0 ? _params$mode : 'crop'
|
|
24
|
+
}, fetchMaxRes ? {
|
|
24
25
|
width: MAX_RESOLUTION,
|
|
25
26
|
height: MAX_RESOLUTION
|
|
26
27
|
} : {});
|
|
@@ -40,6 +41,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
40
41
|
return resolveInitialAuth(_this.config.initialAuth);
|
|
41
42
|
});
|
|
42
43
|
this.config = config;
|
|
44
|
+
this._chunkHashAlgorithm = config.chunkHashAlgorithm || ChunkHashAlgorithm.Sha1;
|
|
43
45
|
}
|
|
44
46
|
_createClass(MediaStore, [{
|
|
45
47
|
key: "removeCollectionFile",
|
|
@@ -102,7 +104,8 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
102
104
|
collectionName: collectionName
|
|
103
105
|
},
|
|
104
106
|
params: {
|
|
105
|
-
createUpTo: createUpTo
|
|
107
|
+
createUpTo: createUpTo,
|
|
108
|
+
hashAlgorithm: this._chunkHashAlgorithm
|
|
106
109
|
},
|
|
107
110
|
headers: {
|
|
108
111
|
Accept: 'application/json'
|
|
@@ -205,7 +208,10 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
205
208
|
},
|
|
206
209
|
headers: jsonHeaders,
|
|
207
210
|
body: JSON.stringify(body),
|
|
208
|
-
traceContext: traceContext
|
|
211
|
+
traceContext: traceContext,
|
|
212
|
+
params: {
|
|
213
|
+
hashAlgorithm: this._chunkHashAlgorithm
|
|
214
|
+
}
|
|
209
215
|
});
|
|
210
216
|
return _context3.abrupt("return", this.request('/upload/createWithFiles', options).then(createMapResponseToJson(metadata)));
|
|
211
217
|
case 5:
|
|
@@ -579,6 +585,11 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
579
585
|
}
|
|
580
586
|
return request;
|
|
581
587
|
}()
|
|
588
|
+
}, {
|
|
589
|
+
key: "chunkHashAlgorithm",
|
|
590
|
+
get: function get() {
|
|
591
|
+
return this._chunkHashAlgorithm;
|
|
592
|
+
}
|
|
582
593
|
}]);
|
|
583
594
|
return MediaStore;
|
|
584
595
|
}();
|
package/dist/esm/index.js
CHANGED
|
@@ -21,4 +21,5 @@ export { globalMediaEventEmitter } from './globalMediaEventEmitter';
|
|
|
21
21
|
export { isMediaBlobUrl, getAttrsFromUrl, addFileAttrsToUrl, objectToQueryString } from './utils/url';
|
|
22
22
|
export { createMediaSubscribable, fromObservable } from './utils/mediaSubscribable';
|
|
23
23
|
export { RECENTS_COLLECTION, MAX_RESOLUTION } from './constants';
|
|
24
|
-
export { getFileStreamsCache } from './file-streams-cache';
|
|
24
|
+
export { getFileStreamsCache } from './file-streams-cache';
|
|
25
|
+
export { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
@@ -10,14 +10,14 @@ import { calculateChunkSize, fileSizeError } from './calculateChunkSize';
|
|
|
10
10
|
|
|
11
11
|
// TODO: Allow to pass multiple files
|
|
12
12
|
|
|
13
|
-
var
|
|
14
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(blob) {
|
|
13
|
+
var _hashingFunction = /*#__PURE__*/function () {
|
|
14
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(blob, hashAlgorithm) {
|
|
15
15
|
var hasher;
|
|
16
16
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
17
17
|
while (1) switch (_context.prev = _context.next) {
|
|
18
18
|
case 0:
|
|
19
19
|
_context.next = 2;
|
|
20
|
-
return createHasher();
|
|
20
|
+
return createHasher(hashAlgorithm);
|
|
21
21
|
case 2:
|
|
22
22
|
hasher = _context.sent;
|
|
23
23
|
return _context.abrupt("return", hasher.hash(blob));
|
|
@@ -27,7 +27,7 @@ var hashingFunction = /*#__PURE__*/function () {
|
|
|
27
27
|
}
|
|
28
28
|
}, _callee);
|
|
29
29
|
}));
|
|
30
|
-
return function hashingFunction(_x) {
|
|
30
|
+
return function hashingFunction(_x, _x2) {
|
|
31
31
|
return _ref.apply(this, arguments);
|
|
32
32
|
};
|
|
33
33
|
}();
|
|
@@ -57,7 +57,7 @@ var createUploadingFunction = function createUploadingFunction(store, deferredUp
|
|
|
57
57
|
}
|
|
58
58
|
}, _callee2);
|
|
59
59
|
}));
|
|
60
|
-
return function (
|
|
60
|
+
return function (_x3) {
|
|
61
61
|
return _ref2.apply(this, arguments);
|
|
62
62
|
};
|
|
63
63
|
}();
|
|
@@ -90,7 +90,7 @@ var createProcessingFunction = function createProcessingFunction(store, deferred
|
|
|
90
90
|
}
|
|
91
91
|
}, _callee3);
|
|
92
92
|
}));
|
|
93
|
-
return function (
|
|
93
|
+
return function (_x4) {
|
|
94
94
|
return _ref3.apply(this, arguments);
|
|
95
95
|
};
|
|
96
96
|
}();
|
|
@@ -126,7 +126,7 @@ var createFileFromUpload = /*#__PURE__*/function () {
|
|
|
126
126
|
}
|
|
127
127
|
}, _callee4);
|
|
128
128
|
}));
|
|
129
|
-
return function createFileFromUpload(
|
|
129
|
+
return function createFileFromUpload(_x5, _x6, _x7, _x8, _x9) {
|
|
130
130
|
return _ref4.apply(this, arguments);
|
|
131
131
|
};
|
|
132
132
|
}();
|
|
@@ -155,7 +155,9 @@ export var uploadFile = function uploadFile(file, store, uploadableFileUpfrontId
|
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
157
|
var chunkinatorObservable = chunkinator(content, {
|
|
158
|
-
hashingFunction: hashingFunction
|
|
158
|
+
hashingFunction: function hashingFunction(blob) {
|
|
159
|
+
return _hashingFunction(blob, store.chunkHashAlgorithm);
|
|
160
|
+
},
|
|
159
161
|
hashingConcurrency: 5,
|
|
160
162
|
chunkSize: chunkSize,
|
|
161
163
|
uploadingConcurrency: 3,
|
|
@@ -1,47 +1,66 @@
|
|
|
1
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
2
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
3
4
|
var hasher = null;
|
|
5
|
+
var sha256Hasher = null;
|
|
4
6
|
export var destroyHasher = function destroyHasher() {
|
|
5
7
|
return hasher = null;
|
|
6
8
|
};
|
|
7
9
|
export var createHasher = /*#__PURE__*/function () {
|
|
8
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
9
|
-
var numWorkers, _yield$import,
|
|
10
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(algorithm) {
|
|
11
|
+
var numWorkers, _yield$import, SimpleHasher, _yield$import2, WorkerHasher, _yield$import3, _SimpleHasher;
|
|
10
12
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
11
13
|
while (1) switch (_context.prev = _context.next) {
|
|
12
14
|
case 0:
|
|
13
15
|
numWorkers = 3;
|
|
14
|
-
if (
|
|
15
|
-
_context.next =
|
|
16
|
+
if (!(algorithm === ChunkHashAlgorithm.Sha256)) {
|
|
17
|
+
_context.next = 11;
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
if (sha256Hasher) {
|
|
21
|
+
_context.next = 8;
|
|
16
22
|
break;
|
|
17
23
|
}
|
|
18
|
-
_context.prev = 2;
|
|
19
24
|
_context.next = 5;
|
|
20
|
-
return import('./
|
|
25
|
+
return import('./sha256SimpleHasher');
|
|
21
26
|
case 5:
|
|
22
27
|
_yield$import = _context.sent;
|
|
23
|
-
|
|
28
|
+
SimpleHasher = _yield$import.SimpleHasher;
|
|
29
|
+
sha256Hasher = new SimpleHasher();
|
|
30
|
+
case 8:
|
|
31
|
+
return _context.abrupt("return", sha256Hasher);
|
|
32
|
+
case 11:
|
|
33
|
+
if (hasher) {
|
|
34
|
+
_context.next = 27;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
_context.prev = 12;
|
|
38
|
+
_context.next = 15;
|
|
39
|
+
return import('./workerHasher');
|
|
40
|
+
case 15:
|
|
41
|
+
_yield$import2 = _context.sent;
|
|
42
|
+
WorkerHasher = _yield$import2.WorkerHasher;
|
|
24
43
|
hasher = new WorkerHasher(numWorkers);
|
|
25
|
-
_context.next =
|
|
44
|
+
_context.next = 27;
|
|
26
45
|
break;
|
|
27
|
-
case
|
|
28
|
-
_context.prev =
|
|
29
|
-
_context.t0 = _context["catch"](
|
|
30
|
-
_context.next =
|
|
46
|
+
case 20:
|
|
47
|
+
_context.prev = 20;
|
|
48
|
+
_context.t0 = _context["catch"](12);
|
|
49
|
+
_context.next = 24;
|
|
31
50
|
return import('./simpleHasher');
|
|
32
|
-
case
|
|
33
|
-
_yield$
|
|
34
|
-
|
|
35
|
-
hasher = new
|
|
36
|
-
case
|
|
51
|
+
case 24:
|
|
52
|
+
_yield$import3 = _context.sent;
|
|
53
|
+
_SimpleHasher = _yield$import3.SimpleHasher;
|
|
54
|
+
hasher = new _SimpleHasher();
|
|
55
|
+
case 27:
|
|
37
56
|
return _context.abrupt("return", hasher);
|
|
38
|
-
case
|
|
57
|
+
case 28:
|
|
39
58
|
case "end":
|
|
40
59
|
return _context.stop();
|
|
41
60
|
}
|
|
42
|
-
}, _callee, null, [[
|
|
61
|
+
}, _callee, null, [[12, 20]]);
|
|
43
62
|
}));
|
|
44
|
-
return function createHasher() {
|
|
63
|
+
return function createHasher(_x) {
|
|
45
64
|
return _ref.apply(this, arguments);
|
|
46
65
|
};
|
|
47
66
|
}();
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import { sha256 } from 'js-sha256';
|
|
4
|
+
export var SimpleHasher = /*#__PURE__*/function () {
|
|
5
|
+
function SimpleHasher() {
|
|
6
|
+
_classCallCheck(this, SimpleHasher);
|
|
7
|
+
}
|
|
8
|
+
_createClass(SimpleHasher, [{
|
|
9
|
+
key: "hash",
|
|
10
|
+
value: function hash(blob) {
|
|
11
|
+
return new Promise(function (resolve, reject) {
|
|
12
|
+
var reader = new FileReader();
|
|
13
|
+
reader.readAsArrayBuffer(blob);
|
|
14
|
+
reader.onload = function () {
|
|
15
|
+
var _reader$result;
|
|
16
|
+
resolve("sha256-".concat(sha256.create().update((_reader$result = reader.result) !== null && _reader$result !== void 0 ? _reader$result : '').hex()));
|
|
17
|
+
};
|
|
18
|
+
reader.onerror = reject;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}]);
|
|
22
|
+
return SimpleHasher;
|
|
23
|
+
}();
|
|
@@ -3,8 +3,10 @@ import { MediaTraceContext } from '@atlaskit/media-common';
|
|
|
3
3
|
import { MediaFileArtifacts } from '@atlaskit/media-state';
|
|
4
4
|
import type { ItemsPayload, ImageMetadata, MediaStoreResponse, MediaStoreTouchFileParams, TouchFileDescriptor, MediaStoreTouchFileBody, RejectedTouchFile, MediaStoreRequestOptions, MediaStoreCreateFileFromUploadParams, MediaStoreCreateFileFromUploadBody, MediaStoreGetFileParams, MediaStoreGetFileImageParams, MediaStoreCopyFileWithTokenBody, MediaStoreCopyFileWithTokenParams, AppendChunksToUploadRequestBody, TouchedFiles, MediaApi } from './types';
|
|
5
5
|
import { MediaFile, MediaUpload } from '../../models/media';
|
|
6
|
+
import { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
6
7
|
export declare class MediaStore implements MediaApi {
|
|
7
8
|
private readonly config;
|
|
9
|
+
private readonly _chunkHashAlgorithm;
|
|
8
10
|
constructor(config: MediaApiConfig);
|
|
9
11
|
removeCollectionFile(id: string, collectionName: string, occurrenceKey?: string, traceContext?: MediaTraceContext): Promise<void>;
|
|
10
12
|
createUpload(createUpTo?: number, collectionName?: string, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaUpload[]>>;
|
|
@@ -28,6 +30,7 @@ export declare class MediaStore implements MediaApi {
|
|
|
28
30
|
request(path: string, options?: MediaStoreRequestOptions, controller?: AbortController): Promise<Response>;
|
|
29
31
|
resolveAuth: (authContext?: AuthContext) => Promise<Auth>;
|
|
30
32
|
resolveInitialAuth: () => Auth;
|
|
33
|
+
get chunkHashAlgorithm(): ChunkHashAlgorithm;
|
|
31
34
|
}
|
|
32
35
|
export declare const getMediaEnvironment: () => string | undefined;
|
|
33
36
|
export declare const getMediaRegion: () => string | undefined;
|
|
@@ -3,6 +3,7 @@ import { MediaTraceContext } from '@atlaskit/media-common';
|
|
|
3
3
|
import { MediaFileArtifacts } from '@atlaskit/media-state';
|
|
4
4
|
import { MediaItemDetails, MediaFile, MediaUpload } from '../../models/media';
|
|
5
5
|
import { ClientOptions, RequestHeaders, RequestMethod, RequestParams, RequestMetadata } from '../../utils/request/types';
|
|
6
|
+
import { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
6
7
|
export interface ResponseFileItem {
|
|
7
8
|
id: string;
|
|
8
9
|
type: 'file';
|
|
@@ -35,6 +36,7 @@ export type MediaStoreRequestOptions = RequestMetadata & {
|
|
|
35
36
|
readonly body?: any;
|
|
36
37
|
readonly clientOptions?: ClientOptions;
|
|
37
38
|
readonly traceContext?: MediaTraceContext;
|
|
39
|
+
readonly ChunkhashAlgorithm?: ChunkHashAlgorithm;
|
|
38
40
|
};
|
|
39
41
|
export type MediaStoreCreateFileFromUploadParams = {
|
|
40
42
|
readonly collection?: string;
|
|
@@ -137,7 +139,7 @@ export interface EmptyFile {
|
|
|
137
139
|
}
|
|
138
140
|
export interface MediaApi {
|
|
139
141
|
removeCollectionFile: (id: string, collectionName: string, occurrenceKey?: string, traceContext?: MediaTraceContext) => Promise<void>;
|
|
140
|
-
createUpload: (createUpTo: number, collectionName?: string, traceContext?: MediaTraceContext) => Promise<MediaStoreResponse<MediaUpload[]>>;
|
|
142
|
+
createUpload: (createUpTo: number, collectionName?: string, traceContext?: MediaTraceContext, chunkChunkHashAlgorithm?: ChunkHashAlgorithm) => Promise<MediaStoreResponse<MediaUpload[]>>;
|
|
141
143
|
uploadChunk: (etag: string, blob: Blob, uploadId: string, partNumber: number, collectionName?: string, traceContext?: MediaTraceContext) => Promise<void>;
|
|
142
144
|
createFileFromUpload: (body: MediaStoreCreateFileFromUploadBody, params: MediaStoreCreateFileFromUploadParams, traceContext?: MediaTraceContext) => Promise<MediaStoreResponse<MediaFile>>;
|
|
143
145
|
getRejectedResponseFromDescriptor: (descriptor: TouchFileDescriptor, limit: number) => RejectedTouchFile;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -43,3 +43,4 @@ export { createMediaSubscribable, fromObservable, } from './utils/mediaSubscriba
|
|
|
43
43
|
export type { MediaSubscribable, MediaSubscription, MediaObserver, } from './utils/mediaSubscribable';
|
|
44
44
|
export { RECENTS_COLLECTION, MAX_RESOLUTION } from './constants';
|
|
45
45
|
export { getFileStreamsCache } from './file-streams-cache';
|
|
46
|
+
export { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Hasher } from './hasher';
|
|
2
|
+
import { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
2
3
|
export declare const destroyHasher: () => null;
|
|
3
|
-
export declare const createHasher: () => Promise<Hasher>;
|
|
4
|
+
export declare const createHasher: (algorithm: ChunkHashAlgorithm) => Promise<Hasher>;
|
|
@@ -3,8 +3,10 @@ import { MediaTraceContext } from '@atlaskit/media-common';
|
|
|
3
3
|
import { MediaFileArtifacts } from '@atlaskit/media-state';
|
|
4
4
|
import type { ItemsPayload, ImageMetadata, MediaStoreResponse, MediaStoreTouchFileParams, TouchFileDescriptor, MediaStoreTouchFileBody, RejectedTouchFile, MediaStoreRequestOptions, MediaStoreCreateFileFromUploadParams, MediaStoreCreateFileFromUploadBody, MediaStoreGetFileParams, MediaStoreGetFileImageParams, MediaStoreCopyFileWithTokenBody, MediaStoreCopyFileWithTokenParams, AppendChunksToUploadRequestBody, TouchedFiles, MediaApi } from './types';
|
|
5
5
|
import { MediaFile, MediaUpload } from '../../models/media';
|
|
6
|
+
import { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
6
7
|
export declare class MediaStore implements MediaApi {
|
|
7
8
|
private readonly config;
|
|
9
|
+
private readonly _chunkHashAlgorithm;
|
|
8
10
|
constructor(config: MediaApiConfig);
|
|
9
11
|
removeCollectionFile(id: string, collectionName: string, occurrenceKey?: string, traceContext?: MediaTraceContext): Promise<void>;
|
|
10
12
|
createUpload(createUpTo?: number, collectionName?: string, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaUpload[]>>;
|
|
@@ -28,6 +30,7 @@ export declare class MediaStore implements MediaApi {
|
|
|
28
30
|
request(path: string, options?: MediaStoreRequestOptions, controller?: AbortController): Promise<Response>;
|
|
29
31
|
resolveAuth: (authContext?: AuthContext) => Promise<Auth>;
|
|
30
32
|
resolveInitialAuth: () => Auth;
|
|
33
|
+
get chunkHashAlgorithm(): ChunkHashAlgorithm;
|
|
31
34
|
}
|
|
32
35
|
export declare const getMediaEnvironment: () => string | undefined;
|
|
33
36
|
export declare const getMediaRegion: () => string | undefined;
|
|
@@ -3,6 +3,7 @@ import { MediaTraceContext } from '@atlaskit/media-common';
|
|
|
3
3
|
import { MediaFileArtifacts } from '@atlaskit/media-state';
|
|
4
4
|
import { MediaItemDetails, MediaFile, MediaUpload } from '../../models/media';
|
|
5
5
|
import { ClientOptions, RequestHeaders, RequestMethod, RequestParams, RequestMetadata } from '../../utils/request/types';
|
|
6
|
+
import { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
6
7
|
export interface ResponseFileItem {
|
|
7
8
|
id: string;
|
|
8
9
|
type: 'file';
|
|
@@ -35,6 +36,7 @@ export type MediaStoreRequestOptions = RequestMetadata & {
|
|
|
35
36
|
readonly body?: any;
|
|
36
37
|
readonly clientOptions?: ClientOptions;
|
|
37
38
|
readonly traceContext?: MediaTraceContext;
|
|
39
|
+
readonly ChunkhashAlgorithm?: ChunkHashAlgorithm;
|
|
38
40
|
};
|
|
39
41
|
export type MediaStoreCreateFileFromUploadParams = {
|
|
40
42
|
readonly collection?: string;
|
|
@@ -137,7 +139,7 @@ export interface EmptyFile {
|
|
|
137
139
|
}
|
|
138
140
|
export interface MediaApi {
|
|
139
141
|
removeCollectionFile: (id: string, collectionName: string, occurrenceKey?: string, traceContext?: MediaTraceContext) => Promise<void>;
|
|
140
|
-
createUpload: (createUpTo: number, collectionName?: string, traceContext?: MediaTraceContext) => Promise<MediaStoreResponse<MediaUpload[]>>;
|
|
142
|
+
createUpload: (createUpTo: number, collectionName?: string, traceContext?: MediaTraceContext, chunkChunkHashAlgorithm?: ChunkHashAlgorithm) => Promise<MediaStoreResponse<MediaUpload[]>>;
|
|
141
143
|
uploadChunk: (etag: string, blob: Blob, uploadId: string, partNumber: number, collectionName?: string, traceContext?: MediaTraceContext) => Promise<void>;
|
|
142
144
|
createFileFromUpload: (body: MediaStoreCreateFileFromUploadBody, params: MediaStoreCreateFileFromUploadParams, traceContext?: MediaTraceContext) => Promise<MediaStoreResponse<MediaFile>>;
|
|
143
145
|
getRejectedResponseFromDescriptor: (descriptor: TouchFileDescriptor, limit: number) => RejectedTouchFile;
|
|
@@ -43,3 +43,4 @@ export { createMediaSubscribable, fromObservable, } from './utils/mediaSubscriba
|
|
|
43
43
|
export type { MediaSubscribable, MediaSubscription, MediaObserver, } from './utils/mediaSubscribable';
|
|
44
44
|
export { RECENTS_COLLECTION, MAX_RESOLUTION } from './constants';
|
|
45
45
|
export { getFileStreamsCache } from './file-streams-cache';
|
|
46
|
+
export { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { Hasher } from './hasher';
|
|
2
|
+
import { ChunkHashAlgorithm } from '@atlaskit/media-core';
|
|
2
3
|
export declare const destroyHasher: () => null;
|
|
3
|
-
export declare const createHasher: () => Promise<Hasher>;
|
|
4
|
+
export declare const createHasher: (algorithm: ChunkHashAlgorithm) => Promise<Hasher>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/media-client",
|
|
3
|
-
"version": "26.
|
|
3
|
+
"version": "26.2.0",
|
|
4
4
|
"description": "Media API Web Client Library",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -36,12 +36,13 @@
|
|
|
36
36
|
}
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@atlaskit/chunkinator": "^
|
|
39
|
+
"@atlaskit/chunkinator": "^6.0.0",
|
|
40
40
|
"@atlaskit/media-common": "^11.0.0",
|
|
41
41
|
"@babel/runtime": "^7.0.0",
|
|
42
42
|
"dataloader": "^2.0.0",
|
|
43
43
|
"deep-equal": "^1.0.1",
|
|
44
44
|
"eventemitter2": "^4.1.0",
|
|
45
|
+
"js-sha256": "^0.10.1",
|
|
45
46
|
"lru_map": "^0.4.1",
|
|
46
47
|
"rusha": "^0.8.13",
|
|
47
48
|
"rxjs": "^5.5.0",
|
|
@@ -55,10 +56,10 @@
|
|
|
55
56
|
"@atlaskit/media-state": "^1.0.0"
|
|
56
57
|
},
|
|
57
58
|
"devDependencies": {
|
|
58
|
-
"@atlaskit/media-core": "^34.
|
|
59
|
+
"@atlaskit/media-core": "^34.2.0",
|
|
59
60
|
"@atlaskit/media-state": "^1.0.0",
|
|
60
61
|
"@atlaskit/ssr": "*",
|
|
61
|
-
"@atlaskit/tokens": "^1.
|
|
62
|
+
"@atlaskit/tokens": "^1.36.0",
|
|
62
63
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
63
64
|
"@emotion/react": "^11.7.1",
|
|
64
65
|
"@types/deep-equal": "^1.0.1",
|