@atlaskit/media-client 33.1.1 → 33.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/dist/cjs/client/file-fetcher/index.js +311 -116
- package/dist/es2019/client/file-fetcher/index.js +84 -0
- package/dist/esm/client/file-fetcher/index.js +311 -116
- package/dist/types/client/file-fetcher/index.d.ts +13 -0
- package/dist/types-ts4.5/client/file-fetcher/index.d.ts +13 -0
- package/package.json +1 -1
|
@@ -58,8 +58,8 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
58
58
|
var err = new CommonMediaClientError(error);
|
|
59
59
|
return fromCommonMediaClientError(id, occurrenceKey, err);
|
|
60
60
|
} else {
|
|
61
|
-
var
|
|
62
|
-
return fromCommonMediaClientError(id, occurrenceKey,
|
|
61
|
+
var _err2 = new CommonMediaClientError((error === null || error === void 0 ? void 0 : error.reason) || 'unknown', error === null || error === void 0 ? void 0 : error.metadata, error === null || error === void 0 ? void 0 : error.innerError);
|
|
62
|
+
return fromCommonMediaClientError(id, occurrenceKey, _err2);
|
|
63
63
|
}
|
|
64
64
|
});
|
|
65
65
|
_defineProperty(this, "setFileState", function (id, fileState) {
|
|
@@ -200,6 +200,201 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
200
200
|
return _ref2.apply(this, arguments);
|
|
201
201
|
};
|
|
202
202
|
}());
|
|
203
|
+
_defineProperty(this, "getOrFetchFileState", /*#__PURE__*/function () {
|
|
204
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(id, collectionName) {
|
|
205
|
+
var fileState;
|
|
206
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
207
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
208
|
+
case 0:
|
|
209
|
+
fileState = _this.store.getState().files[id];
|
|
210
|
+
if (!(fileState !== null && fileState !== void 0)) {
|
|
211
|
+
_context3.next = 5;
|
|
212
|
+
break;
|
|
213
|
+
}
|
|
214
|
+
_context3.t0 = fileState;
|
|
215
|
+
_context3.next = 8;
|
|
216
|
+
break;
|
|
217
|
+
case 5:
|
|
218
|
+
_context3.next = 7;
|
|
219
|
+
return _this.getCurrentState(id, {
|
|
220
|
+
collectionName: collectionName
|
|
221
|
+
});
|
|
222
|
+
case 7:
|
|
223
|
+
_context3.t0 = _context3.sent;
|
|
224
|
+
case 8:
|
|
225
|
+
return _context3.abrupt("return", _context3.t0);
|
|
226
|
+
case 9:
|
|
227
|
+
case "end":
|
|
228
|
+
return _context3.stop();
|
|
229
|
+
}
|
|
230
|
+
}, _callee3);
|
|
231
|
+
}));
|
|
232
|
+
return function (_x6, _x7) {
|
|
233
|
+
return _ref3.apply(this, arguments);
|
|
234
|
+
};
|
|
235
|
+
}());
|
|
236
|
+
_defineProperty(this, "getDurationOfVideo", /*#__PURE__*/function () {
|
|
237
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(id, collectionName) {
|
|
238
|
+
var fileState, aritfactUrl, artifactPath, res, arrayBuffer, uint8Array, mvhdBytes, mvhdIndex, i, j, dataView, start, timeScale, duration, videoLength;
|
|
239
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
240
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
241
|
+
case 0:
|
|
242
|
+
_context4.next = 2;
|
|
243
|
+
return _this.getOrFetchFileState(id, collectionName);
|
|
244
|
+
case 2:
|
|
245
|
+
fileState = _context4.sent;
|
|
246
|
+
if (!(fileState.status !== "processed" || fileState.mediaType !== "video" || !fileState.artifacts["video.mp4"])) {
|
|
247
|
+
_context4.next = 5;
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
throw new Error("File is not a video");
|
|
251
|
+
case 5:
|
|
252
|
+
_context4.next = 7;
|
|
253
|
+
return _this.getArtifactURL(fileState.artifacts, "video.mp4");
|
|
254
|
+
case 7:
|
|
255
|
+
aritfactUrl = _context4.sent;
|
|
256
|
+
artifactPath = new URL(aritfactUrl).pathname;
|
|
257
|
+
_context4.next = 11;
|
|
258
|
+
return _this.mediaApi.request(artifactPath, {
|
|
259
|
+
headers: {
|
|
260
|
+
Range: "bytes=0-199"
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
case 11:
|
|
264
|
+
res = _context4.sent;
|
|
265
|
+
_context4.next = 14;
|
|
266
|
+
return res.arrayBuffer();
|
|
267
|
+
case 14:
|
|
268
|
+
arrayBuffer = _context4.sent;
|
|
269
|
+
uint8Array = new Uint8Array(arrayBuffer);
|
|
270
|
+
mvhdBytes = new Uint8Array([109, 118, 104, 100]); // "mvhd" in ASCII
|
|
271
|
+
mvhdIndex = -1;
|
|
272
|
+
i = 0;
|
|
273
|
+
case 19:
|
|
274
|
+
if (!(i <= uint8Array.length - mvhdBytes.length)) {
|
|
275
|
+
_context4.next = 34;
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
mvhdIndex = i;
|
|
279
|
+
j = 0;
|
|
280
|
+
case 22:
|
|
281
|
+
if (!(j < mvhdBytes.length)) {
|
|
282
|
+
_context4.next = 29;
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
if (!(uint8Array[i + j] !== mvhdBytes[j])) {
|
|
286
|
+
_context4.next = 26;
|
|
287
|
+
break;
|
|
288
|
+
}
|
|
289
|
+
mvhdIndex = -1;
|
|
290
|
+
return _context4.abrupt("break", 29);
|
|
291
|
+
case 26:
|
|
292
|
+
j++;
|
|
293
|
+
_context4.next = 22;
|
|
294
|
+
break;
|
|
295
|
+
case 29:
|
|
296
|
+
if (!(mvhdIndex !== -1)) {
|
|
297
|
+
_context4.next = 31;
|
|
298
|
+
break;
|
|
299
|
+
}
|
|
300
|
+
return _context4.abrupt("break", 34);
|
|
301
|
+
case 31:
|
|
302
|
+
i++;
|
|
303
|
+
_context4.next = 19;
|
|
304
|
+
break;
|
|
305
|
+
case 34:
|
|
306
|
+
if (!(mvhdIndex === -1)) {
|
|
307
|
+
_context4.next = 36;
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
throw new Error("Unable to find mvhd bytes");
|
|
311
|
+
case 36:
|
|
312
|
+
// Create DataView for reading big-endian integers
|
|
313
|
+
dataView = new DataView(arrayBuffer);
|
|
314
|
+
start = mvhdIndex + 16; // Skip atom header and version/flags
|
|
315
|
+
// Check if we have enough bytes to read timescale and duration
|
|
316
|
+
if (!(start + 8 > arrayBuffer.byteLength)) {
|
|
317
|
+
_context4.next = 40;
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
return _context4.abrupt("return", 0);
|
|
321
|
+
case 40:
|
|
322
|
+
// flase as second parameter indicates big-endian 32-bit integers
|
|
323
|
+
timeScale = dataView.getUint32(start, false);
|
|
324
|
+
duration = dataView.getUint32(start + 4, false);
|
|
325
|
+
if (!(timeScale === 0)) {
|
|
326
|
+
_context4.next = 44;
|
|
327
|
+
break;
|
|
328
|
+
}
|
|
329
|
+
throw new Error("Timescale is invalid");
|
|
330
|
+
case 44:
|
|
331
|
+
// get the video length in seconds
|
|
332
|
+
videoLength = Math.floor(duration / timeScale);
|
|
333
|
+
return _context4.abrupt("return", videoLength);
|
|
334
|
+
case 46:
|
|
335
|
+
case "end":
|
|
336
|
+
return _context4.stop();
|
|
337
|
+
}
|
|
338
|
+
}, _callee4);
|
|
339
|
+
}));
|
|
340
|
+
return function (_x8, _x9) {
|
|
341
|
+
return _ref4.apply(this, arguments);
|
|
342
|
+
};
|
|
343
|
+
}());
|
|
344
|
+
_defineProperty(this, "getVideoDurations", /*#__PURE__*/function () {
|
|
345
|
+
var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(files) {
|
|
346
|
+
var promises, durations;
|
|
347
|
+
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
348
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
349
|
+
case 0:
|
|
350
|
+
// get all the duration promises
|
|
351
|
+
promises = files.map( /*#__PURE__*/function () {
|
|
352
|
+
var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(_ref6) {
|
|
353
|
+
var id, collectionName;
|
|
354
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
355
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
356
|
+
case 0:
|
|
357
|
+
id = _ref6.id, collectionName = _ref6.collectionName;
|
|
358
|
+
_context5.prev = 1;
|
|
359
|
+
_context5.next = 4;
|
|
360
|
+
return _this.getDurationOfVideo(id, collectionName);
|
|
361
|
+
case 4:
|
|
362
|
+
return _context5.abrupt("return", _context5.sent);
|
|
363
|
+
case 7:
|
|
364
|
+
_context5.prev = 7;
|
|
365
|
+
_context5.t0 = _context5["catch"](1);
|
|
366
|
+
return _context5.abrupt("return", -1);
|
|
367
|
+
case 10:
|
|
368
|
+
case "end":
|
|
369
|
+
return _context5.stop();
|
|
370
|
+
}
|
|
371
|
+
}, _callee5, null, [[1, 7]]);
|
|
372
|
+
}));
|
|
373
|
+
return function (_x11) {
|
|
374
|
+
return _ref7.apply(this, arguments);
|
|
375
|
+
};
|
|
376
|
+
}());
|
|
377
|
+
_context6.next = 3;
|
|
378
|
+
return Promise.all(promises);
|
|
379
|
+
case 3:
|
|
380
|
+
durations = _context6.sent;
|
|
381
|
+
return _context6.abrupt("return", durations.reduce(function (acc, curr, i) {
|
|
382
|
+
if (curr !== -1) {
|
|
383
|
+
var _id = files[i].id;
|
|
384
|
+
acc[_id] = curr;
|
|
385
|
+
}
|
|
386
|
+
return acc;
|
|
387
|
+
}, {}));
|
|
388
|
+
case 5:
|
|
389
|
+
case "end":
|
|
390
|
+
return _context6.stop();
|
|
391
|
+
}
|
|
392
|
+
}, _callee6);
|
|
393
|
+
}));
|
|
394
|
+
return function (_x10) {
|
|
395
|
+
return _ref5.apply(this, arguments);
|
|
396
|
+
};
|
|
397
|
+
}());
|
|
203
398
|
this.mediaApi = mediaApi;
|
|
204
399
|
this.store = store;
|
|
205
400
|
this.dataloader = createFileDataloader(mediaApi);
|
|
@@ -265,8 +460,8 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
265
460
|
descriptors: descriptors
|
|
266
461
|
}, {
|
|
267
462
|
collection: collection
|
|
268
|
-
}, traceContext).then(function (
|
|
269
|
-
var data =
|
|
463
|
+
}, traceContext).then(function (_ref8) {
|
|
464
|
+
var data = _ref8.data;
|
|
270
465
|
return data;
|
|
271
466
|
});
|
|
272
467
|
}
|
|
@@ -292,11 +487,11 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
292
487
|
}, {
|
|
293
488
|
key: "uploadExternal",
|
|
294
489
|
value: function () {
|
|
295
|
-
var _uploadExternal = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
490
|
+
var _uploadExternal = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9(url, collection, traceContext) {
|
|
296
491
|
var _this3 = this;
|
|
297
492
|
var uploadableFileUpfrontIds, id, occurrenceKey, subject, deferredBlob, preview, name, fileState;
|
|
298
|
-
return _regeneratorRuntime.wrap(function
|
|
299
|
-
while (1) switch (
|
|
493
|
+
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
494
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
300
495
|
case 0:
|
|
301
496
|
uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
|
|
302
497
|
id = uploadableFileUpfrontIds.id, occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
|
|
@@ -307,15 +502,15 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
307
502
|
return undefined;
|
|
308
503
|
});
|
|
309
504
|
preview = new Promise( /*#__PURE__*/function () {
|
|
310
|
-
var
|
|
505
|
+
var _ref9 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(resolve, reject) {
|
|
311
506
|
var blob;
|
|
312
|
-
return _regeneratorRuntime.wrap(function
|
|
313
|
-
while (1) switch (
|
|
507
|
+
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
508
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
314
509
|
case 0:
|
|
315
|
-
|
|
510
|
+
_context7.next = 2;
|
|
316
511
|
return deferredBlob;
|
|
317
512
|
case 2:
|
|
318
|
-
blob =
|
|
513
|
+
blob = _context7.sent;
|
|
319
514
|
if (!blob) {
|
|
320
515
|
reject('Could not fetch the blob');
|
|
321
516
|
}
|
|
@@ -325,12 +520,12 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
325
520
|
});
|
|
326
521
|
case 5:
|
|
327
522
|
case "end":
|
|
328
|
-
return
|
|
523
|
+
return _context7.stop();
|
|
329
524
|
}
|
|
330
|
-
},
|
|
525
|
+
}, _callee7);
|
|
331
526
|
}));
|
|
332
|
-
return function (
|
|
333
|
-
return
|
|
527
|
+
return function (_x15, _x16) {
|
|
528
|
+
return _ref9.apply(this, arguments);
|
|
334
529
|
};
|
|
335
530
|
}());
|
|
336
531
|
name = url.split('/').pop() || ''; // we create a initial fileState with the minimum info that we have at this point
|
|
@@ -348,21 +543,21 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
348
543
|
// we save it into the cache as soon as possible, in case someone subscribes
|
|
349
544
|
getFileStreamsCache().set(id, subject);
|
|
350
545
|
this.setFileState(id, fileState);
|
|
351
|
-
return
|
|
352
|
-
var
|
|
546
|
+
return _context9.abrupt("return", new Promise( /*#__PURE__*/function () {
|
|
547
|
+
var _ref10 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8(resolve, reject) {
|
|
353
548
|
var blob, type, size, file, mediaType, dimensions;
|
|
354
|
-
return _regeneratorRuntime.wrap(function
|
|
355
|
-
while (1) switch (
|
|
549
|
+
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
550
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
356
551
|
case 0:
|
|
357
|
-
|
|
552
|
+
_context8.next = 2;
|
|
358
553
|
return deferredBlob;
|
|
359
554
|
case 2:
|
|
360
|
-
blob =
|
|
555
|
+
blob = _context8.sent;
|
|
361
556
|
if (blob) {
|
|
362
|
-
|
|
557
|
+
_context8.next = 5;
|
|
363
558
|
break;
|
|
364
559
|
}
|
|
365
|
-
return
|
|
560
|
+
return _context8.abrupt("return", reject('Could not download remote file'));
|
|
366
561
|
case 5:
|
|
367
562
|
type = blob.type, size = blob.size;
|
|
368
563
|
file = {
|
|
@@ -385,18 +580,18 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
385
580
|
});
|
|
386
581
|
// we don't want to wait for the file to be upload
|
|
387
582
|
_this3.upload(file, undefined, uploadableFileUpfrontIds, traceContext);
|
|
388
|
-
|
|
389
|
-
|
|
583
|
+
_context8.prev = 10;
|
|
584
|
+
_context8.next = 13;
|
|
390
585
|
return getDimensionsFromBlob(mediaType, blob);
|
|
391
586
|
case 13:
|
|
392
|
-
dimensions =
|
|
393
|
-
|
|
587
|
+
dimensions = _context8.sent;
|
|
588
|
+
_context8.next = 20;
|
|
394
589
|
break;
|
|
395
590
|
case 16:
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
reject(
|
|
399
|
-
return
|
|
591
|
+
_context8.prev = 16;
|
|
592
|
+
_context8.t0 = _context8["catch"](10);
|
|
593
|
+
reject(_context8.t0);
|
|
594
|
+
return _context8.abrupt("return");
|
|
400
595
|
case 20:
|
|
401
596
|
resolve({
|
|
402
597
|
dimensions: dimensions,
|
|
@@ -405,21 +600,21 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
405
600
|
});
|
|
406
601
|
case 21:
|
|
407
602
|
case "end":
|
|
408
|
-
return
|
|
603
|
+
return _context8.stop();
|
|
409
604
|
}
|
|
410
|
-
},
|
|
605
|
+
}, _callee8, null, [[10, 16]]);
|
|
411
606
|
}));
|
|
412
|
-
return function (
|
|
413
|
-
return
|
|
607
|
+
return function (_x17, _x18) {
|
|
608
|
+
return _ref10.apply(this, arguments);
|
|
414
609
|
};
|
|
415
610
|
}()));
|
|
416
611
|
case 11:
|
|
417
612
|
case "end":
|
|
418
|
-
return
|
|
613
|
+
return _context9.stop();
|
|
419
614
|
}
|
|
420
|
-
},
|
|
615
|
+
}, _callee9, this);
|
|
421
616
|
}));
|
|
422
|
-
function uploadExternal(
|
|
617
|
+
function uploadExternal(_x12, _x13, _x14) {
|
|
423
618
|
return _uploadExternal.apply(this, arguments);
|
|
424
619
|
}
|
|
425
620
|
return uploadExternal;
|
|
@@ -486,22 +681,22 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
486
681
|
}, {
|
|
487
682
|
key: "downloadBinary",
|
|
488
683
|
value: function () {
|
|
489
|
-
var _downloadBinary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
684
|
+
var _downloadBinary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(id) {
|
|
490
685
|
var name,
|
|
491
686
|
collectionName,
|
|
492
687
|
traceContext,
|
|
493
688
|
url,
|
|
494
|
-
|
|
495
|
-
return _regeneratorRuntime.wrap(function
|
|
496
|
-
while (1) switch (
|
|
689
|
+
_args10 = arguments;
|
|
690
|
+
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
691
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
497
692
|
case 0:
|
|
498
|
-
name =
|
|
499
|
-
collectionName =
|
|
500
|
-
traceContext =
|
|
501
|
-
|
|
693
|
+
name = _args10.length > 1 && _args10[1] !== undefined ? _args10[1] : 'download';
|
|
694
|
+
collectionName = _args10.length > 2 ? _args10[2] : undefined;
|
|
695
|
+
traceContext = _args10.length > 3 ? _args10[3] : undefined;
|
|
696
|
+
_context10.next = 5;
|
|
502
697
|
return this.mediaApi.getFileBinaryURL(id, collectionName);
|
|
503
698
|
case 5:
|
|
504
|
-
url =
|
|
699
|
+
url = _context10.sent;
|
|
505
700
|
downloadUrl(url, {
|
|
506
701
|
name: name
|
|
507
702
|
});
|
|
@@ -511,17 +706,17 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
511
706
|
viewingLevel: 'download'
|
|
512
707
|
});
|
|
513
708
|
// Test the download after initiated the Browser process to catch any potential errors.
|
|
514
|
-
|
|
709
|
+
_context10.next = 10;
|
|
515
710
|
return this.mediaApi.testUrl(url, {
|
|
516
711
|
traceContext: traceContext
|
|
517
712
|
});
|
|
518
713
|
case 10:
|
|
519
714
|
case "end":
|
|
520
|
-
return
|
|
715
|
+
return _context10.stop();
|
|
521
716
|
}
|
|
522
|
-
},
|
|
717
|
+
}, _callee10, this);
|
|
523
718
|
}));
|
|
524
|
-
function downloadBinary(
|
|
719
|
+
function downloadBinary(_x19) {
|
|
525
720
|
return _downloadBinary.apply(this, arguments);
|
|
526
721
|
}
|
|
527
722
|
return downloadBinary;
|
|
@@ -529,28 +724,28 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
529
724
|
}, {
|
|
530
725
|
key: "registerCopyIntent",
|
|
531
726
|
value: function () {
|
|
532
|
-
var _registerCopyIntent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
727
|
+
var _registerCopyIntent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(id, collectionName) {
|
|
533
728
|
var auth, key, error;
|
|
534
|
-
return _regeneratorRuntime.wrap(function
|
|
535
|
-
while (1) switch (
|
|
729
|
+
return _regeneratorRuntime.wrap(function _callee11$(_context11) {
|
|
730
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
536
731
|
case 0:
|
|
537
|
-
|
|
732
|
+
_context11.next = 2;
|
|
538
733
|
return this.mediaApi.resolveAuth({
|
|
539
734
|
collectionName: collectionName
|
|
540
735
|
});
|
|
541
736
|
case 2:
|
|
542
|
-
auth =
|
|
737
|
+
auth = _context11.sent;
|
|
543
738
|
key = {
|
|
544
739
|
id: id,
|
|
545
740
|
collectionName: collectionName,
|
|
546
741
|
resolvedAuth: auth
|
|
547
742
|
};
|
|
548
|
-
|
|
743
|
+
_context11.next = 6;
|
|
549
744
|
return this.copyIntentRegisterationBatcher.load(key);
|
|
550
745
|
case 6:
|
|
551
|
-
error =
|
|
746
|
+
error = _context11.sent;
|
|
552
747
|
if (!error) {
|
|
553
|
-
|
|
748
|
+
_context11.next = 10;
|
|
554
749
|
break;
|
|
555
750
|
}
|
|
556
751
|
// if the error is retryable then it should not be cached
|
|
@@ -560,11 +755,11 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
560
755
|
throw error;
|
|
561
756
|
case 10:
|
|
562
757
|
case "end":
|
|
563
|
-
return
|
|
758
|
+
return _context11.stop();
|
|
564
759
|
}
|
|
565
|
-
},
|
|
760
|
+
}, _callee11, this);
|
|
566
761
|
}));
|
|
567
|
-
function registerCopyIntent(
|
|
762
|
+
function registerCopyIntent(_x20, _x21) {
|
|
568
763
|
return _registerCopyIntent.apply(this, arguments);
|
|
569
764
|
}
|
|
570
765
|
return registerCopyIntent;
|
|
@@ -572,24 +767,24 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
572
767
|
}, {
|
|
573
768
|
key: "copyFileWithToken",
|
|
574
769
|
value: function () {
|
|
575
|
-
var _copyFileWithToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
770
|
+
var _copyFileWithToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(source, destination, traceContext) {
|
|
576
771
|
var authProvider, sourceCollection, id, destinationAuthProvider, destinationCollectionName, replaceFileId, occurrenceKey, mediaStore, owner, body, params, _yield$mediaStore$cop, data;
|
|
577
|
-
return _regeneratorRuntime.wrap(function
|
|
578
|
-
while (1) switch (
|
|
772
|
+
return _regeneratorRuntime.wrap(function _callee12$(_context12) {
|
|
773
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
579
774
|
case 0:
|
|
580
775
|
authProvider = source.authProvider, sourceCollection = source.collection, id = source.id;
|
|
581
776
|
destinationAuthProvider = destination.authProvider, destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
|
|
582
777
|
mediaStore = destination.mediaStore || new MediaApi({
|
|
583
778
|
authProvider: destinationAuthProvider
|
|
584
779
|
});
|
|
585
|
-
|
|
586
|
-
|
|
780
|
+
_context12.t0 = authToOwner;
|
|
781
|
+
_context12.next = 6;
|
|
587
782
|
return authProvider({
|
|
588
783
|
collectionName: sourceCollection
|
|
589
784
|
});
|
|
590
785
|
case 6:
|
|
591
|
-
|
|
592
|
-
owner = (0,
|
|
786
|
+
_context12.t1 = _context12.sent;
|
|
787
|
+
owner = (0, _context12.t0)(_context12.t1);
|
|
593
788
|
body = {
|
|
594
789
|
sourceFile: {
|
|
595
790
|
id: id,
|
|
@@ -602,19 +797,19 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
602
797
|
replaceFileId: replaceFileId,
|
|
603
798
|
occurrenceKey: occurrenceKey
|
|
604
799
|
};
|
|
605
|
-
|
|
800
|
+
_context12.next = 12;
|
|
606
801
|
return mediaStore.copyFileWithToken(body, params, traceContext);
|
|
607
802
|
case 12:
|
|
608
|
-
_yield$mediaStore$cop =
|
|
803
|
+
_yield$mediaStore$cop = _context12.sent;
|
|
609
804
|
data = _yield$mediaStore$cop.data;
|
|
610
|
-
return
|
|
805
|
+
return _context12.abrupt("return", data);
|
|
611
806
|
case 15:
|
|
612
807
|
case "end":
|
|
613
|
-
return
|
|
808
|
+
return _context12.stop();
|
|
614
809
|
}
|
|
615
|
-
},
|
|
810
|
+
}, _callee12);
|
|
616
811
|
}));
|
|
617
|
-
function copyFileWithToken(
|
|
812
|
+
function copyFileWithToken(_x22, _x23, _x24) {
|
|
618
813
|
return _copyFileWithToken.apply(this, arguments);
|
|
619
814
|
}
|
|
620
815
|
return copyFileWithToken;
|
|
@@ -622,28 +817,28 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
622
817
|
}, {
|
|
623
818
|
key: "copyFileWithIntent",
|
|
624
819
|
value: function () {
|
|
625
|
-
var _copyFileWithIntent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
820
|
+
var _copyFileWithIntent = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(source, destination, traceContext) {
|
|
626
821
|
var res, data;
|
|
627
|
-
return _regeneratorRuntime.wrap(function
|
|
628
|
-
while (1) switch (
|
|
822
|
+
return _regeneratorRuntime.wrap(function _callee13$(_context13) {
|
|
823
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
629
824
|
case 0:
|
|
630
|
-
|
|
825
|
+
_context13.next = 2;
|
|
631
826
|
return this.mediaApi.copyFile(source.id, {
|
|
632
827
|
sourceCollection: source.collection,
|
|
633
828
|
collection: destination.collection,
|
|
634
829
|
replaceFileId: destination.replaceFileId
|
|
635
830
|
}, traceContext);
|
|
636
831
|
case 2:
|
|
637
|
-
res =
|
|
832
|
+
res = _context13.sent;
|
|
638
833
|
data = res.data;
|
|
639
|
-
return
|
|
834
|
+
return _context13.abrupt("return", data);
|
|
640
835
|
case 5:
|
|
641
836
|
case "end":
|
|
642
|
-
return
|
|
837
|
+
return _context13.stop();
|
|
643
838
|
}
|
|
644
|
-
},
|
|
839
|
+
}, _callee13, this);
|
|
645
840
|
}));
|
|
646
|
-
function copyFileWithIntent(
|
|
841
|
+
function copyFileWithIntent(_x25, _x26, _x27) {
|
|
647
842
|
return _copyFileWithIntent.apply(this, arguments);
|
|
648
843
|
}
|
|
649
844
|
return copyFileWithIntent;
|
|
@@ -651,7 +846,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
651
846
|
}, {
|
|
652
847
|
key: "copyFile",
|
|
653
848
|
value: function () {
|
|
654
|
-
var _copyFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
849
|
+
var _copyFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14(source, destination) {
|
|
655
850
|
var _this5 = this;
|
|
656
851
|
var options,
|
|
657
852
|
traceContext,
|
|
@@ -678,32 +873,32 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
678
873
|
replaceFileState,
|
|
679
874
|
key,
|
|
680
875
|
errorFileState,
|
|
681
|
-
|
|
682
|
-
return _regeneratorRuntime.wrap(function
|
|
683
|
-
while (1) switch (
|
|
876
|
+
_args14 = arguments;
|
|
877
|
+
return _regeneratorRuntime.wrap(function _callee14$(_context14) {
|
|
878
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
684
879
|
case 0:
|
|
685
|
-
options =
|
|
686
|
-
traceContext =
|
|
880
|
+
options = _args14.length > 2 && _args14[2] !== undefined ? _args14[2] : {};
|
|
881
|
+
traceContext = _args14.length > 3 ? _args14[3] : undefined;
|
|
687
882
|
id = source.id;
|
|
688
883
|
destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
|
|
689
884
|
preview = options.preview, mimeType = options.mimeType;
|
|
690
885
|
cache = getFileStreamsCache();
|
|
691
|
-
|
|
886
|
+
_context14.prev = 6;
|
|
692
887
|
if (!(isCopySourceFileWithToken(source) && isCopyDestinationWithToken(destination))) {
|
|
693
|
-
|
|
888
|
+
_context14.next = 13;
|
|
694
889
|
break;
|
|
695
890
|
}
|
|
696
|
-
|
|
891
|
+
_context14.next = 10;
|
|
697
892
|
return this.copyFileWithToken(source, destination, traceContext);
|
|
698
893
|
case 10:
|
|
699
|
-
copiedFile =
|
|
700
|
-
|
|
894
|
+
copiedFile = _context14.sent;
|
|
895
|
+
_context14.next = 16;
|
|
701
896
|
break;
|
|
702
897
|
case 13:
|
|
703
|
-
|
|
898
|
+
_context14.next = 15;
|
|
704
899
|
return this.copyFileWithIntent(source, destination, traceContext);
|
|
705
900
|
case 15:
|
|
706
|
-
copiedFile =
|
|
901
|
+
copiedFile = _context14.sent;
|
|
707
902
|
case 16:
|
|
708
903
|
// if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
|
|
709
904
|
copiedFileWithMimeType = _objectSpread(_objectSpread({}, copiedFile), mimeType ? {
|
|
@@ -720,21 +915,21 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
720
915
|
previewOverride = !isErrorFileState(copiedFileState) && !!preview ? {
|
|
721
916
|
preview: preview
|
|
722
917
|
} : {};
|
|
723
|
-
|
|
918
|
+
_context14.t0 = !isFinalFileState(copiedFileState) &&
|
|
724
919
|
// mimeType should always be returned by "copyFileWithToken"
|
|
725
920
|
// but in case it's not, we don't want to penalize "copyFile"
|
|
726
921
|
copiedMimeType;
|
|
727
|
-
if (!
|
|
728
|
-
|
|
922
|
+
if (!_context14.t0) {
|
|
923
|
+
_context14.next = 28;
|
|
729
924
|
break;
|
|
730
925
|
}
|
|
731
|
-
|
|
926
|
+
_context14.next = 27;
|
|
732
927
|
return shouldFetchRemoteFileStates(mediaType, copiedMimeType, preview);
|
|
733
928
|
case 27:
|
|
734
|
-
|
|
929
|
+
_context14.t0 = _context14.sent;
|
|
735
930
|
case 28:
|
|
736
|
-
if (!
|
|
737
|
-
|
|
931
|
+
if (!_context14.t0) {
|
|
932
|
+
_context14.next = 35;
|
|
738
933
|
break;
|
|
739
934
|
}
|
|
740
935
|
fileState = _objectSpread(_objectSpread(_objectSpread({}, copiedFileState), overrideMediaTypeIfUnknown(copiedFileState, mediaType)), previewOverride);
|
|
@@ -755,7 +950,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
755
950
|
return subject.complete();
|
|
756
951
|
}
|
|
757
952
|
});
|
|
758
|
-
|
|
953
|
+
_context14.next = 36;
|
|
759
954
|
break;
|
|
760
955
|
case 35:
|
|
761
956
|
if (!isProcessingFileState(copiedFileState)) {
|
|
@@ -767,10 +962,10 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
767
962
|
if (!cache.has(copiedId)) {
|
|
768
963
|
getFileStreamsCache().set(copiedId, subject);
|
|
769
964
|
}
|
|
770
|
-
return
|
|
965
|
+
return _context14.abrupt("return", copiedFile);
|
|
771
966
|
case 40:
|
|
772
|
-
|
|
773
|
-
|
|
967
|
+
_context14.prev = 40;
|
|
968
|
+
_context14.t1 = _context14["catch"](6);
|
|
774
969
|
if (processingSubscription) {
|
|
775
970
|
processingSubscription.unsubscribe();
|
|
776
971
|
}
|
|
@@ -778,23 +973,23 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
778
973
|
_fileCache = cache.get(replaceFileId);
|
|
779
974
|
replaceFileState = this.store.getState().files[replaceFileId];
|
|
780
975
|
if (_fileCache) {
|
|
781
|
-
_fileCache.error(
|
|
976
|
+
_fileCache.error(_context14.t1);
|
|
782
977
|
} else {
|
|
783
978
|
// Create a new subject with the error state for new subscriptions
|
|
784
|
-
cache.set(id, createMediaSubject(
|
|
979
|
+
cache.set(id, createMediaSubject(_context14.t1));
|
|
785
980
|
}
|
|
786
981
|
key = replaceFileState ? replaceFileId : id;
|
|
787
|
-
errorFileState = this.getErrorFileState(
|
|
982
|
+
errorFileState = this.getErrorFileState(_context14.t1, id, occurrenceKey);
|
|
788
983
|
this.setFileState(key, errorFileState);
|
|
789
984
|
}
|
|
790
|
-
throw
|
|
985
|
+
throw _context14.t1;
|
|
791
986
|
case 45:
|
|
792
987
|
case "end":
|
|
793
|
-
return
|
|
988
|
+
return _context14.stop();
|
|
794
989
|
}
|
|
795
|
-
},
|
|
990
|
+
}, _callee14, this, [[6, 40]]);
|
|
796
991
|
}));
|
|
797
|
-
function copyFile(
|
|
992
|
+
function copyFile(_x28, _x29) {
|
|
798
993
|
return _copyFile.apply(this, arguments);
|
|
799
994
|
}
|
|
800
995
|
return copyFile;
|