@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
|
@@ -17,9 +17,9 @@ const defaultGetCollectionItems = {
|
|
|
17
17
|
limit: 30,
|
|
18
18
|
sortDirection: 'desc'
|
|
19
19
|
};
|
|
20
|
-
|
|
21
20
|
const extendImageParams = (params, fetchMaxRes = false) => {
|
|
22
|
-
return {
|
|
21
|
+
return {
|
|
22
|
+
...defaultImageOptions,
|
|
23
23
|
...params,
|
|
24
24
|
...(fetchMaxRes ? {
|
|
25
25
|
width: MAX_RESOLUTION,
|
|
@@ -27,7 +27,6 @@ const extendImageParams = (params, fetchMaxRes = false) => {
|
|
|
27
27
|
} : {})
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
|
-
|
|
31
30
|
const jsonHeaders = {
|
|
32
31
|
Accept: 'application/json',
|
|
33
32
|
'Content-Type': 'application/json'
|
|
@@ -35,23 +34,22 @@ const jsonHeaders = {
|
|
|
35
34
|
export class MediaStore {
|
|
36
35
|
constructor(config, featureFlags) {
|
|
37
36
|
_defineProperty(this, "resolveAuth", authContext => resolveAuth(this.config.authProvider, authContext));
|
|
38
|
-
|
|
39
37
|
_defineProperty(this, "resolveInitialAuth", () => resolveInitialAuth(this.config.initialAuth));
|
|
40
|
-
|
|
41
38
|
this.config = config;
|
|
42
39
|
this.featureFlags = featureFlags;
|
|
43
40
|
}
|
|
44
|
-
|
|
45
41
|
async getCollectionItems(collectionName, params, traceContext) {
|
|
46
42
|
const metadata = {
|
|
47
43
|
method: 'GET',
|
|
48
44
|
endpoint: '/collection/{collectionName}/items'
|
|
49
45
|
};
|
|
50
|
-
const options = {
|
|
46
|
+
const options = {
|
|
47
|
+
...metadata,
|
|
51
48
|
authContext: {
|
|
52
49
|
collectionName
|
|
53
50
|
},
|
|
54
|
-
params: {
|
|
51
|
+
params: {
|
|
52
|
+
...defaultGetCollectionItems,
|
|
55
53
|
...params
|
|
56
54
|
},
|
|
57
55
|
headers: {
|
|
@@ -65,9 +63,10 @@ export class MediaStore {
|
|
|
65
63
|
contents,
|
|
66
64
|
nextInclusiveStartKey
|
|
67
65
|
}
|
|
68
|
-
} = await createMapResponseToJson(metadata)(response);
|
|
69
|
-
// This prevents showing "ghost" files in recents
|
|
66
|
+
} = await createMapResponseToJson(metadata)(response);
|
|
70
67
|
|
|
68
|
+
// [TODO] MS-705: remove after backend adds filter
|
|
69
|
+
// This prevents showing "ghost" files in recents
|
|
71
70
|
const contentsWithoutEmptyFiles = contents.filter(item => item.details.size && item.details.size > 0);
|
|
72
71
|
return {
|
|
73
72
|
data: {
|
|
@@ -76,7 +75,6 @@ export class MediaStore {
|
|
|
76
75
|
}
|
|
77
76
|
};
|
|
78
77
|
}
|
|
79
|
-
|
|
80
78
|
async removeCollectionFile(id, collectionName, occurrenceKey, traceContext) {
|
|
81
79
|
const metadata = {
|
|
82
80
|
method: 'PUT',
|
|
@@ -92,7 +90,8 @@ export class MediaStore {
|
|
|
92
90
|
}
|
|
93
91
|
}]
|
|
94
92
|
};
|
|
95
|
-
const options = {
|
|
93
|
+
const options = {
|
|
94
|
+
...metadata,
|
|
96
95
|
authContext: {
|
|
97
96
|
collectionName
|
|
98
97
|
},
|
|
@@ -105,13 +104,13 @@ export class MediaStore {
|
|
|
105
104
|
};
|
|
106
105
|
await this.request(`/collection/${collectionName}`, options);
|
|
107
106
|
}
|
|
108
|
-
|
|
109
107
|
createUpload(createUpTo = 1, collectionName, traceContext) {
|
|
110
108
|
const metadata = {
|
|
111
109
|
method: 'POST',
|
|
112
110
|
endpoint: '/upload'
|
|
113
111
|
};
|
|
114
|
-
const options = {
|
|
112
|
+
const options = {
|
|
113
|
+
...metadata,
|
|
115
114
|
authContext: {
|
|
116
115
|
collectionName
|
|
117
116
|
},
|
|
@@ -125,13 +124,13 @@ export class MediaStore {
|
|
|
125
124
|
};
|
|
126
125
|
return this.request(`/upload`, options).then(createMapResponseToJson(metadata));
|
|
127
126
|
}
|
|
128
|
-
|
|
129
127
|
async uploadChunk(etag, blob, uploadId, partNumber, collectionName, traceContext) {
|
|
130
128
|
const metadata = {
|
|
131
129
|
method: 'PUT',
|
|
132
130
|
endpoint: '/chunk/{etag}'
|
|
133
131
|
};
|
|
134
|
-
const options = {
|
|
132
|
+
const options = {
|
|
133
|
+
...metadata,
|
|
135
134
|
params: {
|
|
136
135
|
uploadId,
|
|
137
136
|
partNumber
|
|
@@ -144,13 +143,13 @@ export class MediaStore {
|
|
|
144
143
|
};
|
|
145
144
|
await this.request(`/chunk/${etag}`, options);
|
|
146
145
|
}
|
|
147
|
-
|
|
148
146
|
probeChunks(chunks, uploadId, collectionName, traceContext) {
|
|
149
147
|
const metadata = {
|
|
150
148
|
method: 'POST',
|
|
151
149
|
endpoint: '/chunk/probe'
|
|
152
150
|
};
|
|
153
|
-
const options = {
|
|
151
|
+
const options = {
|
|
152
|
+
...metadata,
|
|
154
153
|
params: {
|
|
155
154
|
uploadId
|
|
156
155
|
},
|
|
@@ -165,13 +164,13 @@ export class MediaStore {
|
|
|
165
164
|
};
|
|
166
165
|
return this.request(`/chunk/probe`, options).then(createMapResponseToJson(metadata));
|
|
167
166
|
}
|
|
168
|
-
|
|
169
167
|
createFileFromUpload(body, params = {}, traceContext) {
|
|
170
168
|
const metadata = {
|
|
171
169
|
method: 'POST',
|
|
172
170
|
endpoint: '/file/upload'
|
|
173
171
|
};
|
|
174
|
-
const options = {
|
|
172
|
+
const options = {
|
|
173
|
+
...metadata,
|
|
175
174
|
authContext: {
|
|
176
175
|
collectionName: params.collection
|
|
177
176
|
},
|
|
@@ -182,13 +181,13 @@ export class MediaStore {
|
|
|
182
181
|
};
|
|
183
182
|
return this.request('/file/upload', options).then(createMapResponseToJson(metadata));
|
|
184
183
|
}
|
|
185
|
-
|
|
186
184
|
touchFiles(body, params = {}, traceContext) {
|
|
187
185
|
const metadata = {
|
|
188
186
|
method: 'POST',
|
|
189
187
|
endpoint: '/upload/createWithFiles'
|
|
190
188
|
};
|
|
191
|
-
const options = {
|
|
189
|
+
const options = {
|
|
190
|
+
...metadata,
|
|
192
191
|
authContext: {
|
|
193
192
|
collectionName: params.collection
|
|
194
193
|
},
|
|
@@ -198,13 +197,13 @@ export class MediaStore {
|
|
|
198
197
|
};
|
|
199
198
|
return this.request('/upload/createWithFiles', options).then(createMapResponseToJson(metadata));
|
|
200
199
|
}
|
|
201
|
-
|
|
202
200
|
getFile(fileId, params = {}, traceContext) {
|
|
203
201
|
const metadata = {
|
|
204
202
|
method: 'GET',
|
|
205
203
|
endpoint: '/file/{fileId}'
|
|
206
204
|
};
|
|
207
|
-
const options = {
|
|
205
|
+
const options = {
|
|
206
|
+
...metadata,
|
|
208
207
|
authContext: {
|
|
209
208
|
collectionName: params.collection
|
|
210
209
|
},
|
|
@@ -213,7 +212,6 @@ export class MediaStore {
|
|
|
213
212
|
};
|
|
214
213
|
return this.request(`/file/${fileId}`, options).then(createMapResponseToJson(metadata));
|
|
215
214
|
}
|
|
216
|
-
|
|
217
215
|
async getFileImageURL(id, params) {
|
|
218
216
|
const {
|
|
219
217
|
collection: collectionName
|
|
@@ -222,14 +220,13 @@ export class MediaStore {
|
|
|
222
220
|
collectionName
|
|
223
221
|
});
|
|
224
222
|
return this.createFileImageURL(id, auth, params);
|
|
225
|
-
}
|
|
226
|
-
|
|
223
|
+
}
|
|
227
224
|
|
|
225
|
+
// TODO Create ticket in case Trace Id can be supported through query params
|
|
228
226
|
getFileImageURLSync(id, params) {
|
|
229
227
|
const auth = this.resolveInitialAuth();
|
|
230
228
|
return this.createFileImageURL(id, auth, params);
|
|
231
229
|
}
|
|
232
|
-
|
|
233
230
|
createFileImageURL(id, auth, params) {
|
|
234
231
|
const options = {
|
|
235
232
|
params: extendImageParams(params),
|
|
@@ -237,7 +234,6 @@ export class MediaStore {
|
|
|
237
234
|
};
|
|
238
235
|
return createUrl(`${auth.baseUrl}/file/${id}/image`, options);
|
|
239
236
|
}
|
|
240
|
-
|
|
241
237
|
async getFileBinaryURL(id, collectionName) {
|
|
242
238
|
const auth = await this.resolveAuth({
|
|
243
239
|
collectionName
|
|
@@ -252,14 +248,11 @@ export class MediaStore {
|
|
|
252
248
|
};
|
|
253
249
|
return createUrl(`${auth.baseUrl}/file/${id}/binary`, options);
|
|
254
250
|
}
|
|
255
|
-
|
|
256
251
|
async getArtifactURL(artifacts, artifactName, collectionName) {
|
|
257
252
|
const artifactUrl = getArtifactUrl(artifacts, artifactName);
|
|
258
|
-
|
|
259
253
|
if (!artifactUrl) {
|
|
260
254
|
throw new Error(`artifact ${artifactName} not found`);
|
|
261
255
|
}
|
|
262
|
-
|
|
263
256
|
const auth = await this.resolveAuth({
|
|
264
257
|
collectionName
|
|
265
258
|
});
|
|
@@ -272,21 +265,19 @@ export class MediaStore {
|
|
|
272
265
|
};
|
|
273
266
|
return createUrl(`${auth.baseUrl}${artifactUrl}`, options);
|
|
274
267
|
}
|
|
275
|
-
|
|
276
268
|
async getImage(id, params, controller, fetchMaxRes, traceContext) {
|
|
277
269
|
// TODO add checkWebpSupport() back https://product-fabric.atlassian.net/browse/MPT-584
|
|
278
270
|
const isWebpSupported = false;
|
|
279
271
|
const headers = {};
|
|
280
|
-
|
|
281
272
|
if (isWebpSupported) {
|
|
282
273
|
headers.accept = 'image/webp,image/*,*/*;q=0.8';
|
|
283
274
|
}
|
|
284
|
-
|
|
285
275
|
const metadata = {
|
|
286
276
|
method: 'GET',
|
|
287
277
|
endpoint: '/file/{fileId}/image'
|
|
288
278
|
};
|
|
289
|
-
const options = {
|
|
279
|
+
const options = {
|
|
280
|
+
...metadata,
|
|
290
281
|
authContext: {
|
|
291
282
|
collectionName: params && params.collection
|
|
292
283
|
},
|
|
@@ -296,7 +287,6 @@ export class MediaStore {
|
|
|
296
287
|
};
|
|
297
288
|
return this.request(`/file/${id}/image`, options, controller).then(createMapResponseToBlob(metadata));
|
|
298
289
|
}
|
|
299
|
-
|
|
300
290
|
async getItems(ids, collectionName, traceContext) {
|
|
301
291
|
const descriptors = ids.map(id => ({
|
|
302
292
|
type: 'file',
|
|
@@ -307,7 +297,8 @@ export class MediaStore {
|
|
|
307
297
|
method: 'POST',
|
|
308
298
|
endpoint: '/items'
|
|
309
299
|
};
|
|
310
|
-
const options = {
|
|
300
|
+
const options = {
|
|
301
|
+
...metadata,
|
|
311
302
|
authContext: {
|
|
312
303
|
collectionName
|
|
313
304
|
},
|
|
@@ -319,13 +310,13 @@ export class MediaStore {
|
|
|
319
310
|
};
|
|
320
311
|
return this.request('/items', options).then(createMapResponseToJson(metadata));
|
|
321
312
|
}
|
|
322
|
-
|
|
323
313
|
async getImageMetadata(id, params, traceContext) {
|
|
324
314
|
const metadata = {
|
|
325
315
|
method: 'GET',
|
|
326
316
|
endpoint: '/file/{fileId}/image/metadata'
|
|
327
317
|
};
|
|
328
|
-
const options = {
|
|
318
|
+
const options = {
|
|
319
|
+
...metadata,
|
|
329
320
|
authContext: {
|
|
330
321
|
collectionName: params && params.collection
|
|
331
322
|
},
|
|
@@ -334,13 +325,13 @@ export class MediaStore {
|
|
|
334
325
|
};
|
|
335
326
|
return this.request(`/file/${id}/image/metadata`, options).then(createMapResponseToJson(metadata));
|
|
336
327
|
}
|
|
337
|
-
|
|
338
328
|
async appendChunksToUpload(uploadId, body, collectionName, traceContext) {
|
|
339
329
|
const metadata = {
|
|
340
330
|
method: 'PUT',
|
|
341
331
|
endpoint: '/upload/{uploadId}/chunks'
|
|
342
332
|
};
|
|
343
|
-
const options = {
|
|
333
|
+
const options = {
|
|
334
|
+
...metadata,
|
|
344
335
|
authContext: {
|
|
345
336
|
collectionName
|
|
346
337
|
},
|
|
@@ -350,13 +341,13 @@ export class MediaStore {
|
|
|
350
341
|
};
|
|
351
342
|
await this.request(`/upload/${uploadId}/chunks`, options);
|
|
352
343
|
}
|
|
353
|
-
|
|
354
344
|
copyFileWithToken(body, params, traceContext) {
|
|
355
345
|
const metadata = {
|
|
356
346
|
method: 'POST',
|
|
357
347
|
endpoint: '/file/copy/withToken'
|
|
358
348
|
};
|
|
359
|
-
const options = {
|
|
349
|
+
const options = {
|
|
350
|
+
...metadata,
|
|
360
351
|
authContext: {
|
|
361
352
|
collectionName: params.collection
|
|
362
353
|
},
|
|
@@ -370,7 +361,6 @@ export class MediaStore {
|
|
|
370
361
|
};
|
|
371
362
|
return this.request('/file/copy/withToken', options).then(createMapResponseToJson(metadata));
|
|
372
363
|
}
|
|
373
|
-
|
|
374
364
|
async request(path, options = {
|
|
375
365
|
method: 'GET',
|
|
376
366
|
endpoint: undefined,
|
|
@@ -387,7 +377,8 @@ export class MediaStore {
|
|
|
387
377
|
traceContext
|
|
388
378
|
} = options;
|
|
389
379
|
const auth = await this.resolveAuth(authContext);
|
|
390
|
-
const extendedTraceContext = traceContext ? {
|
|
380
|
+
const extendedTraceContext = traceContext ? {
|
|
381
|
+
...traceContext,
|
|
391
382
|
spanId: (traceContext === null || traceContext === void 0 ? void 0 : traceContext.spanId) || getRandomHex(8)
|
|
392
383
|
} : undefined;
|
|
393
384
|
const response = await request(`${auth.baseUrl}${path}`, {
|
|
@@ -404,25 +395,19 @@ export class MediaStore {
|
|
|
404
395
|
setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
|
|
405
396
|
return response;
|
|
406
397
|
}
|
|
407
|
-
|
|
408
398
|
}
|
|
409
|
-
|
|
410
399
|
const getValueFromSessionStorage = key => {
|
|
411
400
|
return window && window.sessionStorage && window.sessionStorage.getItem(key) || undefined;
|
|
412
401
|
};
|
|
413
|
-
|
|
414
402
|
const setKeyValueInSessionStorage = (key, value) => {
|
|
415
403
|
if (!value || !(window && window.sessionStorage)) {
|
|
416
404
|
return;
|
|
417
405
|
}
|
|
418
|
-
|
|
419
406
|
const currentValue = window.sessionStorage.getItem(key);
|
|
420
|
-
|
|
421
407
|
if (currentValue !== value) {
|
|
422
408
|
window.sessionStorage.setItem(key, value);
|
|
423
409
|
}
|
|
424
410
|
};
|
|
425
|
-
|
|
426
411
|
export const getMediaEnvironment = () => {
|
|
427
412
|
return getValueFromSessionStorage(MEDIA_API_ENVIRONMENT);
|
|
428
413
|
};
|
|
@@ -3,20 +3,18 @@ import { rejectTimeout } from '../../utils/setTimeoutPromise';
|
|
|
3
3
|
export const DEFAULT_AUTH_PROVIDER_TIMEOUT = 10000;
|
|
4
4
|
export const resolveAuth = async (authProvider, authContext, authProviderTimeout = DEFAULT_AUTH_PROVIDER_TIMEOUT) => {
|
|
5
5
|
let auth;
|
|
6
|
-
|
|
7
6
|
try {
|
|
8
7
|
auth = await Promise.race([authProvider(authContext), rejectTimeout(authProviderTimeout, new MediaStoreError('authProviderTimedOut'))]);
|
|
9
8
|
} catch (err) {
|
|
10
9
|
if (err instanceof MediaStoreError) {
|
|
11
10
|
throw err;
|
|
12
11
|
}
|
|
13
|
-
|
|
14
12
|
throw new MediaStoreError('failedAuthProvider', err instanceof Error ? err : undefined);
|
|
15
13
|
}
|
|
16
|
-
|
|
17
14
|
if (!auth) {
|
|
18
15
|
throw new MediaStoreError('emptyAuth');
|
|
19
16
|
}
|
|
17
|
+
|
|
20
18
|
/*
|
|
21
19
|
We added a token expiration check here in the past, and then we had to revert due to edge cases in the client that we can't control.
|
|
22
20
|
Token expiration check in the frontend is a bad idea. Don't do it!
|
|
@@ -25,13 +23,11 @@ export const resolveAuth = async (authProvider, authContext, authProviderTimeout
|
|
|
25
23
|
https://gist.github.com/timvisee/fcda9bbdff88d45cc9061606b4b923ca
|
|
26
24
|
*/
|
|
27
25
|
|
|
28
|
-
|
|
29
26
|
return auth;
|
|
30
27
|
};
|
|
31
28
|
export const resolveInitialAuth = auth => {
|
|
32
29
|
if (!auth) {
|
|
33
30
|
throw new MediaStoreError('missingInitialAuth');
|
|
34
31
|
}
|
|
35
|
-
|
|
36
32
|
return auth;
|
|
37
33
|
};
|
|
@@ -7,7 +7,6 @@ export class MobileUploadImpl {
|
|
|
7
7
|
this.dataloader = createFileDataloader(mediaStore);
|
|
8
8
|
this.servicesCache = createServicesCache();
|
|
9
9
|
}
|
|
10
|
-
|
|
11
10
|
notifyUploadStart(event) {
|
|
12
11
|
const {
|
|
13
12
|
fileId,
|
|
@@ -37,44 +36,37 @@ export class MobileUploadImpl {
|
|
|
37
36
|
this.servicesCache.set(fileId, service);
|
|
38
37
|
getFileStreamsCache().set(fileId, subject);
|
|
39
38
|
}
|
|
40
|
-
|
|
41
39
|
notifyUploadProgress(event) {
|
|
42
40
|
const {
|
|
43
41
|
fileId,
|
|
44
42
|
progress
|
|
45
43
|
} = event;
|
|
46
44
|
const service = this.servicesCache.get(fileId);
|
|
47
|
-
|
|
48
45
|
if (service) {
|
|
49
46
|
service.send('UPLOAD_PROGRESS', {
|
|
50
47
|
progress
|
|
51
48
|
});
|
|
52
49
|
}
|
|
53
50
|
}
|
|
54
|
-
|
|
55
51
|
notifyUploadEnd(event) {
|
|
56
52
|
const {
|
|
57
53
|
fileId
|
|
58
54
|
} = event;
|
|
59
55
|
const service = this.servicesCache.get(fileId);
|
|
60
|
-
|
|
61
56
|
if (service) {
|
|
62
57
|
service.send('UPLOAD_END');
|
|
63
58
|
}
|
|
64
59
|
}
|
|
65
|
-
|
|
66
60
|
notifyUploadError(event) {
|
|
67
61
|
const {
|
|
68
62
|
fileId,
|
|
69
63
|
message
|
|
70
64
|
} = event;
|
|
71
65
|
const service = this.servicesCache.get(fileId);
|
|
72
|
-
|
|
73
66
|
if (service) {
|
|
74
67
|
service.send('UPLOAD_ERROR', {
|
|
75
68
|
message
|
|
76
69
|
});
|
|
77
70
|
}
|
|
78
71
|
}
|
|
79
|
-
|
|
80
72
|
}
|
|
@@ -2,7 +2,6 @@ export class StargateClient {
|
|
|
2
2
|
constructor(baseUrl) {
|
|
3
3
|
this.baseUrl = baseUrl || '/gateway/api';
|
|
4
4
|
}
|
|
5
|
-
|
|
6
5
|
async fetchToken(clientId) {
|
|
7
6
|
return (await fetch(`${this.baseUrl}/media/auth/smartedge`, {
|
|
8
7
|
credentials: 'include',
|
|
@@ -11,10 +10,8 @@ export class StargateClient {
|
|
|
11
10
|
}
|
|
12
11
|
})).json();
|
|
13
12
|
}
|
|
14
|
-
|
|
15
13
|
isTokenExpired(token) {
|
|
16
14
|
const currentTimeInSeconds = new Date().getTime() / 1000;
|
|
17
15
|
return token.data.iat + token.data.expiresIn - currentTimeInSeconds < 0;
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
}
|
package/dist/es2019/constants.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { DATA_UNIT } from './models/media';
|
|
2
2
|
export const RECENTS_COLLECTION = 'recents';
|
|
3
3
|
export const FILE_CACHE_MAX_AGE = 60 * 60 * 24 * 30; // Retain for 30 days
|
|
4
|
-
|
|
5
4
|
export const MAX_RESOLUTION = 4096;
|
|
6
5
|
export const CHUNK_SIZE = 4 * DATA_UNIT.MB;
|
|
7
6
|
export const PROCESSING_BATCH_SIZE = 1000;
|
|
@@ -2,39 +2,30 @@ export class StreamsCache {
|
|
|
2
2
|
constructor(streams) {
|
|
3
3
|
this.streams = streams;
|
|
4
4
|
}
|
|
5
|
-
|
|
6
5
|
has(id) {
|
|
7
6
|
return !!this.streams.find(id);
|
|
8
7
|
}
|
|
9
|
-
|
|
10
8
|
set(id, stream) {
|
|
11
9
|
this.streams.set(id, stream);
|
|
12
10
|
}
|
|
13
|
-
|
|
14
11
|
get(id) {
|
|
15
12
|
return this.streams.get(id);
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
getOrInsert(id, callback) {
|
|
19
15
|
if (!this.has(id)) {
|
|
20
16
|
this.set(id, callback());
|
|
21
17
|
}
|
|
22
|
-
|
|
23
18
|
return this.get(id);
|
|
24
19
|
}
|
|
25
|
-
|
|
26
20
|
removeAll() {
|
|
27
21
|
this.streams.clear();
|
|
28
22
|
}
|
|
29
|
-
|
|
30
23
|
remove(id) {
|
|
31
24
|
this.streams.delete(id);
|
|
32
25
|
}
|
|
33
|
-
|
|
34
26
|
get size() {
|
|
35
27
|
return this.streams.size;
|
|
36
28
|
}
|
|
37
|
-
|
|
38
29
|
}
|
|
39
30
|
let streamCache;
|
|
40
31
|
export const getFileStreamsCache = () => {
|
|
@@ -42,9 +33,7 @@ export const getFileStreamsCache = () => {
|
|
|
42
33
|
// TODO: we can move this into a static import like
|
|
43
34
|
// import {mediaState} from '@atlaskit/media-core'
|
|
44
35
|
const mediaState = require('@atlaskit/media-core').mediaState;
|
|
45
|
-
|
|
46
36
|
streamCache = new StreamsCache(mediaState.streams);
|
|
47
37
|
}
|
|
48
|
-
|
|
49
38
|
return streamCache;
|
|
50
39
|
};
|
|
@@ -5,19 +5,15 @@ export const globalMediaEventEmitter = {
|
|
|
5
5
|
mediaState.eventEmitter.on(event, listener);
|
|
6
6
|
}
|
|
7
7
|
},
|
|
8
|
-
|
|
9
8
|
off(event, listener) {
|
|
10
9
|
if (mediaState.eventEmitter) {
|
|
11
10
|
mediaState.eventEmitter.off(event, listener);
|
|
12
11
|
}
|
|
13
12
|
},
|
|
14
|
-
|
|
15
13
|
emit(event, payload) {
|
|
16
14
|
if (mediaState.eventEmitter) {
|
|
17
15
|
return mediaState.eventEmitter.emit(event, payload);
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
return undefined;
|
|
21
18
|
}
|
|
22
|
-
|
|
23
19
|
};
|
package/dist/es2019/index.js
CHANGED
|
@@ -24,56 +24,49 @@ export { withMediaClient, getMediaClient } from './utils/with-media-client-hoc';
|
|
|
24
24
|
export { globalMediaEventEmitter } from './globalMediaEventEmitter';
|
|
25
25
|
export { isMediaBlobUrl, getAttrsFromUrl, addFileAttrsToUrl, objectToQueryString } from './utils/url';
|
|
26
26
|
export { createMediaSubscribable } from './utils/mediaSubscribable';
|
|
27
|
-
export { RECENTS_COLLECTION, MAX_RESOLUTION } from './constants';
|
|
27
|
+
export { RECENTS_COLLECTION, MAX_RESOLUTION } from './constants';
|
|
28
|
+
|
|
29
|
+
// TODO MEX-659 Remove these exports when all the usages from media-client are replaced with media-common.
|
|
28
30
|
|
|
29
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';
|
|
32
|
+
|
|
30
33
|
/**
|
|
31
34
|
* @deprecated This export will be removed. Please use one from @atlaskit/media-common or @atlaskit/media-common/mediaTypeUtils
|
|
32
35
|
*/
|
|
33
|
-
|
|
34
36
|
export const getMediaTypeFromMimeType = _getMediaTypeFromMimeType;
|
|
35
37
|
/**
|
|
36
38
|
* @deprecated This export will be removed. Please use one from @atlaskit/media-common or @atlaskit/media-common/mediaTypeUtils
|
|
37
39
|
*/
|
|
38
|
-
|
|
39
40
|
export const isImageMimeTypeSupportedByBrowser = _isImageMimeTypeSupportedByBrowser;
|
|
40
41
|
/**
|
|
41
42
|
* @deprecated This export will be removed. Please use one from @atlaskit/media-common or @atlaskit/media-common/mediaTypeUtils
|
|
42
43
|
*/
|
|
43
|
-
|
|
44
44
|
export const isDocumentMimeTypeSupportedByBrowser = _isDocumentMimeTypeSupportedByBrowser;
|
|
45
45
|
/**
|
|
46
46
|
* @deprecated This export will be removed. Please use one from @atlaskit/media-common or @atlaskit/media-common/mediaTypeUtils
|
|
47
47
|
*/
|
|
48
|
-
|
|
49
48
|
export const isMimeTypeSupportedByBrowser = _isMimeTypeSupportedByBrowser;
|
|
50
49
|
/**
|
|
51
50
|
* @deprecated This export will be removed. Please use one from @atlaskit/media-common or @atlaskit/media-common/mediaTypeUtils
|
|
52
51
|
*/
|
|
53
|
-
|
|
54
52
|
export const isImageMimeTypeSupportedByServer = _isImageMimeTypeSupportedByServer;
|
|
55
53
|
/**
|
|
56
54
|
* @deprecated This export will be removed. Please use one from @atlaskit/media-common or @atlaskit/media-common/mediaTypeUtils
|
|
57
55
|
*/
|
|
58
|
-
|
|
59
56
|
export const isDocumentMimeTypeSupportedByServer = _isDocumentMimeTypeSupportedByServer;
|
|
60
57
|
/**
|
|
61
58
|
* @deprecated This export will be removed. Please use one from @atlaskit/media-common or @atlaskit/media-common/mediaTypeUtils
|
|
62
59
|
*/
|
|
63
|
-
|
|
64
60
|
export const isAudioMimeTypeSupportedByServer = _isAudioMimeTypeSupportedByServer;
|
|
65
61
|
/**
|
|
66
62
|
* @deprecated This export will be removed. Please use one from @atlaskit/media-common or @atlaskit/media-common/mediaTypeUtils
|
|
67
63
|
*/
|
|
68
|
-
|
|
69
64
|
export const isVideoMimeTypeSupportedByServer = _isVideoMimeTypeSupportedByServer;
|
|
70
65
|
/**
|
|
71
66
|
* @deprecated This export will be removed. Please use one from @atlaskit/media-common or @atlaskit/media-common/mediaTypeUtils
|
|
72
67
|
*/
|
|
73
|
-
|
|
74
68
|
export const isUnknownMimeTypeSupportedByServer = _isUnknownMimeTypeSupportedByServer;
|
|
75
69
|
/**
|
|
76
70
|
* @deprecated This export will be removed. Please use one from @atlaskit/media-common or @atlaskit/media-common/mediaTypeUtils
|
|
77
71
|
*/
|
|
78
|
-
|
|
79
72
|
export const isMimeTypeSupportedByServer = _isMimeTypeSupportedByServer;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
export { isMediaClientError, getMediaClientErrorReason } from './helpers';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Base class for media errors
|
|
4
5
|
*/
|
|
5
|
-
|
|
6
6
|
export class BaseMediaClientError extends Error {
|
|
7
7
|
constructor(message) {
|
|
8
|
-
super(message);
|
|
8
|
+
super(message);
|
|
9
9
|
|
|
10
|
+
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-2.html#support-for-newtarget
|
|
10
11
|
this.message = message;
|
|
11
|
-
Object.setPrototypeOf(this, new.target.prototype);
|
|
12
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
12
13
|
|
|
14
|
+
// https://v8.dev/docs/stack-trace-api
|
|
13
15
|
if ('captureStackTrace' in Error) {
|
|
14
16
|
Error.captureStackTrace(this, new.target);
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
|
-
|
|
18
19
|
}
|
|
@@ -10,7 +10,6 @@ export const isImageRepresentationReady = fileState => {
|
|
|
10
10
|
case 'processed':
|
|
11
11
|
case 'failed-processing':
|
|
12
12
|
return !!(fileState.representations && fileState.representations.image);
|
|
13
|
-
|
|
14
13
|
default:
|
|
15
14
|
return false;
|
|
16
15
|
}
|
|
@@ -39,21 +38,21 @@ export const mapMediaFileToFileState = mediaFile => {
|
|
|
39
38
|
createdAt,
|
|
40
39
|
metadataTraceContext
|
|
41
40
|
};
|
|
42
|
-
|
|
43
41
|
switch (processingStatus) {
|
|
44
42
|
case 'pending':
|
|
45
43
|
case undefined:
|
|
46
|
-
return {
|
|
44
|
+
return {
|
|
45
|
+
...baseState,
|
|
47
46
|
status: 'processing'
|
|
48
47
|
};
|
|
49
|
-
|
|
50
48
|
case 'succeeded':
|
|
51
|
-
return {
|
|
49
|
+
return {
|
|
50
|
+
...baseState,
|
|
52
51
|
status: 'processed'
|
|
53
52
|
};
|
|
54
|
-
|
|
55
53
|
case 'failed':
|
|
56
|
-
return {
|
|
54
|
+
return {
|
|
55
|
+
...baseState,
|
|
57
56
|
status: 'failed-processing'
|
|
58
57
|
};
|
|
59
58
|
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { getMediaFeatureFlag } from '@atlaskit/media-common';
|
|
2
2
|
export const isPreviewableType = (type, featureFlags) => {
|
|
3
3
|
// in classic experience, only audio/video/image are previewable
|
|
4
|
-
const defaultPreviewableTypes = ['audio', 'video', 'image'];
|
|
4
|
+
const defaultPreviewableTypes = ['audio', 'video', 'image'];
|
|
5
5
|
|
|
6
|
+
// in the new experience, docs are previewable too
|
|
6
7
|
if (getMediaFeatureFlag('newCardExperience', featureFlags)) {
|
|
7
8
|
return [...defaultPreviewableTypes, 'doc'].indexOf(type) > -1;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
10
|
return defaultPreviewableTypes.indexOf(type) > -1;
|
|
11
11
|
};
|
|
12
12
|
export const isMediaCollectionItemFullDetails = mediaCollectionItem => !!mediaCollectionItem['mediaType'] && !!mediaCollectionItem['mimeType'] && !!mediaCollectionItem['processingStatus'];
|
|
13
13
|
export let DATA_UNIT;
|
|
14
|
-
|
|
15
14
|
(function (DATA_UNIT) {
|
|
16
15
|
DATA_UNIT[DATA_UNIT["MB"] = 1048576] = "MB";
|
|
17
16
|
DATA_UNIT[DATA_UNIT["GB"] = 1073741824] = "GB";
|