@atlaskit/media-client 36.3.0 → 36.3.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 +18 -0
- package/dist/cjs/client/file-fetcher/index.js +181 -169
- package/dist/cjs/client/media-client.js +14 -14
- package/dist/cjs/client/media-store/MediaStore.js +79 -78
- package/dist/cjs/client/media-store/resolveAuth.js +20 -19
- package/dist/cjs/client/stargate-client.js +4 -4
- package/dist/cjs/models/file-state.js +4 -2
- package/dist/cjs/uploader/index.js +28 -35
- package/dist/cjs/utils/createCopyIntentRegisterationBatcher.js +16 -16
- package/dist/cjs/utils/createFileDataLoader.js +16 -16
- package/dist/cjs/utils/getDimensionsFromBlob.js +15 -15
- package/dist/cjs/utils/getVideoDimensionsFromBlob.js +1 -1
- package/dist/cjs/utils/hashing/hasherCreator.js +18 -18
- package/dist/cjs/utils/mobileUpload/helpers.js +15 -15
- package/dist/cjs/utils/mobileUpload/stateMachine/index.js +4 -4
- package/dist/cjs/utils/polling/index.js +18 -18
- package/dist/cjs/utils/request/helpers.js +52 -49
- package/dist/cjs/utils/request/index.js +17 -16
- package/dist/cjs/utils/shouldFetchRemoteFileStates.js +18 -18
- package/dist/es2019/client/file-fetcher/index.js +12 -4
- package/dist/es2019/models/file-state.js +4 -2
- package/dist/esm/client/file-fetcher/index.js +181 -169
- package/dist/esm/client/media-client.js +14 -14
- package/dist/esm/client/media-store/MediaStore.js +79 -78
- package/dist/esm/client/media-store/resolveAuth.js +20 -19
- package/dist/esm/client/stargate-client.js +4 -4
- package/dist/esm/models/file-state.js +4 -2
- package/dist/esm/uploader/index.js +28 -35
- package/dist/esm/utils/createCopyIntentRegisterationBatcher.js +16 -16
- package/dist/esm/utils/createFileDataLoader.js +16 -16
- package/dist/esm/utils/getDimensionsFromBlob.js +15 -15
- package/dist/esm/utils/getVideoDimensionsFromBlob.js +1 -1
- package/dist/esm/utils/hashing/hasherCreator.js +17 -17
- package/dist/esm/utils/mobileUpload/helpers.js +15 -15
- package/dist/esm/utils/mobileUpload/stateMachine/index.js +4 -4
- package/dist/esm/utils/polling/index.js +18 -18
- package/dist/esm/utils/request/helpers.js +52 -49
- package/dist/esm/utils/request/index.js +17 -16
- package/dist/esm/utils/shouldFetchRemoteFileStates.js +18 -18
- package/dist/types/models/file-state.d.ts +1 -0
- package/dist/types/models/media.d.ts +2 -0
- package/dist/types-ts4.5/models/file-state.d.ts +1 -0
- package/dist/types-ts4.5/models/media.d.ts +2 -0
- package/package.json +6 -6
|
@@ -70,8 +70,8 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
70
70
|
});
|
|
71
71
|
});
|
|
72
72
|
// TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
|
|
73
|
-
_defineProperty(this, "createDownloadFileStream", function (id, collectionName, occurrenceKey, includeHashForDuplicateFiles, forceRefresh) {
|
|
74
|
-
var subject = createMediaSubject();
|
|
73
|
+
_defineProperty(this, "createDownloadFileStream", function (id, collectionName, occurrenceKey, includeHashForDuplicateFiles, forceRefresh, initialFileState) {
|
|
74
|
+
var subject = createMediaSubject(initialFileState);
|
|
75
75
|
var poll = new PollingFunction();
|
|
76
76
|
|
|
77
77
|
// ensure subject errors if polling exceeds max iterations or uncaught exception in executor
|
|
@@ -79,10 +79,17 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
79
79
|
return subject.error(error);
|
|
80
80
|
};
|
|
81
81
|
poll.execute( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
82
|
-
var response, fileState;
|
|
83
|
-
return _regeneratorRuntime.wrap(function
|
|
82
|
+
var response, fileState, _t;
|
|
83
|
+
return _regeneratorRuntime.wrap(function (_context) {
|
|
84
84
|
while (1) switch (_context.prev = _context.next) {
|
|
85
85
|
case 0:
|
|
86
|
+
if (!(!forceRefresh && (initialFileState === null || initialFileState === void 0 ? void 0 : initialFileState.status) === 'processed')) {
|
|
87
|
+
_context.next = 1;
|
|
88
|
+
break;
|
|
89
|
+
}
|
|
90
|
+
subject.complete();
|
|
91
|
+
return _context.abrupt("return");
|
|
92
|
+
case 1:
|
|
86
93
|
if (forceRefresh) {
|
|
87
94
|
_this.dataloader.clear({
|
|
88
95
|
id: id,
|
|
@@ -90,16 +97,16 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
90
97
|
includeHashForDuplicateFiles: includeHashForDuplicateFiles
|
|
91
98
|
});
|
|
92
99
|
}
|
|
93
|
-
_context.next =
|
|
100
|
+
_context.next = 2;
|
|
94
101
|
return _this.dataloader.load({
|
|
95
102
|
id: id,
|
|
96
103
|
collectionName: collectionName,
|
|
97
104
|
includeHashForDuplicateFiles: includeHashForDuplicateFiles
|
|
98
105
|
});
|
|
99
|
-
case
|
|
106
|
+
case 2:
|
|
100
107
|
response = _context.sent;
|
|
101
108
|
if (!isNotFoundMediaItemDetails(response)) {
|
|
102
|
-
_context.next =
|
|
109
|
+
_context.next = 3;
|
|
103
110
|
break;
|
|
104
111
|
}
|
|
105
112
|
throw new FileFetcherError('emptyItems', {
|
|
@@ -108,9 +115,9 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
108
115
|
occurrenceKey: occurrenceKey,
|
|
109
116
|
traceContext: response.metadataTraceContext
|
|
110
117
|
});
|
|
111
|
-
case
|
|
118
|
+
case 3:
|
|
112
119
|
if (!isEmptyFile(response)) {
|
|
113
|
-
_context.next =
|
|
120
|
+
_context.next = 4;
|
|
114
121
|
break;
|
|
115
122
|
}
|
|
116
123
|
throw new FileFetcherError('zeroVersionFile', {
|
|
@@ -119,20 +126,20 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
119
126
|
occurrenceKey: occurrenceKey,
|
|
120
127
|
traceContext: response.metadataTraceContext
|
|
121
128
|
});
|
|
122
|
-
case
|
|
129
|
+
case 4:
|
|
123
130
|
fileState = mapMediaItemToFileState(id, response);
|
|
124
131
|
subject.next(fileState);
|
|
125
|
-
|
|
126
|
-
_context.next =
|
|
132
|
+
_t = fileState.status;
|
|
133
|
+
_context.next = _t === 'processing' ? 5 : _t === 'processed' ? 6 : 7;
|
|
127
134
|
break;
|
|
128
|
-
case
|
|
135
|
+
case 5:
|
|
129
136
|
// the only case for continuing polling, otherwise this function is run once only
|
|
130
137
|
poll.next();
|
|
131
|
-
return _context.abrupt("
|
|
132
|
-
case
|
|
138
|
+
return _context.abrupt("continue", 7);
|
|
139
|
+
case 6:
|
|
133
140
|
subject.complete();
|
|
134
|
-
return _context.abrupt("
|
|
135
|
-
case
|
|
141
|
+
return _context.abrupt("continue", 7);
|
|
142
|
+
case 7:
|
|
136
143
|
case "end":
|
|
137
144
|
return _context.stop();
|
|
138
145
|
}
|
|
@@ -176,23 +183,23 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
176
183
|
_defineProperty(this, "uploadArtifact", /*#__PURE__*/function () {
|
|
177
184
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(id, file, params, collectionName, traceContext) {
|
|
178
185
|
var _yield$_this$mediaApi, data, _yield$_this$mediaApi2, altData, itemDetails;
|
|
179
|
-
return _regeneratorRuntime.wrap(function
|
|
186
|
+
return _regeneratorRuntime.wrap(function (_context2) {
|
|
180
187
|
while (1) switch (_context2.prev = _context2.next) {
|
|
181
188
|
case 0:
|
|
182
|
-
_context2.next =
|
|
189
|
+
_context2.next = 1;
|
|
183
190
|
return _this.mediaApi.uploadArtifact(id, file, params, collectionName, traceContext);
|
|
184
|
-
case
|
|
191
|
+
case 1:
|
|
185
192
|
_yield$_this$mediaApi = _context2.sent;
|
|
186
193
|
data = _yield$_this$mediaApi.data;
|
|
187
|
-
_context2.next =
|
|
194
|
+
_context2.next = 2;
|
|
188
195
|
return _this.mediaApi.getItems([id], collectionName, traceContext);
|
|
189
|
-
case
|
|
196
|
+
case 2:
|
|
190
197
|
_yield$_this$mediaApi2 = _context2.sent;
|
|
191
198
|
altData = _yield$_this$mediaApi2.data;
|
|
192
199
|
itemDetails = altData.items[0].details; // ------------------------------------------------------------
|
|
193
200
|
_this.setFileState(id, mapMediaItemToFileState(id, itemDetails));
|
|
194
201
|
return _context2.abrupt("return", data);
|
|
195
|
-
case
|
|
202
|
+
case 3:
|
|
196
203
|
case "end":
|
|
197
204
|
return _context2.stop();
|
|
198
205
|
}
|
|
@@ -205,12 +212,12 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
205
212
|
_defineProperty(this, "deleteArtifact", /*#__PURE__*/function () {
|
|
206
213
|
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(id, artifactName, collectionName, traceContext) {
|
|
207
214
|
var file, updatedArtifacts, updatedFileState;
|
|
208
|
-
return _regeneratorRuntime.wrap(function
|
|
215
|
+
return _regeneratorRuntime.wrap(function (_context3) {
|
|
209
216
|
while (1) switch (_context3.prev = _context3.next) {
|
|
210
217
|
case 0:
|
|
211
|
-
_context3.next =
|
|
218
|
+
_context3.next = 1;
|
|
212
219
|
return _this.mediaApi.deleteArtifact(id, artifactName, collectionName, traceContext);
|
|
213
|
-
case
|
|
220
|
+
case 1:
|
|
214
221
|
// Manually remove the artifact from file state instead of re-requesting the entire payload.
|
|
215
222
|
file = _this.store.getState().files[id];
|
|
216
223
|
if (file && file.status === 'processed' && file.artifacts) {
|
|
@@ -221,7 +228,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
221
228
|
});
|
|
222
229
|
_this.setFileState(id, updatedFileState);
|
|
223
230
|
}
|
|
224
|
-
case
|
|
231
|
+
case 2:
|
|
225
232
|
case "end":
|
|
226
233
|
return _context3.stop();
|
|
227
234
|
}
|
|
@@ -233,28 +240,28 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
233
240
|
}());
|
|
234
241
|
_defineProperty(this, "getOrFetchFileState", /*#__PURE__*/function () {
|
|
235
242
|
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(id, collectionName) {
|
|
236
|
-
var fileState;
|
|
237
|
-
return _regeneratorRuntime.wrap(function
|
|
243
|
+
var fileState, _t2;
|
|
244
|
+
return _regeneratorRuntime.wrap(function (_context4) {
|
|
238
245
|
while (1) switch (_context4.prev = _context4.next) {
|
|
239
246
|
case 0:
|
|
240
247
|
fileState = _this.store.getState().files[id];
|
|
241
248
|
if (!(fileState !== null && fileState !== void 0)) {
|
|
242
|
-
_context4.next =
|
|
249
|
+
_context4.next = 1;
|
|
243
250
|
break;
|
|
244
251
|
}
|
|
245
|
-
|
|
246
|
-
_context4.next =
|
|
252
|
+
_t2 = fileState;
|
|
253
|
+
_context4.next = 3;
|
|
247
254
|
break;
|
|
248
|
-
case
|
|
249
|
-
_context4.next =
|
|
255
|
+
case 1:
|
|
256
|
+
_context4.next = 2;
|
|
250
257
|
return _this.getCurrentState(id, {
|
|
251
258
|
collectionName: collectionName
|
|
252
259
|
});
|
|
253
|
-
case
|
|
254
|
-
|
|
255
|
-
case
|
|
256
|
-
return _context4.abrupt("return",
|
|
257
|
-
case
|
|
260
|
+
case 2:
|
|
261
|
+
_t2 = _context4.sent;
|
|
262
|
+
case 3:
|
|
263
|
+
return _context4.abrupt("return", _t2);
|
|
264
|
+
case 4:
|
|
258
265
|
case "end":
|
|
259
266
|
return _context4.stop();
|
|
260
267
|
}
|
|
@@ -268,109 +275,109 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
268
275
|
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(id, collectionName) {
|
|
269
276
|
var _fileState$mediaMetad;
|
|
270
277
|
var fileState, artifactUrlString, artifactUrl, artifactPath, res, arrayBuffer, uint8Array, mvhdBytes, mvhdIndex, i, j, dataView, start, timeScale, duration, videoLength;
|
|
271
|
-
return _regeneratorRuntime.wrap(function
|
|
278
|
+
return _regeneratorRuntime.wrap(function (_context5) {
|
|
272
279
|
while (1) switch (_context5.prev = _context5.next) {
|
|
273
280
|
case 0:
|
|
274
|
-
_context5.next =
|
|
281
|
+
_context5.next = 1;
|
|
275
282
|
return _this.getOrFetchFileState(id, collectionName);
|
|
276
|
-
case
|
|
283
|
+
case 1:
|
|
277
284
|
fileState = _context5.sent;
|
|
278
285
|
if (!(fileState.status !== 'processed' || fileState.mediaType !== 'video' || !fileState.artifacts['video.mp4'])) {
|
|
279
|
-
_context5.next =
|
|
286
|
+
_context5.next = 2;
|
|
280
287
|
break;
|
|
281
288
|
}
|
|
282
289
|
throw new Error('File is not a video');
|
|
283
|
-
case
|
|
290
|
+
case 2:
|
|
284
291
|
if (!('mediaMetadata' in fileState && (_fileState$mediaMetad = fileState.mediaMetadata) !== null && _fileState$mediaMetad !== void 0 && _fileState$mediaMetad.duration)) {
|
|
285
|
-
_context5.next =
|
|
292
|
+
_context5.next = 3;
|
|
286
293
|
break;
|
|
287
294
|
}
|
|
288
295
|
return _context5.abrupt("return", fileState.mediaMetadata.duration);
|
|
289
|
-
case
|
|
290
|
-
_context5.next =
|
|
296
|
+
case 3:
|
|
297
|
+
_context5.next = 4;
|
|
291
298
|
return _this.getArtifactURL(fileState.artifacts, 'video.mp4', collectionName);
|
|
292
|
-
case
|
|
299
|
+
case 4:
|
|
293
300
|
artifactUrlString = _context5.sent;
|
|
294
301
|
artifactUrl = new URL(artifactUrlString);
|
|
295
302
|
artifactPath = "".concat(artifactUrl.pathname).concat(artifactUrl.search);
|
|
296
|
-
_context5.next =
|
|
303
|
+
_context5.next = 5;
|
|
297
304
|
return _this.mediaApi.request(artifactPath, {
|
|
298
305
|
headers: {
|
|
299
306
|
Range: 'bytes=0-199'
|
|
300
307
|
}
|
|
301
308
|
});
|
|
302
|
-
case
|
|
309
|
+
case 5:
|
|
303
310
|
res = _context5.sent;
|
|
304
|
-
_context5.next =
|
|
311
|
+
_context5.next = 6;
|
|
305
312
|
return res.arrayBuffer();
|
|
306
|
-
case
|
|
313
|
+
case 6:
|
|
307
314
|
arrayBuffer = _context5.sent;
|
|
308
315
|
uint8Array = new Uint8Array(arrayBuffer);
|
|
309
316
|
mvhdBytes = new Uint8Array([109, 118, 104, 100]); // "mvhd" in ASCII
|
|
310
317
|
mvhdIndex = -1;
|
|
311
318
|
i = 0;
|
|
312
|
-
case
|
|
319
|
+
case 7:
|
|
313
320
|
if (!(i <= uint8Array.length - mvhdBytes.length)) {
|
|
314
|
-
_context5.next =
|
|
321
|
+
_context5.next = 12;
|
|
315
322
|
break;
|
|
316
323
|
}
|
|
317
324
|
mvhdIndex = i;
|
|
318
325
|
j = 0;
|
|
319
|
-
case
|
|
326
|
+
case 8:
|
|
320
327
|
if (!(j < mvhdBytes.length)) {
|
|
321
|
-
_context5.next =
|
|
328
|
+
_context5.next = 10;
|
|
322
329
|
break;
|
|
323
330
|
}
|
|
324
331
|
if (!(uint8Array[i + j] !== mvhdBytes[j])) {
|
|
325
|
-
_context5.next =
|
|
332
|
+
_context5.next = 9;
|
|
326
333
|
break;
|
|
327
334
|
}
|
|
328
335
|
mvhdIndex = -1;
|
|
329
|
-
return _context5.abrupt("
|
|
330
|
-
case
|
|
336
|
+
return _context5.abrupt("continue", 10);
|
|
337
|
+
case 9:
|
|
331
338
|
j++;
|
|
332
|
-
_context5.next =
|
|
339
|
+
_context5.next = 8;
|
|
333
340
|
break;
|
|
334
|
-
case
|
|
341
|
+
case 10:
|
|
335
342
|
if (!(mvhdIndex !== -1)) {
|
|
336
|
-
_context5.next =
|
|
343
|
+
_context5.next = 11;
|
|
337
344
|
break;
|
|
338
345
|
}
|
|
339
|
-
return _context5.abrupt("
|
|
340
|
-
case
|
|
346
|
+
return _context5.abrupt("continue", 12);
|
|
347
|
+
case 11:
|
|
341
348
|
i++;
|
|
342
|
-
_context5.next =
|
|
349
|
+
_context5.next = 7;
|
|
343
350
|
break;
|
|
344
|
-
case
|
|
351
|
+
case 12:
|
|
345
352
|
if (!(mvhdIndex === -1)) {
|
|
346
|
-
_context5.next =
|
|
353
|
+
_context5.next = 13;
|
|
347
354
|
break;
|
|
348
355
|
}
|
|
349
356
|
throw new Error('Unable to find mvhd bytes');
|
|
350
|
-
case
|
|
357
|
+
case 13:
|
|
351
358
|
// Create DataView for reading big-endian integers
|
|
352
359
|
dataView = new DataView(arrayBuffer);
|
|
353
360
|
start = mvhdIndex + 16; // Skip atom header and version/flags
|
|
354
361
|
// Check if we have enough bytes to read timescale and duration
|
|
355
362
|
if (!(start + 8 > arrayBuffer.byteLength)) {
|
|
356
|
-
_context5.next =
|
|
363
|
+
_context5.next = 14;
|
|
357
364
|
break;
|
|
358
365
|
}
|
|
359
366
|
return _context5.abrupt("return", 0);
|
|
360
|
-
case
|
|
367
|
+
case 14:
|
|
361
368
|
// flase as second parameter indicates big-endian 32-bit integers
|
|
362
369
|
timeScale = dataView.getUint32(start, false);
|
|
363
370
|
duration = dataView.getUint32(start + 4, false);
|
|
364
371
|
if (!(timeScale === 0)) {
|
|
365
|
-
_context5.next =
|
|
372
|
+
_context5.next = 15;
|
|
366
373
|
break;
|
|
367
374
|
}
|
|
368
375
|
throw new Error('Timescale is invalid');
|
|
369
|
-
case
|
|
376
|
+
case 15:
|
|
370
377
|
// get the video length in seconds
|
|
371
378
|
videoLength = Math.floor(duration / timeScale);
|
|
372
379
|
return _context5.abrupt("return", videoLength);
|
|
373
|
-
case
|
|
380
|
+
case 16:
|
|
374
381
|
case "end":
|
|
375
382
|
return _context5.stop();
|
|
376
383
|
}
|
|
@@ -383,39 +390,39 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
383
390
|
_defineProperty(this, "getVideoDurations", /*#__PURE__*/function () {
|
|
384
391
|
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(files) {
|
|
385
392
|
var promises, durations;
|
|
386
|
-
return _regeneratorRuntime.wrap(function
|
|
393
|
+
return _regeneratorRuntime.wrap(function (_context7) {
|
|
387
394
|
while (1) switch (_context7.prev = _context7.next) {
|
|
388
395
|
case 0:
|
|
389
396
|
// get all the duration promises
|
|
390
397
|
promises = files.map( /*#__PURE__*/function () {
|
|
391
398
|
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(_ref7) {
|
|
392
|
-
var id, collectionName;
|
|
393
|
-
return _regeneratorRuntime.wrap(function
|
|
399
|
+
var id, collectionName, _t3;
|
|
400
|
+
return _regeneratorRuntime.wrap(function (_context6) {
|
|
394
401
|
while (1) switch (_context6.prev = _context6.next) {
|
|
395
402
|
case 0:
|
|
396
403
|
id = _ref7.id, collectionName = _ref7.collectionName;
|
|
397
404
|
_context6.prev = 1;
|
|
398
|
-
_context6.next =
|
|
405
|
+
_context6.next = 2;
|
|
399
406
|
return _this.getDurationOfVideo(id, collectionName);
|
|
400
|
-
case
|
|
407
|
+
case 2:
|
|
401
408
|
return _context6.abrupt("return", _context6.sent);
|
|
402
|
-
case
|
|
403
|
-
_context6.prev =
|
|
404
|
-
|
|
409
|
+
case 3:
|
|
410
|
+
_context6.prev = 3;
|
|
411
|
+
_t3 = _context6["catch"](1);
|
|
405
412
|
return _context6.abrupt("return", -1);
|
|
406
|
-
case
|
|
413
|
+
case 4:
|
|
407
414
|
case "end":
|
|
408
415
|
return _context6.stop();
|
|
409
416
|
}
|
|
410
|
-
}, _callee6, null, [[1,
|
|
417
|
+
}, _callee6, null, [[1, 3]]);
|
|
411
418
|
}));
|
|
412
419
|
return function (_x13) {
|
|
413
420
|
return _ref8.apply(this, arguments);
|
|
414
421
|
};
|
|
415
422
|
}());
|
|
416
|
-
_context7.next =
|
|
423
|
+
_context7.next = 1;
|
|
417
424
|
return Promise.all(promises);
|
|
418
|
-
case
|
|
425
|
+
case 1:
|
|
419
426
|
durations = _context7.sent;
|
|
420
427
|
return _context7.abrupt("return", durations.reduce(function (acc, curr, i) {
|
|
421
428
|
if (curr !== -1) {
|
|
@@ -424,7 +431,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
424
431
|
}
|
|
425
432
|
return acc;
|
|
426
433
|
}, {}));
|
|
427
|
-
case
|
|
434
|
+
case 2:
|
|
428
435
|
case "end":
|
|
429
436
|
return _context7.stop();
|
|
430
437
|
}
|
|
@@ -447,8 +454,12 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
447
454
|
var collectionName = options.collectionName,
|
|
448
455
|
occurrenceKey = options.occurrenceKey,
|
|
449
456
|
includeHashForDuplicateFiles = options.includeHashForDuplicateFiles,
|
|
450
|
-
forceRefresh = options.forceRefresh
|
|
457
|
+
forceRefresh = options.forceRefresh,
|
|
458
|
+
initialFileState = options.initialFileState;
|
|
451
459
|
if (!isValidUuid(id)) {
|
|
460
|
+
// Do NOT pass initialFileState here — for an invalid UUID the SSR seed
|
|
461
|
+
// is meaningless and would cause subscribers to briefly see a
|
|
462
|
+
// valid-looking file state before the error is emitted.
|
|
452
463
|
var subject = createMediaSubject();
|
|
453
464
|
var err = new FileFetcherError('invalidFileId', {
|
|
454
465
|
id: id,
|
|
@@ -464,7 +475,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
464
475
|
getFileStreamsCache().remove(id);
|
|
465
476
|
}
|
|
466
477
|
return fromObservable(getFileStreamsCache().getOrInsert(id, function () {
|
|
467
|
-
var subject = _this2.createDownloadFileStream(id, collectionName, undefined, includeHashForDuplicateFiles, forceRefresh);
|
|
478
|
+
var subject = _this2.createDownloadFileStream(id, collectionName, undefined, includeHashForDuplicateFiles, forceRefresh, initialFileState);
|
|
468
479
|
subject.subscribe({
|
|
469
480
|
next: function next(fileState) {
|
|
470
481
|
_this2.setFileState(id, fileState);
|
|
@@ -531,7 +542,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
531
542
|
var _uploadExternal = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee0(url, collection, traceContext, anonymizeFilename) {
|
|
532
543
|
var _this3 = this;
|
|
533
544
|
var uploadableFileUpfrontIds, id, occurrenceKey, subject, deferredBlob, preview, name, fileState;
|
|
534
|
-
return _regeneratorRuntime.wrap(function
|
|
545
|
+
return _regeneratorRuntime.wrap(function (_context0) {
|
|
535
546
|
while (1) switch (_context0.prev = _context0.next) {
|
|
536
547
|
case 0:
|
|
537
548
|
uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
|
|
@@ -545,12 +556,12 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
545
556
|
preview = new Promise( /*#__PURE__*/function () {
|
|
546
557
|
var _ref0 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(resolve, reject) {
|
|
547
558
|
var blob;
|
|
548
|
-
return _regeneratorRuntime.wrap(function
|
|
559
|
+
return _regeneratorRuntime.wrap(function (_context8) {
|
|
549
560
|
while (1) switch (_context8.prev = _context8.next) {
|
|
550
561
|
case 0:
|
|
551
|
-
_context8.next =
|
|
562
|
+
_context8.next = 1;
|
|
552
563
|
return deferredBlob;
|
|
553
|
-
case
|
|
564
|
+
case 1:
|
|
554
565
|
blob = _context8.sent;
|
|
555
566
|
if (!blob) {
|
|
556
567
|
reject('Could not fetch the blob');
|
|
@@ -559,7 +570,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
559
570
|
value: blob,
|
|
560
571
|
origin: 'remote'
|
|
561
572
|
});
|
|
562
|
-
case
|
|
573
|
+
case 2:
|
|
563
574
|
case "end":
|
|
564
575
|
return _context8.stop();
|
|
565
576
|
}
|
|
@@ -586,20 +597,20 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
586
597
|
this.setFileState(id, fileState);
|
|
587
598
|
return _context0.abrupt("return", new Promise( /*#__PURE__*/function () {
|
|
588
599
|
var _ref1 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(resolve, reject) {
|
|
589
|
-
var blob, type, size, file, mediaType, dimensions;
|
|
590
|
-
return _regeneratorRuntime.wrap(function
|
|
600
|
+
var blob, type, size, file, mediaType, dimensions, _t4;
|
|
601
|
+
return _regeneratorRuntime.wrap(function (_context9) {
|
|
591
602
|
while (1) switch (_context9.prev = _context9.next) {
|
|
592
603
|
case 0:
|
|
593
|
-
_context9.next =
|
|
604
|
+
_context9.next = 1;
|
|
594
605
|
return deferredBlob;
|
|
595
|
-
case
|
|
606
|
+
case 1:
|
|
596
607
|
blob = _context9.sent;
|
|
597
608
|
if (blob) {
|
|
598
|
-
_context9.next =
|
|
609
|
+
_context9.next = 2;
|
|
599
610
|
break;
|
|
600
611
|
}
|
|
601
612
|
return _context9.abrupt("return", reject('Could not download remote file'));
|
|
602
|
-
case
|
|
613
|
+
case 2:
|
|
603
614
|
type = blob.type, size = blob.size;
|
|
604
615
|
file = {
|
|
605
616
|
content: blob,
|
|
@@ -621,35 +632,35 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
621
632
|
});
|
|
622
633
|
// we don't want to wait for the file to be upload
|
|
623
634
|
_this3.upload(file, undefined, uploadableFileUpfrontIds, traceContext);
|
|
624
|
-
_context9.prev =
|
|
625
|
-
_context9.next =
|
|
635
|
+
_context9.prev = 3;
|
|
636
|
+
_context9.next = 4;
|
|
626
637
|
return getDimensionsFromBlob(mediaType, blob);
|
|
627
|
-
case
|
|
638
|
+
case 4:
|
|
628
639
|
dimensions = _context9.sent;
|
|
629
|
-
_context9.next =
|
|
640
|
+
_context9.next = 6;
|
|
630
641
|
break;
|
|
631
|
-
case
|
|
632
|
-
_context9.prev =
|
|
633
|
-
|
|
634
|
-
reject(
|
|
642
|
+
case 5:
|
|
643
|
+
_context9.prev = 5;
|
|
644
|
+
_t4 = _context9["catch"](3);
|
|
645
|
+
reject(_t4);
|
|
635
646
|
return _context9.abrupt("return");
|
|
636
|
-
case
|
|
647
|
+
case 6:
|
|
637
648
|
resolve({
|
|
638
649
|
dimensions: dimensions,
|
|
639
650
|
mimeType: type,
|
|
640
651
|
uploadableFileUpfrontIds: uploadableFileUpfrontIds
|
|
641
652
|
});
|
|
642
|
-
case
|
|
653
|
+
case 7:
|
|
643
654
|
case "end":
|
|
644
655
|
return _context9.stop();
|
|
645
656
|
}
|
|
646
|
-
}, _callee9, null, [[
|
|
657
|
+
}, _callee9, null, [[3, 5]]);
|
|
647
658
|
}));
|
|
648
659
|
return function (_x20, _x21) {
|
|
649
660
|
return _ref1.apply(this, arguments);
|
|
650
661
|
};
|
|
651
662
|
}()));
|
|
652
|
-
case
|
|
663
|
+
case 1:
|
|
653
664
|
case "end":
|
|
654
665
|
return _context0.stop();
|
|
655
666
|
}
|
|
@@ -728,15 +739,15 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
728
739
|
traceContext,
|
|
729
740
|
url,
|
|
730
741
|
_args1 = arguments;
|
|
731
|
-
return _regeneratorRuntime.wrap(function
|
|
742
|
+
return _regeneratorRuntime.wrap(function (_context1) {
|
|
732
743
|
while (1) switch (_context1.prev = _context1.next) {
|
|
733
744
|
case 0:
|
|
734
745
|
name = _args1.length > 1 && _args1[1] !== undefined ? _args1[1] : 'download';
|
|
735
746
|
collectionName = _args1.length > 2 ? _args1[2] : undefined;
|
|
736
747
|
traceContext = _args1.length > 3 ? _args1[3] : undefined;
|
|
737
|
-
_context1.next =
|
|
748
|
+
_context1.next = 1;
|
|
738
749
|
return this.mediaApi.getFileBinaryURL(id, collectionName);
|
|
739
|
-
case
|
|
750
|
+
case 1:
|
|
740
751
|
url = _context1.sent;
|
|
741
752
|
downloadUrl(url, {
|
|
742
753
|
name: name
|
|
@@ -747,11 +758,11 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
747
758
|
viewingLevel: 'download'
|
|
748
759
|
});
|
|
749
760
|
// Test the download after initiated the Browser process to catch any potential errors.
|
|
750
|
-
_context1.next =
|
|
761
|
+
_context1.next = 2;
|
|
751
762
|
return this.mediaApi.testUrl(url, {
|
|
752
763
|
traceContext: traceContext
|
|
753
764
|
});
|
|
754
|
-
case
|
|
765
|
+
case 2:
|
|
755
766
|
case "end":
|
|
756
767
|
return _context1.stop();
|
|
757
768
|
}
|
|
@@ -767,26 +778,26 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
767
778
|
value: function () {
|
|
768
779
|
var _registerCopyIntent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(id, collectionName) {
|
|
769
780
|
var auth, key, error;
|
|
770
|
-
return _regeneratorRuntime.wrap(function
|
|
781
|
+
return _regeneratorRuntime.wrap(function (_context10) {
|
|
771
782
|
while (1) switch (_context10.prev = _context10.next) {
|
|
772
783
|
case 0:
|
|
773
|
-
_context10.next =
|
|
784
|
+
_context10.next = 1;
|
|
774
785
|
return this.mediaApi.resolveAuth({
|
|
775
786
|
collectionName: collectionName
|
|
776
787
|
});
|
|
777
|
-
case
|
|
788
|
+
case 1:
|
|
778
789
|
auth = _context10.sent;
|
|
779
790
|
key = {
|
|
780
791
|
id: id,
|
|
781
792
|
collectionName: collectionName,
|
|
782
793
|
resolvedAuth: auth
|
|
783
794
|
};
|
|
784
|
-
_context10.next =
|
|
795
|
+
_context10.next = 2;
|
|
785
796
|
return this.copyIntentRegisterationBatcher.load(key);
|
|
786
|
-
case
|
|
797
|
+
case 2:
|
|
787
798
|
error = _context10.sent;
|
|
788
799
|
if (!error) {
|
|
789
|
-
_context10.next =
|
|
800
|
+
_context10.next = 3;
|
|
790
801
|
break;
|
|
791
802
|
}
|
|
792
803
|
// if the error is retryable then it should not be cached
|
|
@@ -794,7 +805,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
794
805
|
this.copyIntentRegisterationBatcher.clear(key);
|
|
795
806
|
}
|
|
796
807
|
throw error;
|
|
797
|
-
case
|
|
808
|
+
case 3:
|
|
798
809
|
case "end":
|
|
799
810
|
return _context10.stop();
|
|
800
811
|
}
|
|
@@ -809,8 +820,8 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
809
820
|
key: "copyFileWithToken",
|
|
810
821
|
value: function () {
|
|
811
822
|
var _copyFileWithToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(source, destination, traceContext) {
|
|
812
|
-
var authProvider, sourceCollection, id, destinationAuthProvider, destinationCollectionName, replaceFileId, occurrenceKey, mediaStore, owner, body, params, _yield$mediaStore$cop, data;
|
|
813
|
-
return _regeneratorRuntime.wrap(function
|
|
823
|
+
var authProvider, sourceCollection, id, destinationAuthProvider, destinationCollectionName, replaceFileId, occurrenceKey, mediaStore, owner, body, params, _yield$mediaStore$cop, data, _t5;
|
|
824
|
+
return _regeneratorRuntime.wrap(function (_context11) {
|
|
814
825
|
while (1) switch (_context11.prev = _context11.next) {
|
|
815
826
|
case 0:
|
|
816
827
|
authProvider = source.authProvider, sourceCollection = source.collection, id = source.id;
|
|
@@ -818,14 +829,13 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
818
829
|
mediaStore = destination.mediaStore || new MediaApi({
|
|
819
830
|
authProvider: destinationAuthProvider
|
|
820
831
|
});
|
|
821
|
-
|
|
822
|
-
_context11.next =
|
|
832
|
+
_t5 = authToOwner;
|
|
833
|
+
_context11.next = 1;
|
|
823
834
|
return authProvider({
|
|
824
835
|
collectionName: sourceCollection
|
|
825
836
|
});
|
|
826
|
-
case
|
|
827
|
-
|
|
828
|
-
owner = (0, _context11.t0)(_context11.t1);
|
|
837
|
+
case 1:
|
|
838
|
+
owner = _t5(_context11.sent);
|
|
829
839
|
body = {
|
|
830
840
|
sourceFile: {
|
|
831
841
|
id: id,
|
|
@@ -838,13 +848,13 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
838
848
|
replaceFileId: replaceFileId,
|
|
839
849
|
occurrenceKey: occurrenceKey
|
|
840
850
|
};
|
|
841
|
-
_context11.next =
|
|
851
|
+
_context11.next = 2;
|
|
842
852
|
return mediaStore.copyFileWithToken(body, params, traceContext);
|
|
843
|
-
case
|
|
853
|
+
case 2:
|
|
844
854
|
_yield$mediaStore$cop = _context11.sent;
|
|
845
855
|
data = _yield$mediaStore$cop.data;
|
|
846
856
|
return _context11.abrupt("return", data);
|
|
847
|
-
case
|
|
857
|
+
case 3:
|
|
848
858
|
case "end":
|
|
849
859
|
return _context11.stop();
|
|
850
860
|
}
|
|
@@ -860,20 +870,20 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
860
870
|
value: function () {
|
|
861
871
|
var _copyFileWithIntent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(source, destination, traceContext) {
|
|
862
872
|
var res, data;
|
|
863
|
-
return _regeneratorRuntime.wrap(function
|
|
873
|
+
return _regeneratorRuntime.wrap(function (_context12) {
|
|
864
874
|
while (1) switch (_context12.prev = _context12.next) {
|
|
865
875
|
case 0:
|
|
866
|
-
_context12.next =
|
|
876
|
+
_context12.next = 1;
|
|
867
877
|
return this.mediaApi.copyFile(source.id, {
|
|
868
878
|
sourceCollection: source.collection,
|
|
869
879
|
collection: destination.collection,
|
|
870
880
|
replaceFileId: destination.replaceFileId
|
|
871
881
|
}, traceContext, source.clientId);
|
|
872
|
-
case
|
|
882
|
+
case 1:
|
|
873
883
|
res = _context12.sent;
|
|
874
884
|
data = res.data;
|
|
875
885
|
return _context12.abrupt("return", data);
|
|
876
|
-
case
|
|
886
|
+
case 2:
|
|
877
887
|
case "end":
|
|
878
888
|
return _context12.stop();
|
|
879
889
|
}
|
|
@@ -914,8 +924,10 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
914
924
|
replaceFileState,
|
|
915
925
|
key,
|
|
916
926
|
errorFileState,
|
|
917
|
-
_args13 = arguments
|
|
918
|
-
|
|
927
|
+
_args13 = arguments,
|
|
928
|
+
_t6,
|
|
929
|
+
_t7;
|
|
930
|
+
return _regeneratorRuntime.wrap(function (_context13) {
|
|
919
931
|
while (1) switch (_context13.prev = _context13.next) {
|
|
920
932
|
case 0:
|
|
921
933
|
options = _args13.length > 2 && _args13[2] !== undefined ? _args13[2] : {};
|
|
@@ -924,23 +936,23 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
924
936
|
destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
|
|
925
937
|
preview = options.preview, mimeType = options.mimeType;
|
|
926
938
|
cache = getFileStreamsCache();
|
|
927
|
-
_context13.prev =
|
|
939
|
+
_context13.prev = 1;
|
|
928
940
|
if (!(isCopySourceFileWithToken(source) && isCopyDestinationWithToken(destination))) {
|
|
929
|
-
_context13.next =
|
|
941
|
+
_context13.next = 3;
|
|
930
942
|
break;
|
|
931
943
|
}
|
|
932
|
-
_context13.next =
|
|
944
|
+
_context13.next = 2;
|
|
933
945
|
return this.copyFileWithToken(source, destination, traceContext);
|
|
934
|
-
case
|
|
946
|
+
case 2:
|
|
935
947
|
copiedFile = _context13.sent;
|
|
936
|
-
_context13.next =
|
|
948
|
+
_context13.next = 5;
|
|
937
949
|
break;
|
|
938
|
-
case
|
|
939
|
-
_context13.next =
|
|
950
|
+
case 3:
|
|
951
|
+
_context13.next = 4;
|
|
940
952
|
return this.copyFileWithIntent(source, destination, traceContext);
|
|
941
|
-
case
|
|
953
|
+
case 4:
|
|
942
954
|
copiedFile = _context13.sent;
|
|
943
|
-
case
|
|
955
|
+
case 5:
|
|
944
956
|
// if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
|
|
945
957
|
copiedFileWithMimeType = _objectSpread(_objectSpread({}, copiedFile), mimeType ? {
|
|
946
958
|
mimeType: mimeType
|
|
@@ -956,21 +968,21 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
956
968
|
previewOverride = !isErrorFileState(copiedFileState) && !!preview ? {
|
|
957
969
|
preview: preview
|
|
958
970
|
} : {};
|
|
959
|
-
|
|
971
|
+
_t6 = !isFinalFileState(copiedFileState) &&
|
|
960
972
|
// mimeType should always be returned by "copyFileWithToken"
|
|
961
973
|
// but in case it's not, we don't want to penalize "copyFile"
|
|
962
974
|
copiedMimeType;
|
|
963
|
-
if (!
|
|
964
|
-
_context13.next =
|
|
975
|
+
if (!_t6) {
|
|
976
|
+
_context13.next = 7;
|
|
965
977
|
break;
|
|
966
978
|
}
|
|
967
|
-
_context13.next =
|
|
979
|
+
_context13.next = 6;
|
|
968
980
|
return shouldFetchRemoteFileStates(mediaType, copiedMimeType, preview);
|
|
969
|
-
case
|
|
970
|
-
|
|
971
|
-
case
|
|
972
|
-
if (!
|
|
973
|
-
_context13.next =
|
|
981
|
+
case 6:
|
|
982
|
+
_t6 = _context13.sent;
|
|
983
|
+
case 7:
|
|
984
|
+
if (!_t6) {
|
|
985
|
+
_context13.next = 8;
|
|
974
986
|
break;
|
|
975
987
|
}
|
|
976
988
|
fileState = _objectSpread(_objectSpread(_objectSpread({}, copiedFileState), overrideMediaTypeIfUnknown(copiedFileState, mediaType)), previewOverride);
|
|
@@ -991,22 +1003,22 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
991
1003
|
return subject.complete();
|
|
992
1004
|
}
|
|
993
1005
|
});
|
|
994
|
-
_context13.next =
|
|
1006
|
+
_context13.next = 9;
|
|
995
1007
|
break;
|
|
996
|
-
case
|
|
1008
|
+
case 8:
|
|
997
1009
|
if (!isProcessingFileState(copiedFileState)) {
|
|
998
1010
|
_fileState = _objectSpread(_objectSpread({}, copiedFileState), !isErrorFileState(copiedFileState) && previewOverride);
|
|
999
1011
|
subject.next(_fileState);
|
|
1000
1012
|
this.setFileState(copiedId, _fileState);
|
|
1001
1013
|
}
|
|
1002
|
-
case
|
|
1014
|
+
case 9:
|
|
1003
1015
|
if (!cache.has(copiedId)) {
|
|
1004
1016
|
getFileStreamsCache().set(copiedId, subject);
|
|
1005
1017
|
}
|
|
1006
1018
|
return _context13.abrupt("return", copiedFile);
|
|
1007
|
-
case
|
|
1008
|
-
_context13.prev =
|
|
1009
|
-
|
|
1019
|
+
case 10:
|
|
1020
|
+
_context13.prev = 10;
|
|
1021
|
+
_t7 = _context13["catch"](1);
|
|
1010
1022
|
if (processingSubscription) {
|
|
1011
1023
|
processingSubscription.unsubscribe();
|
|
1012
1024
|
}
|
|
@@ -1014,21 +1026,21 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
1014
1026
|
_fileCache = cache.get(replaceFileId);
|
|
1015
1027
|
replaceFileState = this.store.getState().files[replaceFileId];
|
|
1016
1028
|
if (_fileCache) {
|
|
1017
|
-
_fileCache.error(
|
|
1029
|
+
_fileCache.error(_t7);
|
|
1018
1030
|
} else {
|
|
1019
1031
|
// Create a new subject with the error state for new subscriptions
|
|
1020
|
-
cache.set(id, createMediaSubject(
|
|
1032
|
+
cache.set(id, createMediaSubject(_t7));
|
|
1021
1033
|
}
|
|
1022
1034
|
key = replaceFileState ? replaceFileId : id;
|
|
1023
|
-
errorFileState = this.getErrorFileState(
|
|
1035
|
+
errorFileState = this.getErrorFileState(_t7, id, occurrenceKey);
|
|
1024
1036
|
this.setFileState(key, errorFileState);
|
|
1025
1037
|
}
|
|
1026
|
-
throw
|
|
1027
|
-
case
|
|
1038
|
+
throw _t7;
|
|
1039
|
+
case 11:
|
|
1028
1040
|
case "end":
|
|
1029
1041
|
return _context13.stop();
|
|
1030
1042
|
}
|
|
1031
|
-
}, _callee13, this, [[
|
|
1043
|
+
}, _callee13, this, [[1, 10]]);
|
|
1032
1044
|
}));
|
|
1033
1045
|
function copyFile(_x31, _x32) {
|
|
1034
1046
|
return _copyFile.apply(this, arguments);
|