@atlaskit/media-client 16.0.0 → 17.1.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 +44 -0
- package/dist/cjs/client/collection-fetcher.js +4 -4
- package/dist/cjs/client/file-fetcher/index.js +5 -9
- package/dist/cjs/client/media-store/index.js +49 -32
- package/dist/cjs/constants.js +11 -2
- package/dist/cjs/index.js +2 -2
- 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/index.js +318 -0
- package/dist/cjs/utils/{toMediaSubscribable.js → mediaSubscribable/fromObservable.js} +4 -4
- package/dist/cjs/utils/mediaSubscribable/index.js +27 -0
- package/dist/cjs/utils/{mediaSubscribableToPromise.js → mediaSubscribable/toPromise.js} +3 -3
- package/dist/cjs/utils/mediaSubscribable/types.js +5 -0
- package/dist/cjs/utils/request/errors.js +4 -0
- package/dist/cjs/utils/request/helpers.js +14 -3
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/client/collection-fetcher.js +2 -2
- package/dist/es2019/client/file-fetcher/index.js +5 -6
- package/dist/es2019/client/media-store/index.js +30 -18
- package/dist/es2019/constants.js +5 -1
- package/dist/es2019/index.js +1 -1
- 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} +47 -10
- package/dist/es2019/utils/{toMediaSubscribable.js → mediaSubscribable/fromObservable.js} +3 -3
- package/dist/es2019/utils/mediaSubscribable/index.js +2 -0
- package/dist/es2019/utils/{mediaSubscribableToPromise.js → mediaSubscribable/toPromise.js} +1 -1
- package/dist/es2019/utils/mediaSubscribable/types.js +1 -0
- package/dist/es2019/utils/request/errors.js +4 -0
- package/dist/es2019/utils/request/helpers.js +14 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/client/collection-fetcher.js +3 -3
- package/dist/esm/client/file-fetcher/index.js +6 -9
- package/dist/esm/client/media-client.js +1 -1
- package/dist/esm/client/media-store/index.js +50 -33
- package/dist/esm/client/media-store/resolveAuth.js +1 -1
- package/dist/esm/client/stargate-client.js +1 -1
- package/dist/esm/constants.js +5 -1
- package/dist/esm/index.js +1 -1
- 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/index.js +298 -0
- package/dist/esm/utils/createFileDataLoader.js +1 -1
- package/dist/esm/utils/getDimensionsFromBlob.js +1 -1
- package/dist/esm/utils/getVideoDimensionsFromBlob.js +1 -1
- package/dist/esm/utils/hashing/hasherCreator.js +1 -1
- package/dist/esm/utils/{toMediaSubscribable.js → mediaSubscribable/fromObservable.js} +3 -3
- package/dist/esm/utils/mediaSubscribable/index.js +2 -0
- package/dist/esm/utils/{mediaSubscribableToPromise.js → mediaSubscribable/toPromise.js} +1 -1
- package/dist/esm/utils/mediaSubscribable/types.js +1 -0
- package/dist/esm/utils/mobileUpload/helpers.js +1 -1
- package/dist/esm/utils/mobileUpload/stateMachine/index.js +1 -1
- package/dist/esm/utils/polling/index.js +1 -1
- package/dist/esm/utils/request/errors.js +4 -0
- package/dist/esm/utils/request/helpers.js +13 -4
- package/dist/esm/utils/request/index.js +1 -1
- package/dist/esm/utils/shouldFetchRemoteFileStates.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/client/collection-fetcher.d.ts +1 -1
- package/dist/types/client/file-fetcher/index.d.ts +1 -1
- package/dist/types/client/media-store/index.d.ts +9 -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} +2 -2
- package/dist/types/utils/mediaSubscribable/fromObservable.d.ts +5 -0
- package/dist/types/utils/mediaSubscribable/index.d.ts +3 -0
- package/dist/types/utils/{mediaSubscribableToPromise.d.ts → mediaSubscribable/toPromise.d.ts} +3 -3
- package/dist/types/utils/mediaSubscribable/types.d.ts +16 -0
- package/dist/types/utils/request/errors.d.ts +2 -0
- package/dist/types/utils/request/helpers.d.ts +4 -0
- package/dist/types/utils/request/types.d.ts +2 -0
- package/dist/types/utils/safeUnsubscribe.d.ts +1 -1
- package/example-helpers/styles.ts +99 -0
- package/example-helpers/stylesWrapper.tsx +82 -0
- package/package.json +7 -6
- package/report.api.md +1389 -0
- package/dist/cjs/uploader.js +0 -210
- package/dist/esm/uploader.js +0 -194
- package/dist/types/utils/toMediaSubscribable.d.ts +0 -20
- package/example-helpers/styled.ts +0 -77
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DATA_UNIT } from '../models/media';
|
|
2
|
+
import { MAX_UPLOAD_FILE_SIZE } from '../constants';
|
|
3
|
+
export const 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 const 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,30 @@
|
|
|
1
|
+
import { BaseMediaClientError } from '../models/errors';
|
|
2
|
+
export class UploaderError extends BaseMediaClientError {
|
|
3
|
+
constructor(reason, id, metadata) {
|
|
4
|
+
super(reason);
|
|
5
|
+
this.reason = reason;
|
|
6
|
+
this.id = id;
|
|
7
|
+
this.metadata = metadata;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
get attributes() {
|
|
11
|
+
const {
|
|
12
|
+
reason,
|
|
13
|
+
id,
|
|
14
|
+
metadata: {
|
|
15
|
+
collectionName,
|
|
16
|
+
occurrenceKey
|
|
17
|
+
} = {}
|
|
18
|
+
} = this;
|
|
19
|
+
return {
|
|
20
|
+
reason,
|
|
21
|
+
id,
|
|
22
|
+
collectionName,
|
|
23
|
+
occurrenceKey
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
export function isUploaderError(err) {
|
|
29
|
+
return err instanceof UploaderError;
|
|
30
|
+
}
|
|
@@ -1,21 +1,35 @@
|
|
|
1
1
|
import { chunkinator } from '@atlaskit/chunkinator';
|
|
2
2
|
import { from } from 'rxjs/observable/from';
|
|
3
3
|
import { concatMap } from 'rxjs/operators/concatMap';
|
|
4
|
-
import { createHasher } from '
|
|
4
|
+
import { createHasher } from '../utils/hashing/hasherCreator';
|
|
5
|
+
import { UploaderError } from './error';
|
|
6
|
+
import { CHUNK_SIZE, PROCESSING_BATCH_SIZE } from '../constants';
|
|
7
|
+
import { calculateChunkSize, fileSizeError } from './calculateChunkSize';
|
|
8
|
+
import { getMediaFeatureFlag } from '@atlaskit/media-common'; // TODO: Allow to pass multiple files
|
|
5
9
|
|
|
6
10
|
const hashingFunction = async blob => {
|
|
7
11
|
const hasher = await createHasher();
|
|
8
12
|
return hasher.hash(blob);
|
|
9
13
|
};
|
|
10
14
|
|
|
11
|
-
const createProbingFunction = (store,
|
|
12
|
-
const response = await store.probeChunks(hashedChunks(chunks),
|
|
15
|
+
const createProbingFunction = (store, deferredUploadId, collectionName) => async chunks => {
|
|
16
|
+
const response = await store.probeChunks(hashedChunks(chunks), {
|
|
17
|
+
collectionName,
|
|
18
|
+
uploadId: getMediaFeatureFlag('mediaUploadApiV2', store.featureFlags) ? await deferredUploadId : undefined
|
|
19
|
+
});
|
|
13
20
|
const results = response.data.results;
|
|
14
21
|
return Object.values(results).map(result => result.exists);
|
|
15
22
|
};
|
|
16
23
|
|
|
17
|
-
const createUploadingFunction = (store,
|
|
18
|
-
|
|
24
|
+
const createUploadingFunction = (store, deferredUploadId, collectionName) => async chunk => {
|
|
25
|
+
const options = getMediaFeatureFlag('mediaUploadApiV2', store.featureFlags) ? {
|
|
26
|
+
partNumber: chunk.partNumber,
|
|
27
|
+
uploadId: await deferredUploadId
|
|
28
|
+
} : {};
|
|
29
|
+
return await store.uploadChunk(chunk.hash, chunk.blob, {
|
|
30
|
+
collectionName,
|
|
31
|
+
...options
|
|
32
|
+
});
|
|
19
33
|
};
|
|
20
34
|
|
|
21
35
|
const createProcessingFunction = (store, deferredUploadId, collection) => {
|
|
@@ -50,23 +64,46 @@ const createFileFromUpload = async (file, store, uploadableFileUpfrontIds, uploa
|
|
|
50
64
|
});
|
|
51
65
|
};
|
|
52
66
|
|
|
53
|
-
export const uploadFile = (file, store, uploadableFileUpfrontIds, callbacks
|
|
67
|
+
export const uploadFile = (file, store, uploadableFileUpfrontIds, callbacks) => {
|
|
54
68
|
const {
|
|
55
69
|
content,
|
|
56
70
|
collection
|
|
57
71
|
} = file;
|
|
58
72
|
const {
|
|
59
|
-
deferredUploadId
|
|
73
|
+
deferredUploadId,
|
|
74
|
+
id,
|
|
75
|
+
occurrenceKey
|
|
60
76
|
} = uploadableFileUpfrontIds;
|
|
77
|
+
let chunkSize = CHUNK_SIZE;
|
|
78
|
+
|
|
79
|
+
try {
|
|
80
|
+
if (content instanceof Blob && getMediaFeatureFlag('mediaUploadApiV2', store.featureFlags)) {
|
|
81
|
+
chunkSize = calculateChunkSize(content.size);
|
|
82
|
+
}
|
|
83
|
+
} catch (err) {
|
|
84
|
+
if (err instanceof Error && err.message === fileSizeError) {
|
|
85
|
+
callbacks === null || callbacks === void 0 ? void 0 : callbacks.onUploadFinish(new UploaderError(err.message, id, {
|
|
86
|
+
collectionName: collection,
|
|
87
|
+
occurrenceKey: occurrenceKey
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
cancel: () => {
|
|
93
|
+
callbacks === null || callbacks === void 0 ? void 0 : callbacks.onUploadFinish('canceled');
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
61
98
|
const chunkinatorObservable = chunkinator(content, {
|
|
62
99
|
hashingFunction,
|
|
63
100
|
hashingConcurrency: 5,
|
|
64
101
|
probingBatchSize: 100,
|
|
65
102
|
chunkSize,
|
|
66
103
|
uploadingConcurrency: 3,
|
|
67
|
-
uploadingFunction: createUploadingFunction(store, collection),
|
|
68
|
-
probingFunction: createProbingFunction(store, collection),
|
|
69
|
-
processingBatchSize,
|
|
104
|
+
uploadingFunction: createUploadingFunction(store, deferredUploadId, collection),
|
|
105
|
+
probingFunction: createProbingFunction(store, deferredUploadId, collection),
|
|
106
|
+
processingBatchSize: PROCESSING_BATCH_SIZE,
|
|
70
107
|
processingFunction: createProcessingFunction(store, deferredUploadId, collection)
|
|
71
108
|
}, {
|
|
72
109
|
onProgress(progress) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createMediaSubject } from '
|
|
2
|
-
export function
|
|
1
|
+
import { createMediaSubject } from '../createMediaSubject';
|
|
2
|
+
export function fromObservable(observable) {
|
|
3
3
|
return {
|
|
4
4
|
subscribe: observer => {
|
|
5
5
|
const subscription = // This is needed to handle "subscribe" function overload.
|
|
@@ -14,5 +14,5 @@ export function toMediaSubscribable(observable) {
|
|
|
14
14
|
};
|
|
15
15
|
}
|
|
16
16
|
export function createMediaSubscribable(mediaSubscribableItem) {
|
|
17
|
-
return
|
|
17
|
+
return fromObservable(createMediaSubject(mediaSubscribableItem));
|
|
18
18
|
}
|
|
@@ -6,7 +6,7 @@ import { Subscription } from 'rxjs/Subscription';
|
|
|
6
6
|
* @param mediaSubscribable a given MediaSubscribable<MediaSubscribableItem>
|
|
7
7
|
* @param subscription a default Subscription (this parameter exists for testing purpose)
|
|
8
8
|
*/
|
|
9
|
-
export const
|
|
9
|
+
export const toPromise = (mediaSubscribable, subscription = new Subscription()) => {
|
|
10
10
|
return new Promise((resolve, reject) => subscription.add(mediaSubscribable.subscribe({
|
|
11
11
|
next: state => {
|
|
12
12
|
resolve(state);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -13,6 +13,8 @@ export class RequestError extends BaseMediaClientError {
|
|
|
13
13
|
metadata: {
|
|
14
14
|
method,
|
|
15
15
|
endpoint,
|
|
16
|
+
mediaRegion,
|
|
17
|
+
mediaEnv,
|
|
16
18
|
attempts,
|
|
17
19
|
clientExhaustedRetries,
|
|
18
20
|
statusCode
|
|
@@ -23,6 +25,8 @@ export class RequestError extends BaseMediaClientError {
|
|
|
23
25
|
reason,
|
|
24
26
|
method,
|
|
25
27
|
endpoint,
|
|
28
|
+
mediaRegion,
|
|
29
|
+
mediaEnv,
|
|
26
30
|
attempts,
|
|
27
31
|
clientExhaustedRetries,
|
|
28
32
|
statusCode,
|
|
@@ -108,6 +108,7 @@ export function createMapResponseToJson(metadata) {
|
|
|
108
108
|
return await response.json();
|
|
109
109
|
} catch (err) {
|
|
110
110
|
throw new RequestError('serverInvalidBody', { ...metadata,
|
|
111
|
+
...extractMediaHeaders(response),
|
|
111
112
|
statusCode: response.status
|
|
112
113
|
}, err);
|
|
113
114
|
}
|
|
@@ -119,6 +120,7 @@ export function createMapResponseToBlob(metadata) {
|
|
|
119
120
|
return await response.blob();
|
|
120
121
|
} catch (err) {
|
|
121
122
|
throw new RequestError('serverInvalidBody', { ...metadata,
|
|
123
|
+
...extractMediaHeaders(response),
|
|
122
124
|
statusCode: response.status
|
|
123
125
|
}, err);
|
|
124
126
|
}
|
|
@@ -224,6 +226,7 @@ export function createRequestErrorFromResponse(metadata, response) {
|
|
|
224
226
|
} = response;
|
|
225
227
|
const reason = createRequestErrorReason(statusCode);
|
|
226
228
|
return new RequestError(reason, { ...metadata,
|
|
229
|
+
...extractMediaHeaders(response),
|
|
227
230
|
statusCode
|
|
228
231
|
});
|
|
229
232
|
}
|
|
@@ -236,4 +239,15 @@ export function createProcessFetchResponse(metadata) {
|
|
|
236
239
|
const requestError = createRequestErrorFromResponse(metadata, response);
|
|
237
240
|
throw requestError;
|
|
238
241
|
};
|
|
242
|
+
}
|
|
243
|
+
export function extractMediaHeaders(response) {
|
|
244
|
+
const {
|
|
245
|
+
headers
|
|
246
|
+
} = response;
|
|
247
|
+
const mediaRegion = headers.get('x-media-region') || 'unknown';
|
|
248
|
+
const mediaEnv = headers.get('x-media-env') || 'unknown';
|
|
249
|
+
return {
|
|
250
|
+
mediaRegion,
|
|
251
|
+
mediaEnv
|
|
252
|
+
};
|
|
239
253
|
}
|
package/dist/es2019/version.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
2
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
4
3
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
4
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
6
5
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
6
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
7
7
|
|
|
8
8
|
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; }
|
|
9
9
|
|
|
@@ -12,7 +12,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
12
12
|
import { ReplaySubject } from 'rxjs/ReplaySubject';
|
|
13
13
|
import { getFileStreamsCache } from '../file-streams-cache';
|
|
14
14
|
import { mapMediaFileToFileState } from '../models/file-state';
|
|
15
|
-
import {
|
|
15
|
+
import { fromObservable } from '../utils/mediaSubscribable';
|
|
16
16
|
export var collectionCache = {};
|
|
17
17
|
|
|
18
18
|
var createCacheEntry = function createCacheEntry() {
|
|
@@ -98,7 +98,7 @@ export var CollectionFetcher = /*#__PURE__*/function () {
|
|
|
98
98
|
}).catch(function (error) {
|
|
99
99
|
return subject.error(error);
|
|
100
100
|
});
|
|
101
|
-
return
|
|
101
|
+
return fromObservable(subject);
|
|
102
102
|
}
|
|
103
103
|
}, {
|
|
104
104
|
key: "removeFile",
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
2
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
3
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
@@ -8,6 +7,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
|
8
7
|
|
|
9
8
|
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; }
|
|
10
9
|
|
|
10
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
11
11
|
import { Subscription } from 'rxjs/Subscription';
|
|
12
12
|
import { of } from 'rxjs/observable/of';
|
|
13
13
|
import { map } from 'rxjs/operators/map';
|
|
@@ -30,14 +30,13 @@ import { createFileDataloader } from '../../utils/createFileDataLoader';
|
|
|
30
30
|
import { getMediaTypeFromUploadableFile } from '../../utils/getMediaTypeFromUploadableFile';
|
|
31
31
|
import { overrideMediaTypeIfUnknown } from '../../utils/overrideMediaTypeIfUnknown';
|
|
32
32
|
import { convertBase64ToBlob } from '../../utils/convertBase64ToBlob';
|
|
33
|
-
import {
|
|
33
|
+
import { toPromise, fromObservable } from '../../utils/mediaSubscribable';
|
|
34
34
|
import { getDimensionsFromBlob } from '../../utils/getDimensionsFromBlob';
|
|
35
35
|
import { createMediaSubject } from '../../utils/createMediaSubject';
|
|
36
36
|
import { isMimeTypeSupportedByBrowser, getMediaTypeFromMimeType } from '@atlaskit/media-common/mediaTypeUtils';
|
|
37
37
|
import { shouldFetchRemoteFileStates, shouldFetchRemoteFileStatesObservable } from '../../utils/shouldFetchRemoteFileStates';
|
|
38
38
|
import { PollingFunction } from '../../utils/polling';
|
|
39
39
|
import { isEmptyFile } from '../../utils/detectEmptyFile';
|
|
40
|
-
import { toMediaSubscribable } from '../../utils/toMediaSubscribable';
|
|
41
40
|
export { isFileFetcherError, FileFetcherError } from './error';
|
|
42
41
|
export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
43
42
|
function FileFetcherImpl(mediaStore) {
|
|
@@ -134,17 +133,17 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
134
133
|
collectionName: collectionName,
|
|
135
134
|
occurrenceKey: occurrenceKey
|
|
136
135
|
}));
|
|
137
|
-
return
|
|
136
|
+
return fromObservable(subject);
|
|
138
137
|
}
|
|
139
138
|
|
|
140
|
-
return
|
|
139
|
+
return fromObservable(getFileStreamsCache().getOrInsert(id, function () {
|
|
141
140
|
return _this2.createDownloadFileStream(id, collectionName);
|
|
142
141
|
}));
|
|
143
142
|
}
|
|
144
143
|
}, {
|
|
145
144
|
key: "getCurrentState",
|
|
146
145
|
value: function getCurrentState(id, options) {
|
|
147
|
-
return
|
|
146
|
+
return toPromise(this.getFileState(id, options));
|
|
148
147
|
}
|
|
149
148
|
}, {
|
|
150
149
|
key: "getArtifactURL",
|
|
@@ -285,7 +284,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
285
284
|
};
|
|
286
285
|
mediaType = getMediaTypeFromMimeType(type); // we emit a richer state after the blob is fetched
|
|
287
286
|
|
|
288
|
-
// we emit a richer state after the blob is fetched
|
|
289
287
|
subject.next({
|
|
290
288
|
status: 'processing',
|
|
291
289
|
name: name,
|
|
@@ -297,7 +295,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
297
295
|
preview: preview
|
|
298
296
|
}); // we don't want to wait for the file to be upload
|
|
299
297
|
|
|
300
|
-
// we don't want to wait for the file to be upload
|
|
301
298
|
_this3.upload(file, undefined, uploadableFileUpfrontIds);
|
|
302
299
|
|
|
303
300
|
_context3.next = 12;
|
|
@@ -434,7 +431,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
434
431
|
});
|
|
435
432
|
}
|
|
436
433
|
|
|
437
|
-
return
|
|
434
|
+
return fromObservable(subject);
|
|
438
435
|
}
|
|
439
436
|
}, {
|
|
440
437
|
key: "downloadBinary",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
2
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
3
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
5
|
import { EventEmitter2 } from 'eventemitter2';
|
|
6
6
|
import { MediaStore } from './media-store';
|
|
7
7
|
import { CollectionFetcher } from './collection-fetcher';
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
2
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
3
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
5
4
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
6
6
|
|
|
7
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; }
|
|
8
8
|
|
|
@@ -15,6 +15,7 @@ import { createUrl, createMapResponseToJson, createMapResponseToBlob } from '../
|
|
|
15
15
|
import { resolveAuth, resolveInitialAuth } from './resolveAuth';
|
|
16
16
|
export { MediaStoreError, isMediaStoreError } from './error';
|
|
17
17
|
var MEDIA_API_REGION = 'media-api-region';
|
|
18
|
+
var MEDIA_API_ENVIRONMENT = 'media-api-environment';
|
|
18
19
|
var defaultImageOptions = {
|
|
19
20
|
'max-age': FILE_CACHE_MAX_AGE,
|
|
20
21
|
allowAnimated: true,
|
|
@@ -37,7 +38,6 @@ var jsonHeaders = {
|
|
|
37
38
|
Accept: 'application/json',
|
|
38
39
|
'Content-Type': 'application/json'
|
|
39
40
|
};
|
|
40
|
-
var mediaEnvironment;
|
|
41
41
|
export var MediaStore = /*#__PURE__*/function () {
|
|
42
42
|
function MediaStore(config, featureFlags) {
|
|
43
43
|
var _this = this;
|
|
@@ -195,26 +195,38 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
195
195
|
}, {
|
|
196
196
|
key: "uploadChunk",
|
|
197
197
|
value: function () {
|
|
198
|
-
var _uploadChunk = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(etag, blob
|
|
199
|
-
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
|
+
|
|
200
207
|
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
201
208
|
while (1) {
|
|
202
209
|
switch (_context3.prev = _context3.next) {
|
|
203
210
|
case 0:
|
|
211
|
+
_ref = _args3.length > 2 && _args3[2] !== undefined ? _args3[2] : {}, collectionName = _ref.collectionName, uploadId = _ref.uploadId, partNumber = _ref.partNumber;
|
|
204
212
|
metadata = {
|
|
205
213
|
method: 'PUT',
|
|
206
214
|
endpoint: '/chunk/{etag}'
|
|
207
215
|
};
|
|
208
216
|
options = _objectSpread(_objectSpread({}, metadata), {}, {
|
|
217
|
+
params: {
|
|
218
|
+
uploadId: uploadId,
|
|
219
|
+
partNumber: partNumber
|
|
220
|
+
},
|
|
209
221
|
authContext: {
|
|
210
222
|
collectionName: collectionName
|
|
211
223
|
},
|
|
212
224
|
body: blob
|
|
213
225
|
});
|
|
214
|
-
_context3.next =
|
|
226
|
+
_context3.next = 5;
|
|
215
227
|
return this.request("/chunk/".concat(etag), options);
|
|
216
228
|
|
|
217
|
-
case
|
|
229
|
+
case 5:
|
|
218
230
|
case "end":
|
|
219
231
|
return _context3.stop();
|
|
220
232
|
}
|
|
@@ -222,7 +234,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
222
234
|
}, _callee3, this);
|
|
223
235
|
}));
|
|
224
236
|
|
|
225
|
-
function uploadChunk(_x6, _x7
|
|
237
|
+
function uploadChunk(_x6, _x7) {
|
|
226
238
|
return _uploadChunk.apply(this, arguments);
|
|
227
239
|
}
|
|
228
240
|
|
|
@@ -230,13 +242,20 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
230
242
|
}()
|
|
231
243
|
}, {
|
|
232
244
|
key: "probeChunks",
|
|
233
|
-
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
|
+
|
|
234
250
|
var metadata = {
|
|
235
251
|
method: 'POST',
|
|
236
252
|
endpoint: '/chunk/probe'
|
|
237
253
|
};
|
|
238
254
|
|
|
239
255
|
var options = _objectSpread(_objectSpread({}, metadata), {}, {
|
|
256
|
+
params: {
|
|
257
|
+
uploadId: uploadId
|
|
258
|
+
},
|
|
240
259
|
authContext: {
|
|
241
260
|
collectionName: collectionName
|
|
242
261
|
},
|
|
@@ -309,13 +328,13 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
309
328
|
key: "getFileImageURL",
|
|
310
329
|
value: function () {
|
|
311
330
|
var _getFileImageURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(id, params) {
|
|
312
|
-
var
|
|
331
|
+
var _ref3, collectionName, auth;
|
|
313
332
|
|
|
314
333
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
315
334
|
while (1) {
|
|
316
335
|
switch (_context4.prev = _context4.next) {
|
|
317
336
|
case 0:
|
|
318
|
-
|
|
337
|
+
_ref3 = params || {}, collectionName = _ref3.collection;
|
|
319
338
|
_context4.next = 3;
|
|
320
339
|
return this.resolveAuth({
|
|
321
340
|
collectionName: collectionName
|
|
@@ -333,7 +352,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
333
352
|
}, _callee4, this);
|
|
334
353
|
}));
|
|
335
354
|
|
|
336
|
-
function getFileImageURL(
|
|
355
|
+
function getFileImageURL(_x8, _x9) {
|
|
337
356
|
return _getFileImageURL.apply(this, arguments);
|
|
338
357
|
}
|
|
339
358
|
|
|
@@ -388,7 +407,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
388
407
|
}, _callee5, this);
|
|
389
408
|
}));
|
|
390
409
|
|
|
391
|
-
function getFileBinaryURL(
|
|
410
|
+
function getFileBinaryURL(_x10, _x11) {
|
|
392
411
|
return _getFileBinaryURL.apply(this, arguments);
|
|
393
412
|
}
|
|
394
413
|
|
|
@@ -437,7 +456,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
437
456
|
}, _callee6, this);
|
|
438
457
|
}));
|
|
439
458
|
|
|
440
|
-
function getArtifactURL(_x13, _x14
|
|
459
|
+
function getArtifactURL(_x12, _x13, _x14) {
|
|
441
460
|
return _getArtifactURL.apply(this, arguments);
|
|
442
461
|
}
|
|
443
462
|
|
|
@@ -482,7 +501,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
482
501
|
}, _callee7, this);
|
|
483
502
|
}));
|
|
484
503
|
|
|
485
|
-
function getImage(_x16, _x17, _x18
|
|
504
|
+
function getImage(_x15, _x16, _x17, _x18) {
|
|
486
505
|
return _getImage.apply(this, arguments);
|
|
487
506
|
}
|
|
488
507
|
|
|
@@ -527,7 +546,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
527
546
|
}, _callee8, this);
|
|
528
547
|
}));
|
|
529
548
|
|
|
530
|
-
function getItems(
|
|
549
|
+
function getItems(_x19, _x20) {
|
|
531
550
|
return _getItems.apply(this, arguments);
|
|
532
551
|
}
|
|
533
552
|
|
|
@@ -562,7 +581,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
562
581
|
}, _callee9, this);
|
|
563
582
|
}));
|
|
564
583
|
|
|
565
|
-
function getImageMetadata(
|
|
584
|
+
function getImageMetadata(_x21, _x22) {
|
|
566
585
|
return _getImageMetadata.apply(this, arguments);
|
|
567
586
|
}
|
|
568
587
|
|
|
@@ -599,7 +618,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
599
618
|
}, _callee10, this);
|
|
600
619
|
}));
|
|
601
620
|
|
|
602
|
-
function appendChunksToUpload(_x24, _x25
|
|
621
|
+
function appendChunksToUpload(_x23, _x24, _x25) {
|
|
603
622
|
return _appendChunksToUpload.apply(this, arguments);
|
|
604
623
|
}
|
|
605
624
|
|
|
@@ -672,8 +691,8 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
672
691
|
|
|
673
692
|
case 8:
|
|
674
693
|
response = _context11.sent;
|
|
675
|
-
|
|
676
|
-
|
|
694
|
+
setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
|
|
695
|
+
setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
|
|
677
696
|
return _context11.abrupt("return", response);
|
|
678
697
|
|
|
679
698
|
case 12:
|
|
@@ -684,7 +703,7 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
684
703
|
}, _callee11, this);
|
|
685
704
|
}));
|
|
686
705
|
|
|
687
|
-
function request(
|
|
706
|
+
function request(_x26) {
|
|
688
707
|
return _request2.apply(this, arguments);
|
|
689
708
|
}
|
|
690
709
|
|
|
@@ -695,27 +714,25 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
695
714
|
return MediaStore;
|
|
696
715
|
}();
|
|
697
716
|
|
|
698
|
-
function
|
|
699
|
-
|
|
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)) {
|
|
700
723
|
return;
|
|
701
724
|
}
|
|
702
725
|
|
|
703
|
-
var
|
|
704
|
-
|
|
705
|
-
if (currentRegion !== region) {
|
|
706
|
-
window.sessionStorage.setItem(MEDIA_API_REGION, region);
|
|
707
|
-
}
|
|
708
|
-
}
|
|
726
|
+
var currentValue = window.sessionStorage.getItem(key);
|
|
709
727
|
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
mediaEnvironment = mediaEnv;
|
|
728
|
+
if (currentValue !== value) {
|
|
729
|
+
window.sessionStorage.setItem(key, value);
|
|
713
730
|
}
|
|
714
731
|
};
|
|
715
732
|
|
|
716
733
|
export var getMediaEnvironment = function getMediaEnvironment() {
|
|
717
|
-
return
|
|
734
|
+
return getValueFromSessionStorage(MEDIA_API_ENVIRONMENT);
|
|
718
735
|
};
|
|
719
736
|
export var getMediaRegion = function getMediaRegion() {
|
|
720
|
-
return
|
|
737
|
+
return getValueFromSessionStorage(MEDIA_API_REGION);
|
|
721
738
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
3
|
import { MediaStoreError } from './error';
|
|
4
4
|
import { rejectTimeout } from '../../utils/setTimeoutPromise';
|
|
5
5
|
export var DEFAULT_AUTH_PROVIDER_TIMEOUT = 10000;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
2
1
|
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
2
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
3
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
5
|
export var StargateClient = /*#__PURE__*/function () {
|
|
6
6
|
function StargateClient(baseUrl) {
|
|
7
7
|
_classCallCheck(this, StargateClient);
|
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
|
@@ -25,7 +25,7 @@ export { isFileIdentifier, isExternalImageIdentifier, isDifferentIdentifier } fr
|
|
|
25
25
|
export { withMediaClient, getMediaClient } from './utils/with-media-client-hoc';
|
|
26
26
|
export { globalMediaEventEmitter } from './globalMediaEventEmitter';
|
|
27
27
|
export { isMediaBlobUrl, getAttrsFromUrl, addFileAttrsToUrl, objectToQueryString } from './utils/url';
|
|
28
|
-
export { createMediaSubscribable } from './utils/
|
|
28
|
+
export { createMediaSubscribable } from './utils/mediaSubscribable';
|
|
29
29
|
export { RECENTS_COLLECTION, MAX_RESOLUTION } from './constants'; // TODO MEX-659 Remove these exports when all the usages from media-client are replaced with media-common.
|
|
30
30
|
|
|
31
31
|
import { getMediaTypeFromMimeType as _getMediaTypeFromMimeType, isImageMimeTypeSupportedByBrowser as _isImageMimeTypeSupportedByBrowser, isDocumentMimeTypeSupportedByBrowser as _isDocumentMimeTypeSupportedByBrowser, isMimeTypeSupportedByBrowser as _isMimeTypeSupportedByBrowser, isImageMimeTypeSupportedByServer as _isImageMimeTypeSupportedByServer, isDocumentMimeTypeSupportedByServer as _isDocumentMimeTypeSupportedByServer, isAudioMimeTypeSupportedByServer as _isAudioMimeTypeSupportedByServer, isVideoMimeTypeSupportedByServer as _isVideoMimeTypeSupportedByServer, isUnknownMimeTypeSupportedByServer as _isUnknownMimeTypeSupportedByServer, isMimeTypeSupportedByServer as _isMimeTypeSupportedByServer } from '@atlaskit/media-common/mediaTypeUtils';
|
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 = {}));
|