@atlaskit/media-client 20.0.0 → 20.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/client/collection-fetcher.js +4 -44
- package/dist/cjs/client/file-fetcher/error.js +3 -19
- package/dist/cjs/client/file-fetcher/index.js +152 -167
- package/dist/cjs/client/media-client.js +3 -27
- package/dist/cjs/client/media-store/error.js +1 -17
- package/dist/cjs/client/media-store/index.js +13 -103
- package/dist/cjs/client/media-store/resolveAuth.js +2 -23
- package/dist/cjs/client/mobile-upload.js +9 -22
- package/dist/cjs/client/stargate-client.js +0 -12
- package/dist/cjs/constants.js +0 -3
- package/dist/cjs/file-streams-cache.js +0 -11
- package/dist/cjs/globalMediaEventEmitter.js +0 -3
- package/dist/cjs/identifier.js +0 -8
- package/dist/cjs/index.js +0 -38
- package/dist/cjs/models/artifacts.js +0 -4
- package/dist/cjs/models/auth-headers.js +0 -2
- package/dist/cjs/models/auth-query-parameters.js +0 -2
- package/dist/cjs/models/errors/helpers.js +0 -2
- package/dist/cjs/models/errors/index.js +4 -20
- package/dist/cjs/models/file-state.js +10 -36
- package/dist/cjs/models/media.js +2 -8
- package/dist/cjs/upload-controller.js +0 -6
- package/dist/cjs/uploader/calculateChunkSize.js +1 -10
- package/dist/cjs/uploader/error.js +3 -19
- package/dist/cjs/uploader/index.js +3 -43
- package/dist/cjs/utils/checkWebpSupport.js +3 -7
- package/dist/cjs/utils/convertBase64ToBlob.js +0 -5
- package/dist/cjs/utils/createFileDataLoader.js +4 -28
- package/dist/cjs/utils/createMediaSubject.js +0 -4
- package/dist/cjs/utils/detectEmptyFile.js +8 -15
- package/dist/cjs/utils/getDimensionsFromBlob.js +0 -14
- package/dist/cjs/utils/getImageDimensionsFromBlob.js +0 -4
- package/dist/cjs/utils/getMediaTypeFromUploadableFile.js +0 -3
- package/dist/cjs/utils/getVideoDimensionsFromBlob.js +2 -8
- package/dist/cjs/utils/hashing/hasherCreator.js +0 -20
- package/dist/cjs/utils/hashing/simpleHasher.js +0 -12
- package/dist/cjs/utils/hashing/workerHasher.js +3 -24
- package/dist/cjs/utils/imageResizeModeToFileImageMode.js +0 -2
- package/dist/cjs/utils/isImageRemote.js +0 -5
- package/dist/cjs/utils/mediaSubscribable/fromObservable.js +2 -4
- package/dist/cjs/utils/mediaSubscribable/index.js +0 -2
- package/dist/cjs/utils/mediaSubscribable/toPromise.js +1 -3
- package/dist/cjs/utils/mobileUpload/error.js +3 -19
- package/dist/cjs/utils/mobileUpload/helpers.js +2 -26
- package/dist/cjs/utils/mobileUpload/index.js +0 -4
- package/dist/cjs/utils/mobileUpload/servicesCache.js +0 -2
- package/dist/cjs/utils/mobileUpload/stateMachine/index.js +0 -22
- package/dist/cjs/utils/mobileUpload/stateMachine/states/processing.js +0 -2
- package/dist/cjs/utils/mobileUpload/stateMachine/states/uploading.js +0 -7
- package/dist/cjs/utils/overrideMediaTypeIfUnknown.js +0 -4
- package/dist/cjs/utils/polling/errors.js +1 -17
- package/dist/cjs/utils/polling/index.js +1 -30
- package/dist/cjs/utils/request/errors.js +8 -24
- package/dist/cjs/utils/request/helpers.js +19 -103
- package/dist/cjs/utils/request/index.js +15 -26
- package/dist/cjs/utils/safeUnsubscribe.js +0 -2
- package/dist/cjs/utils/setTimeoutPromise.js +0 -4
- package/dist/cjs/utils/shouldFetchRemoteFileStates.js +0 -21
- package/dist/cjs/utils/url.js +4 -27
- package/dist/cjs/utils/with-media-client-hoc.js +12 -28
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/client/collection-fetcher.js +6 -18
- package/dist/es2019/client/file-fetcher/error.js +0 -2
- package/dist/es2019/client/file-fetcher/index.js +138 -70
- package/dist/es2019/client/media-client.js +4 -14
- package/dist/es2019/client/media-store/error.js +0 -2
- package/dist/es2019/client/media-store/index.js +37 -52
- package/dist/es2019/client/media-store/resolveAuth.js +1 -5
- package/dist/es2019/client/mobile-upload.js +0 -8
- package/dist/es2019/client/stargate-client.js +0 -3
- package/dist/es2019/constants.js +0 -1
- package/dist/es2019/file-streams-cache.js +0 -11
- package/dist/es2019/globalMediaEventEmitter.js +0 -4
- package/dist/es2019/index.js +4 -11
- package/dist/es2019/models/artifacts.js +0 -2
- package/dist/es2019/models/errors/index.js +5 -4
- package/dist/es2019/models/file-state.js +6 -7
- package/dist/es2019/models/media.js +2 -3
- package/dist/es2019/upload-controller.js +0 -3
- package/dist/es2019/uploader/calculateChunkSize.js +1 -4
- package/dist/es2019/uploader/error.js +0 -2
- package/dist/es2019/uploader/index.js +0 -13
- package/dist/es2019/utils/checkWebpSupport.js +3 -4
- package/dist/es2019/utils/convertBase64ToBlob.js +0 -2
- package/dist/es2019/utils/createFileDataLoader.js +6 -9
- package/dist/es2019/utils/createMediaSubject.js +0 -2
- package/dist/es2019/utils/detectEmptyFile.js +1 -5
- package/dist/es2019/utils/getDimensionsFromBlob.js +0 -3
- package/dist/es2019/utils/getImageDimensionsFromBlob.js +0 -2
- package/dist/es2019/utils/getVideoDimensionsFromBlob.js +2 -1
- package/dist/es2019/utils/hashing/hasherCreator.js +0 -2
- package/dist/es2019/utils/hashing/simpleHasher.js +0 -3
- package/dist/es2019/utils/hashing/workerHasher.js +1 -16
- package/dist/es2019/utils/isImageRemote.js +0 -2
- package/dist/es2019/utils/mediaSubscribable/fromObservable.js +2 -1
- package/dist/es2019/utils/mediaSubscribable/toPromise.js +1 -1
- package/dist/es2019/utils/mobileUpload/error.js +0 -2
- package/dist/es2019/utils/mobileUpload/helpers.js +2 -7
- package/dist/es2019/utils/mobileUpload/stateMachine/index.js +0 -2
- package/dist/es2019/utils/mobileUpload/stateMachine/states/uploading.js +2 -1
- package/dist/es2019/utils/overrideMediaTypeIfUnknown.js +0 -1
- package/dist/es2019/utils/polling/errors.js +0 -2
- package/dist/es2019/utils/polling/index.js +3 -20
- package/dist/es2019/utils/request/errors.js +0 -2
- package/dist/es2019/utils/request/helpers.js +24 -35
- package/dist/es2019/utils/request/index.js +2 -2
- package/dist/es2019/utils/shouldFetchRemoteFileStates.js +1 -5
- package/dist/es2019/utils/url.js +6 -14
- package/dist/es2019/utils/with-media-client-hoc.js +10 -7
- package/dist/es2019/version.json +1 -1
- package/dist/esm/client/collection-fetcher.js +4 -34
- package/dist/esm/client/file-fetcher/error.js +3 -12
- package/dist/esm/client/file-fetcher/index.js +154 -137
- package/dist/esm/client/media-client.js +4 -17
- package/dist/esm/client/media-store/error.js +1 -10
- package/dist/esm/client/media-store/index.js +13 -89
- package/dist/esm/client/media-store/resolveAuth.js +2 -13
- package/dist/esm/client/mobile-upload.js +9 -15
- package/dist/esm/client/stargate-client.js +0 -7
- package/dist/esm/constants.js +0 -1
- package/dist/esm/file-streams-cache.js +0 -6
- package/dist/esm/globalMediaEventEmitter.js +0 -1
- package/dist/esm/index.js +4 -11
- package/dist/esm/models/artifacts.js +0 -2
- package/dist/esm/models/errors/index.js +5 -12
- package/dist/esm/models/file-state.js +10 -17
- package/dist/esm/models/media.js +2 -3
- package/dist/esm/upload-controller.js +0 -2
- package/dist/esm/uploader/calculateChunkSize.js +1 -4
- package/dist/esm/uploader/error.js +3 -12
- package/dist/esm/uploader/index.js +3 -32
- package/dist/esm/utils/checkWebpSupport.js +3 -4
- package/dist/esm/utils/convertBase64ToBlob.js +0 -3
- package/dist/esm/utils/createFileDataLoader.js +4 -18
- package/dist/esm/utils/createMediaSubject.js +0 -2
- package/dist/esm/utils/detectEmptyFile.js +8 -12
- package/dist/esm/utils/getDimensionsFromBlob.js +0 -7
- package/dist/esm/utils/getImageDimensionsFromBlob.js +0 -2
- package/dist/esm/utils/getVideoDimensionsFromBlob.js +2 -3
- package/dist/esm/utils/hashing/hasherCreator.js +0 -9
- package/dist/esm/utils/hashing/simpleHasher.js +0 -4
- package/dist/esm/utils/hashing/workerHasher.js +3 -18
- package/dist/esm/utils/isImageRemote.js +0 -3
- package/dist/esm/utils/mediaSubscribable/fromObservable.js +2 -1
- package/dist/esm/utils/mediaSubscribable/toPromise.js +1 -1
- package/dist/esm/utils/mobileUpload/error.js +3 -12
- package/dist/esm/utils/mobileUpload/helpers.js +2 -11
- package/dist/esm/utils/mobileUpload/stateMachine/index.js +0 -6
- package/dist/esm/utils/mobileUpload/stateMachine/states/uploading.js +0 -3
- package/dist/esm/utils/overrideMediaTypeIfUnknown.js +0 -1
- package/dist/esm/utils/polling/errors.js +1 -10
- package/dist/esm/utils/polling/index.js +1 -27
- package/dist/esm/utils/request/errors.js +8 -17
- package/dist/esm/utils/request/helpers.js +22 -76
- package/dist/esm/utils/request/index.js +15 -20
- package/dist/esm/utils/shouldFetchRemoteFileStates.js +1 -15
- package/dist/esm/utils/url.js +4 -18
- package/dist/esm/utils/with-media-client-hoc.js +12 -17
- package/dist/esm/version.json +1 -1
- package/dist/types/client/file-fetcher/index.d.ts +6 -2
- package/package.json +8 -6
- package/report.api.md +4 -1
|
@@ -6,7 +6,6 @@ export class RequestError extends BaseMediaClientError {
|
|
|
6
6
|
this.metadata = metadata;
|
|
7
7
|
this.innerError = innerError;
|
|
8
8
|
}
|
|
9
|
-
|
|
10
9
|
get attributes() {
|
|
11
10
|
const {
|
|
12
11
|
reason,
|
|
@@ -33,7 +32,6 @@ export class RequestError extends BaseMediaClientError {
|
|
|
33
32
|
innerError
|
|
34
33
|
};
|
|
35
34
|
}
|
|
36
|
-
|
|
37
35
|
}
|
|
38
36
|
export function isRequestError(err) {
|
|
39
37
|
return err instanceof RequestError;
|
|
@@ -11,8 +11,9 @@ export function waitPromise(timeout) {
|
|
|
11
11
|
}
|
|
12
12
|
export function isAbortedRequestError(err) {
|
|
13
13
|
return err instanceof Error && err.message === 'request_cancelled' || !!err && err.name === 'AbortError';
|
|
14
|
-
}
|
|
14
|
+
}
|
|
15
15
|
|
|
16
|
+
// fetch throws TypeError for network errors
|
|
16
17
|
export function isFetchNetworkError(err) {
|
|
17
18
|
return err instanceof TypeError;
|
|
18
19
|
}
|
|
@@ -26,26 +27,22 @@ export const ZipkinHeaderKeys = {
|
|
|
26
27
|
sampled: 'x-b3-sampled',
|
|
27
28
|
flags: 'x-b3-flags'
|
|
28
29
|
};
|
|
29
|
-
|
|
30
30
|
const mapTraceIdToRequestHeaders = traceContext => {
|
|
31
31
|
return traceContext ? {
|
|
32
32
|
[ZipkinHeaderKeys.traceId]: traceContext.traceId,
|
|
33
33
|
[ZipkinHeaderKeys.spanId]: traceContext.spanId
|
|
34
34
|
} : {};
|
|
35
35
|
};
|
|
36
|
-
|
|
37
36
|
export function mapAuthToRequestHeaders(auth) {
|
|
38
37
|
if (!auth) {
|
|
39
38
|
return {};
|
|
40
39
|
}
|
|
41
|
-
|
|
42
40
|
if (isClientBasedAuth(auth)) {
|
|
43
41
|
return {
|
|
44
42
|
'X-Client-Id': auth.clientId,
|
|
45
43
|
Authorization: `Bearer ${auth.token}`
|
|
46
44
|
};
|
|
47
45
|
}
|
|
48
|
-
|
|
49
46
|
return {
|
|
50
47
|
'X-Issuer': auth.asapIssuer,
|
|
51
48
|
Authorization: `Bearer ${auth.token}`
|
|
@@ -57,7 +54,8 @@ export function createUrl(url, {
|
|
|
57
54
|
}) {
|
|
58
55
|
const parsedUrl = new URL(url);
|
|
59
56
|
const authParams = auth && mapAuthToQueryParameters(auth) || {};
|
|
60
|
-
const paramsToAppend = {
|
|
57
|
+
const paramsToAppend = {
|
|
58
|
+
...params,
|
|
61
59
|
...authParams
|
|
62
60
|
};
|
|
63
61
|
Object.entries(paramsToAppend).filter(([_, value]) => value != null).forEach(pair => {
|
|
@@ -70,21 +68,20 @@ export function extendHeaders(headers, auth, traceContext) {
|
|
|
70
68
|
if (!auth && !traceContext && !headers) {
|
|
71
69
|
return undefined;
|
|
72
70
|
}
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
return {
|
|
72
|
+
...(headers !== null && headers !== void 0 ? headers : {}),
|
|
75
73
|
...mapAuthToRequestHeaders(auth),
|
|
76
74
|
...mapTraceIdToRequestHeaders(traceContext)
|
|
77
75
|
};
|
|
78
76
|
}
|
|
77
|
+
|
|
79
78
|
/**
|
|
80
79
|
* @deprecated Helper is deprecated and will be removed in the next major version.
|
|
81
80
|
* TODO: https://product-fabric.atlassian.net/browse/BMPT-1354
|
|
82
81
|
*/
|
|
83
|
-
|
|
84
82
|
export async function mapResponseToJson(response) {
|
|
85
83
|
// eslint-disable-next-line no-console
|
|
86
84
|
console.warn('Helper is deprecated and will be remove in the next major version');
|
|
87
|
-
|
|
88
85
|
try {
|
|
89
86
|
return await response.json();
|
|
90
87
|
} catch (err) {
|
|
@@ -93,15 +90,14 @@ export async function mapResponseToJson(response) {
|
|
|
93
90
|
}, err instanceof Error ? err : undefined);
|
|
94
91
|
}
|
|
95
92
|
}
|
|
93
|
+
|
|
96
94
|
/**
|
|
97
95
|
* @deprecated Helper is deprecated and will be removed in the next major version.
|
|
98
96
|
* TODO: https://product-fabric.atlassian.net/browse/BMPT-1354
|
|
99
97
|
*/
|
|
100
|
-
|
|
101
98
|
export async function mapResponseToBlob(response) {
|
|
102
99
|
// eslint-disable-next-line no-console
|
|
103
100
|
console.warn('Helper is deprecated and will be remove in the next major version');
|
|
104
|
-
|
|
105
101
|
try {
|
|
106
102
|
return await response.blob();
|
|
107
103
|
} catch (err) {
|
|
@@ -110,11 +106,11 @@ export async function mapResponseToBlob(response) {
|
|
|
110
106
|
}, err instanceof Error ? err : undefined);
|
|
111
107
|
}
|
|
112
108
|
}
|
|
109
|
+
|
|
113
110
|
/**
|
|
114
111
|
* @deprecated Helper is deprecated and will be removed in the next major version.
|
|
115
112
|
* TODO: https://product-fabric.atlassian.net/browse/BMPT-1354
|
|
116
113
|
*/
|
|
117
|
-
|
|
118
114
|
export function mapResponseToVoid() {
|
|
119
115
|
// eslint-disable-next-line no-console
|
|
120
116
|
console.warn('Helper is deprecated and will be remove in the next major version');
|
|
@@ -125,7 +121,8 @@ export function createMapResponseToJson(metadata) {
|
|
|
125
121
|
try {
|
|
126
122
|
return await response.json();
|
|
127
123
|
} catch (err) {
|
|
128
|
-
throw new RequestError('serverInvalidBody', {
|
|
124
|
+
throw new RequestError('serverInvalidBody', {
|
|
125
|
+
...metadata,
|
|
129
126
|
...extractMediaHeaders(response),
|
|
130
127
|
statusCode: response.status
|
|
131
128
|
}, err instanceof Error ? err : undefined);
|
|
@@ -137,7 +134,8 @@ export function createMapResponseToBlob(metadata) {
|
|
|
137
134
|
try {
|
|
138
135
|
return await response.blob();
|
|
139
136
|
} catch (err) {
|
|
140
|
-
throw new RequestError('serverInvalidBody', {
|
|
137
|
+
throw new RequestError('serverInvalidBody', {
|
|
138
|
+
...metadata,
|
|
141
139
|
...extractMediaHeaders(response),
|
|
142
140
|
statusCode: response.status
|
|
143
141
|
}, err instanceof Error ? err : undefined);
|
|
@@ -150,20 +148,22 @@ export const DEFAULT_RETRY_OPTIONS = {
|
|
|
150
148
|
maxAttempts: 5,
|
|
151
149
|
// Current test delay is 60s, so retries should finish before if a promise takes < 1s
|
|
152
150
|
factor: 2 // Good for polling, which is out main use case
|
|
153
|
-
|
|
154
151
|
};
|
|
152
|
+
|
|
155
153
|
export function cloneRequestError(error, extraMetadata) {
|
|
156
154
|
const {
|
|
157
155
|
reason,
|
|
158
156
|
metadata,
|
|
159
157
|
innerError
|
|
160
158
|
} = error;
|
|
161
|
-
return new RequestError(reason, {
|
|
159
|
+
return new RequestError(reason, {
|
|
160
|
+
...metadata,
|
|
162
161
|
...extraMetadata
|
|
163
162
|
}, innerError);
|
|
164
163
|
}
|
|
165
164
|
export async function fetchRetry(functionToRetry, metadata, overwriteOptions = {}) {
|
|
166
|
-
const options = {
|
|
165
|
+
const options = {
|
|
166
|
+
...DEFAULT_RETRY_OPTIONS,
|
|
167
167
|
...overwriteOptions
|
|
168
168
|
};
|
|
169
169
|
const {
|
|
@@ -174,39 +174,35 @@ export async function fetchRetry(functionToRetry, metadata, overwriteOptions = {
|
|
|
174
174
|
let attempts = 0;
|
|
175
175
|
let timeoutInMs = startTimeoutInMs;
|
|
176
176
|
let lastError;
|
|
177
|
-
|
|
178
177
|
const waitAndBumpTimeout = async () => {
|
|
179
178
|
await waitPromise(timeoutInMs);
|
|
180
179
|
timeoutInMs *= factor;
|
|
181
180
|
attempts += 1;
|
|
182
181
|
};
|
|
183
|
-
|
|
184
182
|
while (attempts < maxAttempts) {
|
|
185
183
|
try {
|
|
186
184
|
return await functionToRetry();
|
|
187
185
|
} catch (err) {
|
|
188
|
-
lastError = err;
|
|
186
|
+
lastError = err;
|
|
189
187
|
|
|
188
|
+
// don't retry if request was aborted by user
|
|
190
189
|
if (isAbortedRequestError(err)) {
|
|
191
190
|
throw new RequestError('clientAbortedRequest', metadata, err);
|
|
192
191
|
}
|
|
193
|
-
|
|
194
192
|
if (!isFetchNetworkError(err) && !isRequestError(err) || isRequestError(err) && (!err.metadata || !err.metadata.statusCode || err.metadata.statusCode < 500)) {
|
|
195
193
|
throw err;
|
|
196
194
|
}
|
|
197
|
-
|
|
198
195
|
await waitAndBumpTimeout();
|
|
199
196
|
}
|
|
200
197
|
}
|
|
201
|
-
|
|
202
198
|
if (isRequestError(lastError)) {
|
|
203
199
|
throw cloneRequestError(lastError, {
|
|
204
200
|
attempts,
|
|
205
201
|
clientExhaustedRetries: true
|
|
206
202
|
});
|
|
207
203
|
}
|
|
208
|
-
|
|
209
|
-
|
|
204
|
+
throw new RequestError('serverUnexpectedError', {
|
|
205
|
+
...metadata,
|
|
210
206
|
attempts,
|
|
211
207
|
clientExhaustedRetries: true
|
|
212
208
|
}, lastError);
|
|
@@ -215,25 +211,18 @@ export function createRequestErrorReason(statusCode) {
|
|
|
215
211
|
switch (statusCode) {
|
|
216
212
|
case 400:
|
|
217
213
|
return 'serverBadRequest';
|
|
218
|
-
|
|
219
214
|
case 401:
|
|
220
215
|
return 'serverUnauthorized';
|
|
221
|
-
|
|
222
216
|
case 403:
|
|
223
217
|
return 'serverForbidden';
|
|
224
|
-
|
|
225
218
|
case 404:
|
|
226
219
|
return 'serverNotFound';
|
|
227
|
-
|
|
228
220
|
case 429:
|
|
229
221
|
return 'serverRateLimited';
|
|
230
|
-
|
|
231
222
|
case 500:
|
|
232
223
|
return 'serverInternalError';
|
|
233
|
-
|
|
234
224
|
case 502:
|
|
235
225
|
return 'serverBadGateway';
|
|
236
|
-
|
|
237
226
|
default:
|
|
238
227
|
return 'serverUnexpectedError';
|
|
239
228
|
}
|
|
@@ -243,7 +232,8 @@ export function createRequestErrorFromResponse(metadata, response) {
|
|
|
243
232
|
status: statusCode
|
|
244
233
|
} = response;
|
|
245
234
|
const reason = createRequestErrorReason(statusCode);
|
|
246
|
-
return new RequestError(reason, {
|
|
235
|
+
return new RequestError(reason, {
|
|
236
|
+
...metadata,
|
|
247
237
|
...extractMediaHeaders(response),
|
|
248
238
|
statusCode
|
|
249
239
|
});
|
|
@@ -253,7 +243,6 @@ export function createProcessFetchResponse(metadata) {
|
|
|
253
243
|
if (response.ok || response.status < 400) {
|
|
254
244
|
return response;
|
|
255
245
|
}
|
|
256
|
-
|
|
257
246
|
const requestError = createRequestErrorFromResponse(metadata, response);
|
|
258
247
|
throw requestError;
|
|
259
248
|
};
|
|
@@ -19,8 +19,9 @@ export async function request(url, options = {}, controller) {
|
|
|
19
19
|
method,
|
|
20
20
|
endpoint,
|
|
21
21
|
traceContext
|
|
22
|
-
};
|
|
22
|
+
};
|
|
23
23
|
|
|
24
|
+
// TODO BMPT-918: add client timeout feature behing a FF (using clientOptions.clientTimeout + Promise.race)
|
|
24
25
|
const doFetch = () => fetch(createUrl(url, {
|
|
25
26
|
params
|
|
26
27
|
}), {
|
|
@@ -29,6 +30,5 @@ export async function request(url, options = {}, controller) {
|
|
|
29
30
|
headers: extendHeaders(headers, auth, traceContext),
|
|
30
31
|
signal: controller && controller.signal
|
|
31
32
|
}).then(createProcessFetchResponse(metadata));
|
|
32
|
-
|
|
33
33
|
return fetchRetry(doFetch, metadata, retryOptions);
|
|
34
34
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { from } from 'rxjs/observable/from';
|
|
2
2
|
import { isMimeTypeSupportedByBrowser, isMimeTypeSupportedByServer } from '@atlaskit/media-common/mediaTypeUtils';
|
|
3
3
|
import { getVideoDimensionsFromBlob } from './getVideoDimensionsFromBlob';
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* Async helper determining if we should fetch remote fileStates from the backend:
|
|
6
7
|
* - we poll the backend for all supported documents,
|
|
@@ -12,19 +13,15 @@ import { getVideoDimensionsFromBlob } from './getVideoDimensionsFromBlob';
|
|
|
12
13
|
* Polling is needed for the use cases above to properly render the file in our components.
|
|
13
14
|
*
|
|
14
15
|
*/
|
|
15
|
-
|
|
16
16
|
export async function shouldFetchRemoteFileStates(mediaType, mimeType, preview) {
|
|
17
17
|
if ((mediaType === 'doc' || !isMimeTypeSupportedByBrowser(mimeType) || !preview) && isMimeTypeSupportedByServer(mimeType)) {
|
|
18
18
|
return true;
|
|
19
19
|
}
|
|
20
|
-
|
|
21
20
|
if (mediaType === 'video' && !!preview) {
|
|
22
21
|
const content = (await preview).value;
|
|
23
|
-
|
|
24
22
|
if (!(content instanceof Blob)) {
|
|
25
23
|
return false;
|
|
26
24
|
}
|
|
27
|
-
|
|
28
25
|
try {
|
|
29
26
|
const {
|
|
30
27
|
width,
|
|
@@ -37,7 +34,6 @@ export async function shouldFetchRemoteFileStates(mediaType, mimeType, preview)
|
|
|
37
34
|
return true;
|
|
38
35
|
}
|
|
39
36
|
}
|
|
40
|
-
|
|
41
37
|
return false;
|
|
42
38
|
}
|
|
43
39
|
export function shouldFetchRemoteFileStatesObservable(mediaType, mimeType, preview) {
|
package/dist/es2019/utils/url.js
CHANGED
|
@@ -2,33 +2,27 @@ const mediaBlobUrlIdentifier = 'media-blob-url';
|
|
|
2
2
|
export const isMediaBlobUrl = url => {
|
|
3
3
|
return url.indexOf(`${mediaBlobUrlIdentifier}=true`) > -1;
|
|
4
4
|
};
|
|
5
|
-
|
|
6
5
|
const getNumberFromParams = (params, name) => {
|
|
7
6
|
const value = params.get(name);
|
|
8
7
|
return typeof value === 'string' && !isNaN(parseInt(value)) ? parseInt(value) : undefined;
|
|
9
8
|
};
|
|
10
|
-
|
|
11
9
|
const getStringFromParams = (params, name) => {
|
|
12
10
|
const value = params.get(name);
|
|
13
|
-
|
|
14
11
|
if (!value) {
|
|
15
12
|
return;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
return decodeURIComponent(value);
|
|
19
15
|
};
|
|
20
|
-
|
|
21
16
|
export const getAttrsFromUrl = blobUrl => {
|
|
22
17
|
const url = new URL(blobUrl);
|
|
23
18
|
const hash = url.hash.replace('#', '');
|
|
24
19
|
const params = new URLSearchParams(hash);
|
|
25
20
|
const id = params.get('id');
|
|
26
|
-
const contextId = params.get('contextId');
|
|
27
|
-
|
|
21
|
+
const contextId = params.get('contextId');
|
|
22
|
+
// check if we have the required params
|
|
28
23
|
if (!id || !contextId) {
|
|
29
24
|
return;
|
|
30
25
|
}
|
|
31
|
-
|
|
32
26
|
return {
|
|
33
27
|
id,
|
|
34
28
|
contextId,
|
|
@@ -44,28 +38,26 @@ export const getAttrsFromUrl = blobUrl => {
|
|
|
44
38
|
export const objectToQueryString = json => {
|
|
45
39
|
return Object.keys(json).filter(attrName => typeof json[attrName] !== 'undefined' && json[attrName] !== null).map(key => {
|
|
46
40
|
const value = json[key];
|
|
47
|
-
|
|
48
41
|
if (typeof value === 'undefined' || value === null) {
|
|
49
42
|
return;
|
|
50
43
|
}
|
|
51
|
-
|
|
52
44
|
return `${encodeURIComponent(key)}=${encodeURIComponent(value.toString())}`;
|
|
53
45
|
}).join('&');
|
|
54
46
|
};
|
|
55
47
|
export const addFileAttrsToUrl = (url, fileAttrs) => {
|
|
56
48
|
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent);
|
|
57
|
-
|
|
58
49
|
if (isSafari) {
|
|
59
50
|
return url;
|
|
60
51
|
}
|
|
61
|
-
|
|
62
52
|
const mediaIdentifierAttr = {
|
|
63
53
|
[mediaBlobUrlIdentifier]: 'true'
|
|
64
54
|
};
|
|
65
|
-
const mergedAttrs = {
|
|
55
|
+
const mergedAttrs = {
|
|
56
|
+
...mediaIdentifierAttr,
|
|
66
57
|
...fileAttrs
|
|
67
58
|
};
|
|
68
|
-
const queryAttrs = objectToQueryString(mergedAttrs);
|
|
59
|
+
const queryAttrs = objectToQueryString(mergedAttrs);
|
|
69
60
|
|
|
61
|
+
// we can't use '?' separator for blob url params
|
|
70
62
|
return `${url}#${queryAttrs}`;
|
|
71
63
|
};
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import { MediaClient } from '../client/media-client';
|
|
4
|
+
const NO_FLAGS = 'NO_FLAGS';
|
|
4
5
|
const mediaClientsMap = new Map();
|
|
5
6
|
export const getMediaClient = (mediaClientConfig, featureFlags) => {
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
var _mediaClientsMap$get;
|
|
8
|
+
const flagsMapKey = featureFlags || NO_FLAGS;
|
|
9
|
+
let mediaClient = (_mediaClientsMap$get = mediaClientsMap.get(mediaClientConfig)) === null || _mediaClientsMap$get === void 0 ? void 0 : _mediaClientsMap$get.get(flagsMapKey);
|
|
8
10
|
if (!mediaClient) {
|
|
11
|
+
let subMap = mediaClientsMap.get(mediaClientConfig);
|
|
12
|
+
if (!subMap) {
|
|
13
|
+
subMap = new Map();
|
|
14
|
+
mediaClientsMap.set(mediaClientConfig, subMap);
|
|
15
|
+
}
|
|
9
16
|
mediaClient = new MediaClient(mediaClientConfig, featureFlags);
|
|
10
|
-
|
|
17
|
+
subMap.set(flagsMapKey, mediaClient);
|
|
11
18
|
}
|
|
12
|
-
|
|
13
19
|
return mediaClient;
|
|
14
20
|
};
|
|
15
|
-
|
|
16
21
|
const createEmptyMediaClient = featureFlags => {
|
|
17
22
|
const emptyConfig = {
|
|
18
23
|
authProvider: () => Promise.resolve({
|
|
@@ -23,7 +28,6 @@ const createEmptyMediaClient = featureFlags => {
|
|
|
23
28
|
};
|
|
24
29
|
return new MediaClient(emptyConfig, featureFlags);
|
|
25
30
|
};
|
|
26
|
-
|
|
27
31
|
export const withMediaClient = (Component, featureFlags) => {
|
|
28
32
|
return class extends React.Component {
|
|
29
33
|
render() {
|
|
@@ -37,6 +41,5 @@ export const withMediaClient = (Component, featureFlags) => {
|
|
|
37
41
|
mediaClient: mediaClient
|
|
38
42
|
}));
|
|
39
43
|
}
|
|
40
|
-
|
|
41
44
|
};
|
|
42
45
|
};
|
package/dist/es2019/version.json
CHANGED
|
@@ -4,17 +4,13 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
4
4
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
5
5
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
6
6
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
7
|
-
|
|
8
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; }
|
|
9
|
-
|
|
10
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; }
|
|
11
|
-
|
|
12
9
|
import { ReplaySubject } from 'rxjs/ReplaySubject';
|
|
13
10
|
import { getFileStreamsCache } from '../file-streams-cache';
|
|
14
11
|
import { mapMediaFileToFileState } from '../models/file-state';
|
|
15
12
|
import { fromObservable } from '../utils/mediaSubscribable';
|
|
16
13
|
export var collectionCache = {};
|
|
17
|
-
|
|
18
14
|
var createCacheEntry = function createCacheEntry() {
|
|
19
15
|
return {
|
|
20
16
|
items: [],
|
|
@@ -22,23 +18,18 @@ var createCacheEntry = function createCacheEntry() {
|
|
|
22
18
|
isLoadingNextPage: false
|
|
23
19
|
};
|
|
24
20
|
};
|
|
25
|
-
|
|
26
21
|
export var CollectionFetcher = /*#__PURE__*/function () {
|
|
27
22
|
function CollectionFetcher(mediaStore) {
|
|
28
23
|
_classCallCheck(this, CollectionFetcher);
|
|
29
|
-
|
|
30
24
|
this.mediaStore = mediaStore;
|
|
31
25
|
}
|
|
32
|
-
|
|
33
26
|
_createClass(CollectionFetcher, [{
|
|
34
27
|
key: "createFileStateObserver",
|
|
35
28
|
value: function createFileStateObserver(id, details) {
|
|
36
29
|
var subject = new ReplaySubject(1);
|
|
37
|
-
|
|
38
30
|
var mediaFile = _objectSpread({
|
|
39
31
|
id: id
|
|
40
32
|
}, details);
|
|
41
|
-
|
|
42
33
|
var fileState = mapMediaFileToFileState({
|
|
43
34
|
data: mediaFile
|
|
44
35
|
});
|
|
@@ -49,10 +40,8 @@ export var CollectionFetcher = /*#__PURE__*/function () {
|
|
|
49
40
|
key: "populateCache",
|
|
50
41
|
value: function populateCache(items) {
|
|
51
42
|
var _this = this;
|
|
52
|
-
|
|
53
43
|
items.forEach(function (item) {
|
|
54
44
|
var fileStream = _this.createFileStateObserver(item.id, item.details);
|
|
55
|
-
|
|
56
45
|
getFileStreamsCache().set(item.id, fileStream);
|
|
57
46
|
});
|
|
58
47
|
}
|
|
@@ -62,11 +51,9 @@ export var CollectionFetcher = /*#__PURE__*/function () {
|
|
|
62
51
|
var collectionCacheIndex = collectionCache[collectionName].items.findIndex(function (item) {
|
|
63
52
|
return item.id === id;
|
|
64
53
|
});
|
|
65
|
-
|
|
66
54
|
if (collectionCacheIndex === -1) {
|
|
67
55
|
return;
|
|
68
56
|
}
|
|
69
|
-
|
|
70
57
|
getFileStreamsCache().remove(id);
|
|
71
58
|
collectionCache[collectionName].items.splice(collectionCacheIndex, 1);
|
|
72
59
|
}
|
|
@@ -74,24 +61,20 @@ export var CollectionFetcher = /*#__PURE__*/function () {
|
|
|
74
61
|
key: "getItems",
|
|
75
62
|
value: function getItems(collectionName, params, traceContext) {
|
|
76
63
|
var _this2 = this;
|
|
77
|
-
|
|
78
64
|
if (!collectionCache[collectionName]) {
|
|
79
65
|
collectionCache[collectionName] = createCacheEntry();
|
|
80
66
|
}
|
|
81
|
-
|
|
82
67
|
var collection = collectionCache[collectionName];
|
|
83
68
|
var subject = collection.subject;
|
|
84
69
|
this.mediaStore.getCollectionItems(collectionName, _objectSpread(_objectSpread({}, params), {}, {
|
|
85
70
|
details: 'full'
|
|
86
71
|
}), traceContext).then(function (items) {
|
|
87
72
|
var _items$data = items.data,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
73
|
+
contents = _items$data.contents,
|
|
74
|
+
nextInclusiveStartKey = _items$data.nextInclusiveStartKey;
|
|
75
|
+
_this2.populateCache(contents);
|
|
76
|
+
// It's hard to merge two together, so we just take what's came from the server.
|
|
92
77
|
// Since we load only one page > 2 pages will be ditched from the cache.
|
|
93
|
-
|
|
94
|
-
|
|
95
78
|
collection.items = items.data.contents;
|
|
96
79
|
collection.nextInclusiveStartKey = nextInclusiveStartKey;
|
|
97
80
|
subject.next(collection.items);
|
|
@@ -111,12 +94,10 @@ export var CollectionFetcher = /*#__PURE__*/function () {
|
|
|
111
94
|
case 0:
|
|
112
95
|
_context.next = 2;
|
|
113
96
|
return this.mediaStore.removeCollectionFile(id, collectionName, occurrenceKey, traceContext);
|
|
114
|
-
|
|
115
97
|
case 2:
|
|
116
98
|
this.removeFromCache(id, collectionName);
|
|
117
99
|
collection = collectionCache[collectionName];
|
|
118
100
|
collection.subject.next(collection.items);
|
|
119
|
-
|
|
120
101
|
case 5:
|
|
121
102
|
case "end":
|
|
122
103
|
return _context.stop();
|
|
@@ -124,11 +105,9 @@ export var CollectionFetcher = /*#__PURE__*/function () {
|
|
|
124
105
|
}
|
|
125
106
|
}, _callee, this);
|
|
126
107
|
}));
|
|
127
|
-
|
|
128
108
|
function removeFile(_x, _x2, _x3, _x4) {
|
|
129
109
|
return _removeFile.apply(this, arguments);
|
|
130
110
|
}
|
|
131
|
-
|
|
132
111
|
return removeFile;
|
|
133
112
|
}()
|
|
134
113
|
}, {
|
|
@@ -136,21 +115,17 @@ export var CollectionFetcher = /*#__PURE__*/function () {
|
|
|
136
115
|
value: function () {
|
|
137
116
|
var _loadNextPage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(collectionName, params, traceContext) {
|
|
138
117
|
var collection, isLoading, _collectionCache$coll, inclusiveStartKey, currentItems, subject, response, _response$data, contents, nextInclusiveStartKey, newItems, items;
|
|
139
|
-
|
|
140
118
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
141
119
|
while (1) {
|
|
142
120
|
switch (_context2.prev = _context2.next) {
|
|
143
121
|
case 0:
|
|
144
122
|
collection = collectionCache[collectionName];
|
|
145
123
|
isLoading = collection ? collection.isLoadingNextPage : false;
|
|
146
|
-
|
|
147
124
|
if (!(!collection || !collection.nextInclusiveStartKey || isLoading)) {
|
|
148
125
|
_context2.next = 4;
|
|
149
126
|
break;
|
|
150
127
|
}
|
|
151
|
-
|
|
152
128
|
return _context2.abrupt("return");
|
|
153
|
-
|
|
154
129
|
case 4:
|
|
155
130
|
collection.isLoadingNextPage = true;
|
|
156
131
|
_collectionCache$coll = collectionCache[collectionName], inclusiveStartKey = _collectionCache$coll.nextInclusiveStartKey, currentItems = _collectionCache$coll.items, subject = _collectionCache$coll.subject;
|
|
@@ -159,7 +134,6 @@ export var CollectionFetcher = /*#__PURE__*/function () {
|
|
|
159
134
|
inclusiveStartKey: inclusiveStartKey,
|
|
160
135
|
details: 'full'
|
|
161
136
|
}), traceContext);
|
|
162
|
-
|
|
163
137
|
case 8:
|
|
164
138
|
response = _context2.sent;
|
|
165
139
|
_response$data = response.data, contents = _response$data.contents, nextInclusiveStartKey = _response$data.nextInclusiveStartKey;
|
|
@@ -173,7 +147,6 @@ export var CollectionFetcher = /*#__PURE__*/function () {
|
|
|
173
147
|
subject: subject,
|
|
174
148
|
isLoadingNextPage: false
|
|
175
149
|
};
|
|
176
|
-
|
|
177
150
|
case 15:
|
|
178
151
|
case "end":
|
|
179
152
|
return _context2.stop();
|
|
@@ -181,14 +154,11 @@ export var CollectionFetcher = /*#__PURE__*/function () {
|
|
|
181
154
|
}
|
|
182
155
|
}, _callee2, this);
|
|
183
156
|
}));
|
|
184
|
-
|
|
185
157
|
function loadNextPage(_x5, _x6, _x7) {
|
|
186
158
|
return _loadNextPage.apply(this, arguments);
|
|
187
159
|
}
|
|
188
|
-
|
|
189
160
|
return loadNextPage;
|
|
190
161
|
}()
|
|
191
162
|
}]);
|
|
192
|
-
|
|
193
163
|
return CollectionFetcher;
|
|
194
164
|
}();
|
|
@@ -3,38 +3,30 @@ import _createClass from "@babel/runtime/helpers/createClass";
|
|
|
3
3
|
import _inherits from "@babel/runtime/helpers/inherits";
|
|
4
4
|
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
5
5
|
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
|
-
|
|
7
6
|
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
7
|
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
8
|
import { BaseMediaClientError } from '../../models/errors';
|
|
12
9
|
export var FileFetcherError = /*#__PURE__*/function (_BaseMediaClientError) {
|
|
13
10
|
_inherits(FileFetcherError, _BaseMediaClientError);
|
|
14
|
-
|
|
15
11
|
var _super = _createSuper(FileFetcherError);
|
|
16
|
-
|
|
17
12
|
function FileFetcherError(reason, id, metadata) {
|
|
18
13
|
var _this;
|
|
19
|
-
|
|
20
14
|
_classCallCheck(this, FileFetcherError);
|
|
21
|
-
|
|
22
15
|
_this = _super.call(this, reason);
|
|
23
16
|
_this.reason = reason;
|
|
24
17
|
_this.id = id;
|
|
25
18
|
_this.metadata = metadata;
|
|
26
19
|
return _this;
|
|
27
20
|
}
|
|
28
|
-
|
|
29
21
|
_createClass(FileFetcherError, [{
|
|
30
22
|
key: "attributes",
|
|
31
23
|
get: function get() {
|
|
32
24
|
var reason = this.reason,
|
|
33
|
-
|
|
34
|
-
|
|
25
|
+
id = this.id,
|
|
26
|
+
_this$metadata = this.metadata;
|
|
35
27
|
_this$metadata = _this$metadata === void 0 ? {} : _this$metadata;
|
|
36
28
|
var collectionName = _this$metadata.collectionName,
|
|
37
|
-
|
|
29
|
+
occurrenceKey = _this$metadata.occurrenceKey;
|
|
38
30
|
return {
|
|
39
31
|
reason: reason,
|
|
40
32
|
id: id,
|
|
@@ -43,7 +35,6 @@ export var FileFetcherError = /*#__PURE__*/function (_BaseMediaClientError) {
|
|
|
43
35
|
};
|
|
44
36
|
}
|
|
45
37
|
}]);
|
|
46
|
-
|
|
47
38
|
return FileFetcherError;
|
|
48
39
|
}(BaseMediaClientError);
|
|
49
40
|
export function isFileFetcherError(err) {
|