@atlaskit/media-client 15.1.1 → 17.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/constants/package.json +1 -0
- package/dist/cjs/client/file-fetcher/index.js +0 -2
- package/dist/cjs/client/media-store/index.js +63 -24
- package/dist/cjs/constants.js +11 -2
- package/dist/cjs/index.js +12 -6
- package/dist/cjs/models/media.js +10 -2
- package/dist/cjs/uploader/calculateChunkSize.js +45 -0
- package/dist/cjs/uploader/error.js +67 -0
- package/dist/cjs/{uploader.js → uploader/index.js} +43 -8
- package/dist/cjs/utils/request/errors.js +4 -0
- package/dist/cjs/utils/request/helpers.js +40 -34
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/client/media-store/index.js +37 -9
- package/dist/es2019/constants.js +5 -1
- package/dist/es2019/index.js +2 -2
- package/dist/es2019/models/media.js +8 -1
- package/dist/es2019/uploader/calculateChunkSize.js +32 -0
- package/dist/es2019/uploader/error.js +30 -0
- package/dist/es2019/{uploader.js → uploader/index.js} +39 -8
- package/dist/es2019/utils/request/errors.js +4 -0
- package/dist/es2019/utils/request/helpers.js +22 -24
- package/dist/es2019/version.json +1 -1
- package/dist/esm/client/file-fetcher/index.js +0 -2
- package/dist/esm/client/media-store/index.js +57 -24
- package/dist/esm/constants.js +5 -1
- package/dist/esm/index.js +2 -2
- package/dist/esm/models/media.js +8 -1
- package/dist/esm/uploader/calculateChunkSize.js +32 -0
- package/dist/esm/uploader/error.js +51 -0
- package/dist/esm/{uploader.js → uploader/index.js} +39 -8
- package/dist/esm/utils/request/errors.js +4 -0
- package/dist/esm/utils/request/helpers.js +36 -31
- package/dist/esm/version.json +1 -1
- package/dist/types/client/media-store/index.d.ts +11 -2
- package/dist/types/constants.d.ts +3 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/models/errors/types.d.ts +1 -1
- package/dist/types/models/media.d.ts +5 -0
- package/dist/types/uploader/calculateChunkSize.d.ts +11 -0
- package/dist/types/uploader/error.d.ts +29 -0
- package/dist/types/{uploader.d.ts → uploader/index.d.ts} +1 -1
- package/dist/types/utils/request/errors.d.ts +2 -0
- package/dist/types/utils/request/helpers.d.ts +4 -4
- package/dist/types/utils/request/types.d.ts +2 -0
- package/package.json +7 -9
|
@@ -14,6 +14,8 @@ import { request as _request } from '../../utils/request';
|
|
|
14
14
|
import { createUrl, createMapResponseToJson, createMapResponseToBlob } from '../../utils/request/helpers';
|
|
15
15
|
import { resolveAuth, resolveInitialAuth } from './resolveAuth';
|
|
16
16
|
export { MediaStoreError, isMediaStoreError } from './error';
|
|
17
|
+
var MEDIA_API_REGION = 'media-api-region';
|
|
18
|
+
var MEDIA_API_ENVIRONMENT = 'media-api-environment';
|
|
17
19
|
var defaultImageOptions = {
|
|
18
20
|
'max-age': FILE_CACHE_MAX_AGE,
|
|
19
21
|
allowAnimated: true,
|
|
@@ -193,26 +195,38 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
193
195
|
}, {
|
|
194
196
|
key: "uploadChunk",
|
|
195
197
|
value: function () {
|
|
196
|
-
var _uploadChunk = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(etag, blob
|
|
197
|
-
var
|
|
198
|
+
var _uploadChunk = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(etag, blob) {
|
|
199
|
+
var _ref,
|
|
200
|
+
collectionName,
|
|
201
|
+
uploadId,
|
|
202
|
+
partNumber,
|
|
203
|
+
metadata,
|
|
204
|
+
options,
|
|
205
|
+
_args3 = arguments;
|
|
206
|
+
|
|
198
207
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
199
208
|
while (1) {
|
|
200
209
|
switch (_context3.prev = _context3.next) {
|
|
201
210
|
case 0:
|
|
211
|
+
_ref = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : {}, collectionName = _ref.collectionName, uploadId = _ref.uploadId, partNumber = _ref.partNumber;
|
|
202
212
|
metadata = {
|
|
203
213
|
method: 'PUT',
|
|
204
214
|
endpoint: '/chunk/{etag}'
|
|
205
215
|
};
|
|
206
216
|
options = _objectSpread(_objectSpread({}, metadata), {}, {
|
|
217
|
+
params: {
|
|
218
|
+
uploadId: uploadId,
|
|
219
|
+
partNumber: partNumber
|
|
220
|
+
},
|
|
207
221
|
authContext: {
|
|
208
222
|
collectionName: collectionName
|
|
209
223
|
},
|
|
210
224
|
body: blob
|
|
211
225
|
});
|
|
212
|
-
_context3.next =
|
|
226
|
+
_context3.next = 5;
|
|
213
227
|
return this.request("/chunk/".concat(etag), options);
|
|
214
228
|
|
|
215
|
-
case
|
|
229
|
+
case 5:
|
|
216
230
|
case "end":
|
|
217
231
|
return _context3.stop();
|
|
218
232
|
}
|
|
@@ -220,7 +234,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
220
234
|
}, _callee3, this);
|
|
221
235
|
}));
|
|
222
236
|
|
|
223
|
-
function uploadChunk(_x6, _x7
|
|
237
|
+
function uploadChunk(_x6, _x7) {
|
|
224
238
|
return _uploadChunk.apply(this, arguments);
|
|
225
239
|
}
|
|
226
240
|
|
|
@@ -228,13 +242,20 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
228
242
|
}()
|
|
229
243
|
}, {
|
|
230
244
|
key: "probeChunks",
|
|
231
|
-
value: function probeChunks(chunks
|
|
245
|
+
value: function probeChunks(chunks) {
|
|
246
|
+
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
|
|
247
|
+
collectionName = _ref2.collectionName,
|
|
248
|
+
uploadId = _ref2.uploadId;
|
|
249
|
+
|
|
232
250
|
var metadata = {
|
|
233
251
|
method: 'POST',
|
|
234
252
|
endpoint: '/chunk/probe'
|
|
235
253
|
};
|
|
236
254
|
|
|
237
255
|
var options = _objectSpread(_objectSpread({}, metadata), {}, {
|
|
256
|
+
params: {
|
|
257
|
+
uploadId: uploadId
|
|
258
|
+
},
|
|
238
259
|
authContext: {
|
|
239
260
|
collectionName: collectionName
|
|
240
261
|
},
|
|
@@ -307,13 +328,13 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
307
328
|
key: "getFileImageURL",
|
|
308
329
|
value: function () {
|
|
309
330
|
var _getFileImageURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(id, params) {
|
|
310
|
-
var
|
|
331
|
+
var _ref3, collectionName, auth;
|
|
311
332
|
|
|
312
333
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
313
334
|
while (1) {
|
|
314
335
|
switch (_context4.prev = _context4.next) {
|
|
315
336
|
case 0:
|
|
316
|
-
|
|
337
|
+
_ref3 = params || {}, collectionName = _ref3.collection;
|
|
317
338
|
_context4.next = 3;
|
|
318
339
|
return this.resolveAuth({
|
|
319
340
|
collectionName: collectionName
|
|
@@ -331,7 +352,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
331
352
|
}, _callee4, this);
|
|
332
353
|
}));
|
|
333
354
|
|
|
334
|
-
function getFileImageURL(
|
|
355
|
+
function getFileImageURL(_x8, _x9) {
|
|
335
356
|
return _getFileImageURL.apply(this, arguments);
|
|
336
357
|
}
|
|
337
358
|
|
|
@@ -386,7 +407,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
386
407
|
}, _callee5, this);
|
|
387
408
|
}));
|
|
388
409
|
|
|
389
|
-
function getFileBinaryURL(
|
|
410
|
+
function getFileBinaryURL(_x10, _x11) {
|
|
390
411
|
return _getFileBinaryURL.apply(this, arguments);
|
|
391
412
|
}
|
|
392
413
|
|
|
@@ -435,7 +456,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
435
456
|
}, _callee6, this);
|
|
436
457
|
}));
|
|
437
458
|
|
|
438
|
-
function getArtifactURL(_x13, _x14
|
|
459
|
+
function getArtifactURL(_x12, _x13, _x14) {
|
|
439
460
|
return _getArtifactURL.apply(this, arguments);
|
|
440
461
|
}
|
|
441
462
|
|
|
@@ -480,7 +501,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
480
501
|
}, _callee7, this);
|
|
481
502
|
}));
|
|
482
503
|
|
|
483
|
-
function getImage(_x16, _x17, _x18
|
|
504
|
+
function getImage(_x15, _x16, _x17, _x18) {
|
|
484
505
|
return _getImage.apply(this, arguments);
|
|
485
506
|
}
|
|
486
507
|
|
|
@@ -525,7 +546,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
525
546
|
}, _callee8, this);
|
|
526
547
|
}));
|
|
527
548
|
|
|
528
|
-
function getItems(
|
|
549
|
+
function getItems(_x19, _x20) {
|
|
529
550
|
return _getItems.apply(this, arguments);
|
|
530
551
|
}
|
|
531
552
|
|
|
@@ -560,7 +581,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
560
581
|
}, _callee9, this);
|
|
561
582
|
}));
|
|
562
583
|
|
|
563
|
-
function getImageMetadata(
|
|
584
|
+
function getImageMetadata(_x21, _x22) {
|
|
564
585
|
return _getImageMetadata.apply(this, arguments);
|
|
565
586
|
}
|
|
566
587
|
|
|
@@ -597,7 +618,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
597
618
|
}, _callee10, this);
|
|
598
619
|
}));
|
|
599
620
|
|
|
600
|
-
function appendChunksToUpload(_x24, _x25
|
|
621
|
+
function appendChunksToUpload(_x23, _x24, _x25) {
|
|
601
622
|
return _appendChunksToUpload.apply(this, arguments);
|
|
602
623
|
}
|
|
603
624
|
|
|
@@ -670,10 +691,11 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
670
691
|
|
|
671
692
|
case 8:
|
|
672
693
|
response = _context11.sent;
|
|
673
|
-
|
|
694
|
+
setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
|
|
695
|
+
setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
|
|
674
696
|
return _context11.abrupt("return", response);
|
|
675
697
|
|
|
676
|
-
case
|
|
698
|
+
case 12:
|
|
677
699
|
case "end":
|
|
678
700
|
return _context11.stop();
|
|
679
701
|
}
|
|
@@ -681,7 +703,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
681
703
|
}, _callee11, this);
|
|
682
704
|
}));
|
|
683
705
|
|
|
684
|
-
function request(
|
|
706
|
+
function request(_x26) {
|
|
685
707
|
return _request2.apply(this, arguments);
|
|
686
708
|
}
|
|
687
709
|
|
|
@@ -692,14 +714,25 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
692
714
|
return MediaStore;
|
|
693
715
|
}();
|
|
694
716
|
|
|
695
|
-
function
|
|
696
|
-
|
|
717
|
+
var getValueFromSessionStorage = function getValueFromSessionStorage(key) {
|
|
718
|
+
return window && window.sessionStorage && window.sessionStorage.getItem(key) || undefined;
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
var setKeyValueInSessionStorage = function setKeyValueInSessionStorage(key, value) {
|
|
722
|
+
if (!value || !(window && window.sessionStorage)) {
|
|
697
723
|
return;
|
|
698
724
|
}
|
|
699
725
|
|
|
700
|
-
var
|
|
726
|
+
var currentValue = window.sessionStorage.getItem(key);
|
|
701
727
|
|
|
702
|
-
if (
|
|
703
|
-
window.sessionStorage.setItem(
|
|
728
|
+
if (currentValue !== value) {
|
|
729
|
+
window.sessionStorage.setItem(key, value);
|
|
704
730
|
}
|
|
705
|
-
}
|
|
731
|
+
};
|
|
732
|
+
|
|
733
|
+
export var getMediaEnvironment = function getMediaEnvironment() {
|
|
734
|
+
return getValueFromSessionStorage(MEDIA_API_ENVIRONMENT);
|
|
735
|
+
};
|
|
736
|
+
export var getMediaRegion = function getMediaRegion() {
|
|
737
|
+
return getValueFromSessionStorage(MEDIA_API_REGION);
|
|
738
|
+
};
|
package/dist/esm/constants.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import { DATA_UNIT } from './models/media';
|
|
1
2
|
export var RECENTS_COLLECTION = 'recents';
|
|
2
3
|
export var FILE_CACHE_MAX_AGE = 60 * 60 * 24 * 30; // Retain for 30 days
|
|
3
4
|
|
|
4
|
-
export var MAX_RESOLUTION = 4096;
|
|
5
|
+
export var MAX_RESOLUTION = 4096;
|
|
6
|
+
export var CHUNK_SIZE = 4 * DATA_UNIT.MB;
|
|
7
|
+
export var PROCESSING_BATCH_SIZE = 1000;
|
|
8
|
+
export var MAX_UPLOAD_FILE_SIZE = 2 * DATA_UNIT.TB;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export { MediaStore, MediaStoreError, isMediaStoreError } from './client/media-store';
|
|
1
|
+
export { MediaStore, MediaStoreError, isMediaStoreError, getMediaEnvironment, getMediaRegion } from './client/media-store';
|
|
2
2
|
export { UploadController } from './upload-controller';
|
|
3
3
|
export { isPreviewableType, isMediaCollectionItemFullDetails } from './models/media';
|
|
4
4
|
export { getArtifactUrl } from './models/artifacts';
|
|
5
5
|
export { isMediaClientError, getMediaClientErrorReason } from './models/errors';
|
|
6
6
|
export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, mapMediaFileToFileState, mapMediaItemToFileState } from './models/file-state';
|
|
7
7
|
// TODO: remove access to media file stream cache https://product-fabric.atlassian.net/browse/MEX-1417
|
|
8
|
-
export {
|
|
8
|
+
export { StreamsCache } from './file-streams-cache';
|
|
9
9
|
export { uploadFile } from './uploader';
|
|
10
10
|
export { request, RequestError, isRequestError, isRateLimitedError } from './utils/request';
|
|
11
11
|
export { isAbortedRequestError, mapResponseToJson, mapResponseToBlob, mapResponseToVoid, createUrl } from './utils/request/helpers';
|
package/dist/esm/models/media.js
CHANGED
|
@@ -11,4 +11,11 @@ export var isPreviewableType = function isPreviewableType(type, featureFlags) {
|
|
|
11
11
|
};
|
|
12
12
|
export var isMediaCollectionItemFullDetails = function isMediaCollectionItemFullDetails(mediaCollectionItem) {
|
|
13
13
|
return !!mediaCollectionItem['mediaType'] && !!mediaCollectionItem['mimeType'] && !!mediaCollectionItem['processingStatus'];
|
|
14
|
-
};
|
|
14
|
+
};
|
|
15
|
+
export var DATA_UNIT;
|
|
16
|
+
|
|
17
|
+
(function (DATA_UNIT) {
|
|
18
|
+
DATA_UNIT[DATA_UNIT["MB"] = 1048576] = "MB";
|
|
19
|
+
DATA_UNIT[DATA_UNIT["GB"] = 1073741824] = "GB";
|
|
20
|
+
DATA_UNIT[DATA_UNIT["TB"] = 1099511627776] = "TB";
|
|
21
|
+
})(DATA_UNIT || (DATA_UNIT = {}));
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DATA_UNIT } from '../models/media';
|
|
2
|
+
import { MAX_UPLOAD_FILE_SIZE } from '../constants';
|
|
3
|
+
export var fileSizeError = 'fileSizeExceedsLimit';
|
|
4
|
+
/**
|
|
5
|
+
* This is a helper to dynamically calculate the chunk size for a given file size.
|
|
6
|
+
*
|
|
7
|
+
* @param fileSize The size of a file to calculate the chunk size for.
|
|
8
|
+
* @returns A number of bytes per chunk or Throws an Error if the file size exceeds 2TB
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://product-fabric.atlassian.net/wiki/spaces/FIL/pages/3221881143/Rule+of+thumb+for+chunk+sizes#Given-the-following-conditions}
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export var calculateChunkSize = function calculateChunkSize(fileSize) {
|
|
15
|
+
if (fileSize > MAX_UPLOAD_FILE_SIZE) {
|
|
16
|
+
throw new Error(fileSizeError);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (fileSize <= 5 * DATA_UNIT.GB) {
|
|
20
|
+
return 5 * DATA_UNIT.MB;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (fileSize > 5 * DATA_UNIT.GB && fileSize <= 50 * DATA_UNIT.GB) {
|
|
24
|
+
return 50 * DATA_UNIT.MB;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (fileSize > 50 * DATA_UNIT.GB && fileSize <= 0.95 * DATA_UNIT.TB) {
|
|
28
|
+
return 100 * DATA_UNIT.MB;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return 210 * DATA_UNIT.MB;
|
|
32
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
4
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
5
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
|
+
|
|
7
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
8
|
+
|
|
9
|
+
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; } }
|
|
10
|
+
|
|
11
|
+
import { BaseMediaClientError } from '../models/errors';
|
|
12
|
+
export var UploaderError = /*#__PURE__*/function (_BaseMediaClientError) {
|
|
13
|
+
_inherits(UploaderError, _BaseMediaClientError);
|
|
14
|
+
|
|
15
|
+
var _super = _createSuper(UploaderError);
|
|
16
|
+
|
|
17
|
+
function UploaderError(reason, id, metadata) {
|
|
18
|
+
var _this;
|
|
19
|
+
|
|
20
|
+
_classCallCheck(this, UploaderError);
|
|
21
|
+
|
|
22
|
+
_this = _super.call(this, reason);
|
|
23
|
+
_this.reason = reason;
|
|
24
|
+
_this.id = id;
|
|
25
|
+
_this.metadata = metadata;
|
|
26
|
+
return _this;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
_createClass(UploaderError, [{
|
|
30
|
+
key: "attributes",
|
|
31
|
+
get: function get() {
|
|
32
|
+
var reason = this.reason,
|
|
33
|
+
id = this.id,
|
|
34
|
+
_this$metadata = this.metadata;
|
|
35
|
+
_this$metadata = _this$metadata === void 0 ? {} : _this$metadata;
|
|
36
|
+
var collectionName = _this$metadata.collectionName,
|
|
37
|
+
occurrenceKey = _this$metadata.occurrenceKey;
|
|
38
|
+
return {
|
|
39
|
+
reason: reason,
|
|
40
|
+
id: id,
|
|
41
|
+
collectionName: collectionName,
|
|
42
|
+
occurrenceKey: occurrenceKey
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}]);
|
|
46
|
+
|
|
47
|
+
return UploaderError;
|
|
48
|
+
}(BaseMediaClientError);
|
|
49
|
+
export function isUploaderError(err) {
|
|
50
|
+
return err instanceof UploaderError;
|
|
51
|
+
}
|
|
@@ -3,7 +3,11 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
3
3
|
import { chunkinator } from '@atlaskit/chunkinator';
|
|
4
4
|
import { from } from 'rxjs/observable/from';
|
|
5
5
|
import { concatMap } from 'rxjs/operators/concatMap';
|
|
6
|
-
import { createHasher } from '
|
|
6
|
+
import { createHasher } from '../utils/hashing/hasherCreator';
|
|
7
|
+
import { UploaderError } from './error';
|
|
8
|
+
import { CHUNK_SIZE, PROCESSING_BATCH_SIZE } from '../constants';
|
|
9
|
+
import { calculateChunkSize, fileSizeError } from './calculateChunkSize';
|
|
10
|
+
import { getMediaFeatureFlag } from '@atlaskit/media-common'; // TODO: Allow to pass multiple files
|
|
7
11
|
|
|
8
12
|
var hashingFunction = /*#__PURE__*/function () {
|
|
9
13
|
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(blob) {
|
|
@@ -32,7 +36,7 @@ var hashingFunction = /*#__PURE__*/function () {
|
|
|
32
36
|
};
|
|
33
37
|
}();
|
|
34
38
|
|
|
35
|
-
var createProbingFunction = function createProbingFunction(store,
|
|
39
|
+
var createProbingFunction = function createProbingFunction(store, collectionName) {
|
|
36
40
|
return /*#__PURE__*/function () {
|
|
37
41
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(chunks) {
|
|
38
42
|
var response, results;
|
|
@@ -41,7 +45,9 @@ var createProbingFunction = function createProbingFunction(store, collection) {
|
|
|
41
45
|
switch (_context2.prev = _context2.next) {
|
|
42
46
|
case 0:
|
|
43
47
|
_context2.next = 2;
|
|
44
|
-
return store.probeChunks(hashedChunks(chunks),
|
|
48
|
+
return store.probeChunks(hashedChunks(chunks), {
|
|
49
|
+
collectionName: collectionName
|
|
50
|
+
});
|
|
45
51
|
|
|
46
52
|
case 2:
|
|
47
53
|
response = _context2.sent;
|
|
@@ -64,9 +70,11 @@ var createProbingFunction = function createProbingFunction(store, collection) {
|
|
|
64
70
|
}();
|
|
65
71
|
};
|
|
66
72
|
|
|
67
|
-
var createUploadingFunction = function createUploadingFunction(store,
|
|
73
|
+
var createUploadingFunction = function createUploadingFunction(store, collectionName) {
|
|
68
74
|
return function (chunk) {
|
|
69
|
-
return store.uploadChunk(chunk.hash, chunk.blob,
|
|
75
|
+
return store.uploadChunk(chunk.hash, chunk.blob, {
|
|
76
|
+
collectionName: collectionName
|
|
77
|
+
});
|
|
70
78
|
};
|
|
71
79
|
};
|
|
72
80
|
|
|
@@ -144,16 +152,39 @@ var createFileFromUpload = /*#__PURE__*/function () {
|
|
|
144
152
|
export var uploadFile = function uploadFile(file, store, uploadableFileUpfrontIds, callbacks) {
|
|
145
153
|
var content = file.content,
|
|
146
154
|
collection = file.collection;
|
|
147
|
-
var deferredUploadId = uploadableFileUpfrontIds.deferredUploadId
|
|
155
|
+
var deferredUploadId = uploadableFileUpfrontIds.deferredUploadId,
|
|
156
|
+
id = uploadableFileUpfrontIds.id,
|
|
157
|
+
occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
|
|
158
|
+
var chunkSize = CHUNK_SIZE;
|
|
159
|
+
|
|
160
|
+
try {
|
|
161
|
+
if (content instanceof Blob && getMediaFeatureFlag('mediaUploadApiV2', store.featureFlags)) {
|
|
162
|
+
chunkSize = calculateChunkSize(content.size);
|
|
163
|
+
}
|
|
164
|
+
} catch (err) {
|
|
165
|
+
if (err instanceof Error && err.message === fileSizeError) {
|
|
166
|
+
callbacks === null || callbacks === void 0 ? void 0 : callbacks.onUploadFinish(new UploaderError(err.message, id, {
|
|
167
|
+
collectionName: collection,
|
|
168
|
+
occurrenceKey: occurrenceKey
|
|
169
|
+
}));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return {
|
|
173
|
+
cancel: function cancel() {
|
|
174
|
+
callbacks === null || callbacks === void 0 ? void 0 : callbacks.onUploadFinish('canceled');
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
148
179
|
var chunkinatorObservable = chunkinator(content, {
|
|
149
180
|
hashingFunction: hashingFunction,
|
|
150
181
|
hashingConcurrency: 5,
|
|
151
182
|
probingBatchSize: 100,
|
|
152
|
-
chunkSize:
|
|
183
|
+
chunkSize: chunkSize,
|
|
153
184
|
uploadingConcurrency: 3,
|
|
154
185
|
uploadingFunction: createUploadingFunction(store, collection),
|
|
155
186
|
probingFunction: createProbingFunction(store, collection),
|
|
156
|
-
processingBatchSize:
|
|
187
|
+
processingBatchSize: PROCESSING_BATCH_SIZE,
|
|
157
188
|
processingFunction: createProcessingFunction(store, deferredUploadId, collection)
|
|
158
189
|
}, {
|
|
159
190
|
onProgress: function onProgress(progress) {
|
|
@@ -34,6 +34,8 @@ export var RequestError = /*#__PURE__*/function (_BaseMediaClientError) {
|
|
|
34
34
|
_this$metadata = _this$metadata === void 0 ? {} : _this$metadata;
|
|
35
35
|
var method = _this$metadata.method,
|
|
36
36
|
endpoint = _this$metadata.endpoint,
|
|
37
|
+
mediaRegion = _this$metadata.mediaRegion,
|
|
38
|
+
mediaEnv = _this$metadata.mediaEnv,
|
|
37
39
|
attempts = _this$metadata.attempts,
|
|
38
40
|
clientExhaustedRetries = _this$metadata.clientExhaustedRetries,
|
|
39
41
|
statusCode = _this$metadata.statusCode,
|
|
@@ -42,6 +44,8 @@ export var RequestError = /*#__PURE__*/function (_BaseMediaClientError) {
|
|
|
42
44
|
reason: reason,
|
|
43
45
|
method: method,
|
|
44
46
|
endpoint: endpoint,
|
|
47
|
+
mediaRegion: mediaRegion,
|
|
48
|
+
mediaEnv: mediaEnv,
|
|
45
49
|
attempts: attempts,
|
|
46
50
|
clientExhaustedRetries: clientExhaustedRetries,
|
|
47
51
|
statusCode: statusCode,
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
2
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
4
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
5
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
6
|
|
|
5
7
|
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; }
|
|
@@ -7,7 +9,6 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
7
9
|
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) { _defineProperty(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; }
|
|
8
10
|
|
|
9
11
|
import { isClientBasedAuth } from '@atlaskit/media-core';
|
|
10
|
-
import { parse, stringify } from 'query-string';
|
|
11
12
|
import { mapAuthToQueryParameters } from '../../models/auth-query-parameters';
|
|
12
13
|
import { RequestError, isRequestError } from './errors';
|
|
13
14
|
export function clientTimeoutPromise(timeout) {
|
|
@@ -30,20 +31,6 @@ export function isFetchNetworkError(err) {
|
|
|
30
31
|
export function isRateLimitedError(error) {
|
|
31
32
|
return !!error && isRequestError(error) && error.attributes.statusCode === 429 || !!error && !!error.message && error.message.includes('429');
|
|
32
33
|
}
|
|
33
|
-
export function extract(url) {
|
|
34
|
-
var index = url.indexOf('?');
|
|
35
|
-
|
|
36
|
-
if (index > 0) {
|
|
37
|
-
return {
|
|
38
|
-
baseUrl: url.substring(0, index),
|
|
39
|
-
queryParams: parse(url.substring(index + 1, url.length))
|
|
40
|
-
};
|
|
41
|
-
} else {
|
|
42
|
-
return {
|
|
43
|
-
baseUrl: url
|
|
44
|
-
};
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
34
|
export function mapAuthToRequestHeaders(auth) {
|
|
48
35
|
if (isClientBasedAuth(auth)) {
|
|
49
36
|
return {
|
|
@@ -60,15 +47,24 @@ export function mapAuthToRequestHeaders(auth) {
|
|
|
60
47
|
export function createUrl(url, _ref) {
|
|
61
48
|
var params = _ref.params,
|
|
62
49
|
auth = _ref.auth;
|
|
50
|
+
var parsedUrl = new URL(url);
|
|
51
|
+
var authParams = auth && mapAuthToQueryParameters(auth) || {};
|
|
63
52
|
|
|
64
|
-
var
|
|
65
|
-
baseUrl = _extract.baseUrl,
|
|
66
|
-
queryParams = _extract.queryParams;
|
|
53
|
+
var paramsToAppend = _objectSpread(_objectSpread({}, params), authParams);
|
|
67
54
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
55
|
+
Object.entries(paramsToAppend).filter(function (_ref2) {
|
|
56
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
57
|
+
_ = _ref3[0],
|
|
58
|
+
value = _ref3[1];
|
|
59
|
+
|
|
60
|
+
return value != null;
|
|
61
|
+
}).forEach(function (pair) {
|
|
62
|
+
var _parsedUrl$searchPara;
|
|
63
|
+
|
|
64
|
+
(_parsedUrl$searchPara = parsedUrl.searchParams).append.apply(_parsedUrl$searchPara, _toConsumableArray(pair));
|
|
65
|
+
});
|
|
66
|
+
parsedUrl.searchParams.sort();
|
|
67
|
+
return parsedUrl.toString();
|
|
72
68
|
}
|
|
73
69
|
export function withAuth(auth) {
|
|
74
70
|
return function (headers) {
|
|
@@ -171,7 +167,7 @@ export function mapResponseToVoid() {
|
|
|
171
167
|
}
|
|
172
168
|
export function createMapResponseToJson(metadata) {
|
|
173
169
|
return /*#__PURE__*/function () {
|
|
174
|
-
var
|
|
170
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(response) {
|
|
175
171
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
176
172
|
while (1) {
|
|
177
173
|
switch (_context.prev = _context.next) {
|
|
@@ -186,7 +182,7 @@ export function createMapResponseToJson(metadata) {
|
|
|
186
182
|
case 6:
|
|
187
183
|
_context.prev = 6;
|
|
188
184
|
_context.t0 = _context["catch"](0);
|
|
189
|
-
throw new RequestError('serverInvalidBody', _objectSpread(_objectSpread({}, metadata), {}, {
|
|
185
|
+
throw new RequestError('serverInvalidBody', _objectSpread(_objectSpread(_objectSpread({}, metadata), extractMediaHeaders(response)), {}, {
|
|
190
186
|
statusCode: response.status
|
|
191
187
|
}), _context.t0);
|
|
192
188
|
|
|
@@ -199,13 +195,13 @@ export function createMapResponseToJson(metadata) {
|
|
|
199
195
|
}));
|
|
200
196
|
|
|
201
197
|
return function (_x3) {
|
|
202
|
-
return
|
|
198
|
+
return _ref4.apply(this, arguments);
|
|
203
199
|
};
|
|
204
200
|
}();
|
|
205
201
|
}
|
|
206
202
|
export function createMapResponseToBlob(metadata) {
|
|
207
203
|
return /*#__PURE__*/function () {
|
|
208
|
-
var
|
|
204
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(response) {
|
|
209
205
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
210
206
|
while (1) {
|
|
211
207
|
switch (_context2.prev = _context2.next) {
|
|
@@ -220,7 +216,7 @@ export function createMapResponseToBlob(metadata) {
|
|
|
220
216
|
case 6:
|
|
221
217
|
_context2.prev = 6;
|
|
222
218
|
_context2.t0 = _context2["catch"](0);
|
|
223
|
-
throw new RequestError('serverInvalidBody', _objectSpread(_objectSpread({}, metadata), {}, {
|
|
219
|
+
throw new RequestError('serverInvalidBody', _objectSpread(_objectSpread(_objectSpread({}, metadata), extractMediaHeaders(response)), {}, {
|
|
224
220
|
statusCode: response.status
|
|
225
221
|
}), _context2.t0);
|
|
226
222
|
|
|
@@ -233,7 +229,7 @@ export function createMapResponseToBlob(metadata) {
|
|
|
233
229
|
}));
|
|
234
230
|
|
|
235
231
|
return function (_x4) {
|
|
236
|
-
return
|
|
232
|
+
return _ref5.apply(this, arguments);
|
|
237
233
|
};
|
|
238
234
|
}();
|
|
239
235
|
}
|
|
@@ -278,7 +274,7 @@ function _fetchRetry() {
|
|
|
278
274
|
timeoutInMs = startTimeoutInMs;
|
|
279
275
|
|
|
280
276
|
waitAndBumpTimeout = /*#__PURE__*/function () {
|
|
281
|
-
var
|
|
277
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
|
282
278
|
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
283
279
|
while (1) {
|
|
284
280
|
switch (_context5.prev = _context5.next) {
|
|
@@ -299,7 +295,7 @@ function _fetchRetry() {
|
|
|
299
295
|
}));
|
|
300
296
|
|
|
301
297
|
return function waitAndBumpTimeout() {
|
|
302
|
-
return
|
|
298
|
+
return _ref6.apply(this, arguments);
|
|
303
299
|
};
|
|
304
300
|
}();
|
|
305
301
|
|
|
@@ -401,7 +397,7 @@ export function createRequestErrorReason(statusCode) {
|
|
|
401
397
|
export function createRequestErrorFromResponse(metadata, response) {
|
|
402
398
|
var statusCode = response.status;
|
|
403
399
|
var reason = createRequestErrorReason(statusCode);
|
|
404
|
-
return new RequestError(reason, _objectSpread(_objectSpread({}, metadata), {}, {
|
|
400
|
+
return new RequestError(reason, _objectSpread(_objectSpread(_objectSpread({}, metadata), extractMediaHeaders(response)), {}, {
|
|
405
401
|
statusCode: statusCode
|
|
406
402
|
}));
|
|
407
403
|
}
|
|
@@ -414,4 +410,13 @@ export function createProcessFetchResponse(metadata) {
|
|
|
414
410
|
var requestError = createRequestErrorFromResponse(metadata, response);
|
|
415
411
|
throw requestError;
|
|
416
412
|
};
|
|
413
|
+
}
|
|
414
|
+
export function extractMediaHeaders(response) {
|
|
415
|
+
var headers = response.headers;
|
|
416
|
+
var mediaRegion = headers.get('x-media-region') || 'unknown';
|
|
417
|
+
var mediaEnv = headers.get('x-media-env') || 'unknown';
|
|
418
|
+
return {
|
|
419
|
+
mediaRegion: mediaRegion,
|
|
420
|
+
mediaEnv: mediaEnv
|
|
421
|
+
};
|
|
417
422
|
}
|
package/dist/esm/version.json
CHANGED
|
@@ -12,8 +12,15 @@ export declare class MediaStore {
|
|
|
12
12
|
getCollectionItems(collectionName: string, params?: MediaStoreGetCollectionItemsParams): Promise<MediaStoreResponse<MediaCollectionItems>>;
|
|
13
13
|
removeCollectionFile(id: string, collectionName: string, occurrenceKey?: string): Promise<void>;
|
|
14
14
|
createUpload(createUpTo?: number, collectionName?: string): Promise<MediaStoreResponse<MediaUpload[]>>;
|
|
15
|
-
uploadChunk(etag: string, blob: Blob, collectionName?:
|
|
16
|
-
|
|
15
|
+
uploadChunk(etag: string, blob: Blob, { collectionName, uploadId, partNumber, }?: {
|
|
16
|
+
collectionName?: string;
|
|
17
|
+
uploadId?: string;
|
|
18
|
+
partNumber?: number;
|
|
19
|
+
}): Promise<void>;
|
|
20
|
+
probeChunks(chunks: string[], { collectionName, uploadId, }?: {
|
|
21
|
+
collectionName?: string;
|
|
22
|
+
uploadId?: string;
|
|
23
|
+
}): Promise<MediaStoreResponse<MediaChunksProbe>>;
|
|
17
24
|
createFileFromUpload(body: MediaStoreCreateFileFromUploadBody, params?: MediaStoreCreateFileFromUploadParams): Promise<MediaStoreResponse<MediaFile>>;
|
|
18
25
|
touchFiles(body: MediaStoreTouchFileBody, params?: MediaStoreTouchFileParams): Promise<MediaStoreResponse<TouchedFiles>>;
|
|
19
26
|
getFile(fileId: string, params?: MediaStoreGetFileParams): Promise<MediaStoreResponse<MediaFile>>;
|
|
@@ -33,6 +40,8 @@ export declare class MediaStore {
|
|
|
33
40
|
resolveAuth: (authContext?: AuthContext | undefined) => Promise<Auth>;
|
|
34
41
|
resolveInitialAuth: () => Auth;
|
|
35
42
|
}
|
|
43
|
+
export declare const getMediaEnvironment: () => string | undefined;
|
|
44
|
+
export declare const getMediaRegion: () => string | undefined;
|
|
36
45
|
export interface ResponseFileItem {
|
|
37
46
|
id: string;
|
|
38
47
|
type: 'file';
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export declare const RECENTS_COLLECTION = "recents";
|
|
2
2
|
export declare const FILE_CACHE_MAX_AGE: number;
|
|
3
3
|
export declare const MAX_RESOLUTION = 4096;
|
|
4
|
+
export declare const CHUNK_SIZE: number;
|
|
5
|
+
export declare const PROCESSING_BATCH_SIZE = 1000;
|
|
6
|
+
export declare const MAX_UPLOAD_FILE_SIZE: number;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { MediaStore, MediaStoreError, isMediaStoreError, } from './client/media-store';
|
|
1
|
+
export { MediaStore, MediaStoreError, isMediaStoreError, getMediaEnvironment, getMediaRegion, } from './client/media-store';
|
|
2
2
|
export type { ResponseFileItem, ItemsPayload, ImageMetadataArtifact, ImageMetadata, MediaStoreResponse, MediaStoreRequestOptions, MediaStoreCreateFileFromUploadParams, MediaStoreCreateFileParams, MediaStoreTouchFileParams, TouchFileDescriptor, MediaStoreTouchFileBody, MediaStoreCreateFileFromBinaryParams, MediaStoreCreateFileFromUploadConditions, MediaStoreCreateFileFromUploadBody, MediaStoreGetFileParams, MediaStoreGetFileImageParams, MediaStoreGetCollectionItemsParams, SourceFile, MediaStoreCopyFileWithTokenBody, MediaStoreCopyFileWithTokenParams, AppendChunksToUploadRequestBody, CreatedTouchedFile, TouchedFiles, EmptyFile, MediaStoreErrorReason, MediaStoreErrorAttributes, } from './client/media-store';
|
|
3
3
|
export { UploadController } from './upload-controller';
|
|
4
4
|
export type { AbortFunction } from './upload-controller';
|
|
@@ -13,7 +13,7 @@ export type { MediaClientError, MediaClientErrorReason, MediaClientErrorAttribut
|
|
|
13
13
|
export { isUploadingFileState, isProcessingFileState, isProcessedFileState, isErrorFileState, isPreviewableFileState, isFinalFileState, isImageRepresentationReady, mapMediaFileToFileState, mapMediaItemToFileState, } from './models/file-state';
|
|
14
14
|
export type { FileStatus, FilePreview, PreviewOptions, GetFileOptions, UploadingFileState, ProcessingFileState, ProcessedFileState, ProcessingFailedState, ErrorFileState, NonErrorFileState, PreviewableFileState, FileState, } from './models/file-state';
|
|
15
15
|
export type { MobileUploadStartEvent, MobileUploadProgressEvent, MobileUploadEndEvent, MobileUploadErrorEvent, } from './models/mobile-upload';
|
|
16
|
-
export {
|
|
16
|
+
export { StreamsCache } from './file-streams-cache';
|
|
17
17
|
export { uploadFile } from './uploader';
|
|
18
18
|
export type { UploadableFile, UploadableFileUpfrontIds, UploadFileCallbacks, UploadFileResult, } from './uploader';
|
|
19
19
|
export { request, RequestError, isRequestError, isRateLimitedError, } from './utils/request';
|