@atlaskit/media-client 28.6.0 → 29.0.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 +99 -53
- package/dist/cjs/client/media-store/MediaStore.js +24 -21
- package/dist/cjs/utils/createCopyIntentRegisterationBatcher.js +123 -0
- package/dist/es2019/client/file-fetcher/index.js +22 -0
- package/dist/es2019/client/media-store/MediaStore.js +6 -11
- package/dist/es2019/utils/createCopyIntentRegisterationBatcher.js +75 -0
- package/dist/esm/client/file-fetcher/index.js +99 -53
- package/dist/esm/client/media-store/MediaStore.js +24 -21
- package/dist/esm/utils/createCopyIntentRegisterationBatcher.js +115 -0
- package/dist/types/client/file-fetcher/index.d.ts +3 -0
- package/dist/types/client/media-store/MediaStore.d.ts +4 -1
- package/dist/types/client/media-store/types.d.ts +5 -1
- package/dist/types/utils/createCopyIntentRegisterationBatcher.d.ts +20 -0
- package/dist/types-ts4.5/client/file-fetcher/index.d.ts +3 -0
- package/dist/types-ts4.5/client/media-store/MediaStore.d.ts +4 -1
- package/dist/types-ts4.5/client/media-store/types.d.ts +5 -1
- package/dist/types-ts4.5/utils/createCopyIntentRegisterationBatcher.d.ts +20 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/media-client
|
|
2
2
|
|
|
3
|
+
## 29.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#98696](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/98696)
|
|
8
|
+
[`bb55fa33eaf3f`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/bb55fa33eaf3f) -
|
|
9
|
+
Changed API of unused registerCopyIntents to enable mutli-file uploads and added bulk reigster
|
|
10
|
+
copy intent endpoint in file
|
|
11
|
+
|
|
3
12
|
## 28.6.0
|
|
4
13
|
|
|
5
14
|
### Minor Changes
|
|
@@ -49,6 +49,8 @@ var _shouldFetchRemoteFileStates = require("../../utils/shouldFetchRemoteFileSta
|
|
|
49
49
|
var _polling = require("../../utils/polling");
|
|
50
50
|
var _detectEmptyFile = require("../../utils/detectEmptyFile");
|
|
51
51
|
var _mediaState = require("@atlaskit/media-state");
|
|
52
|
+
var _createCopyIntentRegisterationBatcher = require("../../utils/createCopyIntentRegisterationBatcher");
|
|
53
|
+
var _helpers = require("../../utils/request/helpers");
|
|
52
54
|
var _excluded = ["metadata"],
|
|
53
55
|
_excluded2 = ["metadata"];
|
|
54
56
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
@@ -189,6 +191,7 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
189
191
|
this.mediaApi = mediaApi;
|
|
190
192
|
this.store = store;
|
|
191
193
|
this.dataloader = (0, _createFileDataLoader.createFileDataloader)(mediaApi);
|
|
194
|
+
this.copyIntentRegisterationBatcher = (0, _createCopyIntentRegisterationBatcher.createCopyIntentRegisterationBatcher)(mediaApi);
|
|
192
195
|
}
|
|
193
196
|
return (0, _createClass2.default)(FileFetcherImpl, [{
|
|
194
197
|
key: "getFileState",
|
|
@@ -520,26 +523,69 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
520
523
|
return downloadBinary;
|
|
521
524
|
}()
|
|
522
525
|
}, {
|
|
523
|
-
key: "
|
|
526
|
+
key: "registerCopyIntent",
|
|
524
527
|
value: function () {
|
|
525
|
-
var
|
|
526
|
-
var
|
|
528
|
+
var _registerCopyIntent = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(id, collectionName) {
|
|
529
|
+
var auth, key, error;
|
|
527
530
|
return _regenerator.default.wrap(function _callee6$(_context6) {
|
|
528
531
|
while (1) switch (_context6.prev = _context6.next) {
|
|
532
|
+
case 0:
|
|
533
|
+
_context6.next = 2;
|
|
534
|
+
return this.mediaApi.resolveAuth({
|
|
535
|
+
collectionName: collectionName
|
|
536
|
+
});
|
|
537
|
+
case 2:
|
|
538
|
+
auth = _context6.sent;
|
|
539
|
+
key = {
|
|
540
|
+
id: id,
|
|
541
|
+
collectionName: collectionName,
|
|
542
|
+
resolvedAuth: auth
|
|
543
|
+
};
|
|
544
|
+
_context6.next = 6;
|
|
545
|
+
return this.copyIntentRegisterationBatcher.load(key);
|
|
546
|
+
case 6:
|
|
547
|
+
error = _context6.sent;
|
|
548
|
+
if (!error) {
|
|
549
|
+
_context6.next = 10;
|
|
550
|
+
break;
|
|
551
|
+
}
|
|
552
|
+
// if the error is retryable then it should not be cached
|
|
553
|
+
if ((0, _helpers.defaultShouldRetryError)(error)) {
|
|
554
|
+
this.copyIntentRegisterationBatcher.clear(key);
|
|
555
|
+
}
|
|
556
|
+
throw error;
|
|
557
|
+
case 10:
|
|
558
|
+
case "end":
|
|
559
|
+
return _context6.stop();
|
|
560
|
+
}
|
|
561
|
+
}, _callee6, this);
|
|
562
|
+
}));
|
|
563
|
+
function registerCopyIntent(_x9, _x10) {
|
|
564
|
+
return _registerCopyIntent.apply(this, arguments);
|
|
565
|
+
}
|
|
566
|
+
return registerCopyIntent;
|
|
567
|
+
}()
|
|
568
|
+
}, {
|
|
569
|
+
key: "copyFileWithToken",
|
|
570
|
+
value: function () {
|
|
571
|
+
var _copyFileWithToken = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee7(source, destination, traceContext) {
|
|
572
|
+
var authProvider, sourceCollection, id, destinationAuthProvider, destinationCollectionName, replaceFileId, occurrenceKey, mediaStore, owner, body, params, _yield$mediaStore$cop, data;
|
|
573
|
+
return _regenerator.default.wrap(function _callee7$(_context7) {
|
|
574
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
529
575
|
case 0:
|
|
530
576
|
authProvider = source.authProvider, sourceCollection = source.collection, id = source.id;
|
|
531
577
|
destinationAuthProvider = destination.authProvider, destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
|
|
532
578
|
mediaStore = destination.mediaStore || new _mediaStore.MediaStore({
|
|
533
579
|
authProvider: destinationAuthProvider
|
|
534
580
|
});
|
|
535
|
-
|
|
536
|
-
|
|
581
|
+
_context7.t0 = _mediaCore.authToOwner;
|
|
582
|
+
_context7.next = 6;
|
|
537
583
|
return authProvider({
|
|
538
584
|
collectionName: sourceCollection
|
|
539
585
|
});
|
|
540
586
|
case 6:
|
|
541
|
-
|
|
542
|
-
owner = (0,
|
|
587
|
+
_context7.t1 = _context7.sent;
|
|
588
|
+
owner = (0, _context7.t0)(_context7.t1);
|
|
543
589
|
body = {
|
|
544
590
|
sourceFile: {
|
|
545
591
|
id: id,
|
|
@@ -552,19 +598,19 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
552
598
|
replaceFileId: replaceFileId,
|
|
553
599
|
occurrenceKey: occurrenceKey
|
|
554
600
|
};
|
|
555
|
-
|
|
601
|
+
_context7.next = 12;
|
|
556
602
|
return mediaStore.copyFileWithToken(body, params, traceContext);
|
|
557
603
|
case 12:
|
|
558
|
-
_yield$mediaStore$cop =
|
|
604
|
+
_yield$mediaStore$cop = _context7.sent;
|
|
559
605
|
data = _yield$mediaStore$cop.data;
|
|
560
|
-
return
|
|
606
|
+
return _context7.abrupt("return", data);
|
|
561
607
|
case 15:
|
|
562
608
|
case "end":
|
|
563
|
-
return
|
|
609
|
+
return _context7.stop();
|
|
564
610
|
}
|
|
565
|
-
},
|
|
611
|
+
}, _callee7);
|
|
566
612
|
}));
|
|
567
|
-
function copyFileWithToken(
|
|
613
|
+
function copyFileWithToken(_x11, _x12, _x13) {
|
|
568
614
|
return _copyFileWithToken.apply(this, arguments);
|
|
569
615
|
}
|
|
570
616
|
return copyFileWithToken;
|
|
@@ -572,28 +618,28 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
572
618
|
}, {
|
|
573
619
|
key: "copyFileWithIntent",
|
|
574
620
|
value: function () {
|
|
575
|
-
var _copyFileWithIntent = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
621
|
+
var _copyFileWithIntent = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee8(source, destination, traceContext) {
|
|
576
622
|
var res, data;
|
|
577
|
-
return _regenerator.default.wrap(function
|
|
578
|
-
while (1) switch (
|
|
623
|
+
return _regenerator.default.wrap(function _callee8$(_context8) {
|
|
624
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
579
625
|
case 0:
|
|
580
|
-
|
|
626
|
+
_context8.next = 2;
|
|
581
627
|
return this.mediaApi.copyFile(source.id, {
|
|
582
628
|
sourceCollection: source.collection,
|
|
583
629
|
collection: destination.collection,
|
|
584
630
|
replaceFileId: destination.replaceFileId
|
|
585
631
|
}, traceContext);
|
|
586
632
|
case 2:
|
|
587
|
-
res =
|
|
633
|
+
res = _context8.sent;
|
|
588
634
|
data = res.data;
|
|
589
|
-
return
|
|
635
|
+
return _context8.abrupt("return", data);
|
|
590
636
|
case 5:
|
|
591
637
|
case "end":
|
|
592
|
-
return
|
|
638
|
+
return _context8.stop();
|
|
593
639
|
}
|
|
594
|
-
},
|
|
640
|
+
}, _callee8, this);
|
|
595
641
|
}));
|
|
596
|
-
function copyFileWithIntent(
|
|
642
|
+
function copyFileWithIntent(_x14, _x15, _x16) {
|
|
597
643
|
return _copyFileWithIntent.apply(this, arguments);
|
|
598
644
|
}
|
|
599
645
|
return copyFileWithIntent;
|
|
@@ -601,7 +647,7 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
601
647
|
}, {
|
|
602
648
|
key: "copyFile",
|
|
603
649
|
value: function () {
|
|
604
|
-
var _copyFile = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function
|
|
650
|
+
var _copyFile = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee9(source, destination) {
|
|
605
651
|
var _this5 = this;
|
|
606
652
|
var options,
|
|
607
653
|
traceContext,
|
|
@@ -628,32 +674,32 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
628
674
|
replaceFileState,
|
|
629
675
|
key,
|
|
630
676
|
errorFileState,
|
|
631
|
-
|
|
632
|
-
return _regenerator.default.wrap(function
|
|
633
|
-
while (1) switch (
|
|
677
|
+
_args9 = arguments;
|
|
678
|
+
return _regenerator.default.wrap(function _callee9$(_context9) {
|
|
679
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
634
680
|
case 0:
|
|
635
|
-
options =
|
|
636
|
-
traceContext =
|
|
681
|
+
options = _args9.length > 2 && _args9[2] !== undefined ? _args9[2] : {};
|
|
682
|
+
traceContext = _args9.length > 3 ? _args9[3] : undefined;
|
|
637
683
|
id = source.id;
|
|
638
684
|
destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
|
|
639
685
|
preview = options.preview, mimeType = options.mimeType;
|
|
640
686
|
cache = (0, _fileStreamsCache.getFileStreamsCache)();
|
|
641
|
-
|
|
687
|
+
_context9.prev = 6;
|
|
642
688
|
if (!(isCopySourceFileWithToken(source) && isCopyDestinationWithToken(destination))) {
|
|
643
|
-
|
|
689
|
+
_context9.next = 13;
|
|
644
690
|
break;
|
|
645
691
|
}
|
|
646
|
-
|
|
692
|
+
_context9.next = 10;
|
|
647
693
|
return this.copyFileWithToken(source, destination, traceContext);
|
|
648
694
|
case 10:
|
|
649
|
-
copiedFile =
|
|
650
|
-
|
|
695
|
+
copiedFile = _context9.sent;
|
|
696
|
+
_context9.next = 16;
|
|
651
697
|
break;
|
|
652
698
|
case 13:
|
|
653
|
-
|
|
699
|
+
_context9.next = 15;
|
|
654
700
|
return this.copyFileWithIntent(source, destination, traceContext);
|
|
655
701
|
case 15:
|
|
656
|
-
copiedFile =
|
|
702
|
+
copiedFile = _context9.sent;
|
|
657
703
|
case 16:
|
|
658
704
|
// if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
|
|
659
705
|
copiedFileWithMimeType = _objectSpread(_objectSpread({}, copiedFile), mimeType ? {
|
|
@@ -670,21 +716,21 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
670
716
|
previewOverride = !(0, _fileState2.isErrorFileState)(copiedFileState) && !!preview ? {
|
|
671
717
|
preview: preview
|
|
672
718
|
} : {};
|
|
673
|
-
|
|
719
|
+
_context9.t0 = !(0, _fileState2.isFinalFileState)(copiedFileState) &&
|
|
674
720
|
// mimeType should always be returned by "copyFileWithToken"
|
|
675
721
|
// but in case it's not, we don't want to penalize "copyFile"
|
|
676
722
|
copiedMimeType;
|
|
677
|
-
if (!
|
|
678
|
-
|
|
723
|
+
if (!_context9.t0) {
|
|
724
|
+
_context9.next = 28;
|
|
679
725
|
break;
|
|
680
726
|
}
|
|
681
|
-
|
|
727
|
+
_context9.next = 27;
|
|
682
728
|
return (0, _shouldFetchRemoteFileStates.shouldFetchRemoteFileStates)(mediaType, copiedMimeType, preview);
|
|
683
729
|
case 27:
|
|
684
|
-
|
|
730
|
+
_context9.t0 = _context9.sent;
|
|
685
731
|
case 28:
|
|
686
|
-
if (!
|
|
687
|
-
|
|
732
|
+
if (!_context9.t0) {
|
|
733
|
+
_context9.next = 35;
|
|
688
734
|
break;
|
|
689
735
|
}
|
|
690
736
|
fileState = _objectSpread(_objectSpread(_objectSpread({}, copiedFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(copiedFileState, mediaType)), previewOverride);
|
|
@@ -705,7 +751,7 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
705
751
|
return subject.complete();
|
|
706
752
|
}
|
|
707
753
|
});
|
|
708
|
-
|
|
754
|
+
_context9.next = 36;
|
|
709
755
|
break;
|
|
710
756
|
case 35:
|
|
711
757
|
if (!(0, _fileState2.isProcessingFileState)(copiedFileState)) {
|
|
@@ -717,10 +763,10 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
717
763
|
if (!cache.has(copiedId)) {
|
|
718
764
|
(0, _fileStreamsCache.getFileStreamsCache)().set(copiedId, subject);
|
|
719
765
|
}
|
|
720
|
-
return
|
|
766
|
+
return _context9.abrupt("return", copiedFile);
|
|
721
767
|
case 40:
|
|
722
|
-
|
|
723
|
-
|
|
768
|
+
_context9.prev = 40;
|
|
769
|
+
_context9.t1 = _context9["catch"](6);
|
|
724
770
|
if (processingSubscription) {
|
|
725
771
|
processingSubscription.unsubscribe();
|
|
726
772
|
}
|
|
@@ -728,23 +774,23 @@ var FileFetcherImpl = exports.FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
728
774
|
_fileCache = cache.get(replaceFileId);
|
|
729
775
|
replaceFileState = this.store.getState().files[replaceFileId];
|
|
730
776
|
if (_fileCache) {
|
|
731
|
-
_fileCache.error(
|
|
777
|
+
_fileCache.error(_context9.t1);
|
|
732
778
|
} else {
|
|
733
779
|
// Create a new subject with the error state for new subscriptions
|
|
734
|
-
cache.set(id, (0, _createMediaSubject.createMediaSubject)(
|
|
780
|
+
cache.set(id, (0, _createMediaSubject.createMediaSubject)(_context9.t1));
|
|
735
781
|
}
|
|
736
782
|
key = replaceFileState ? replaceFileId : id;
|
|
737
|
-
errorFileState = this.getErrorFileState(
|
|
783
|
+
errorFileState = this.getErrorFileState(_context9.t1, id, occurrenceKey);
|
|
738
784
|
this.setFileState(key, errorFileState);
|
|
739
785
|
}
|
|
740
|
-
throw
|
|
786
|
+
throw _context9.t1;
|
|
741
787
|
case 45:
|
|
742
788
|
case "end":
|
|
743
|
-
return
|
|
789
|
+
return _context9.stop();
|
|
744
790
|
}
|
|
745
|
-
},
|
|
791
|
+
}, _callee9, this, [[6, 40]]);
|
|
746
792
|
}));
|
|
747
|
-
function copyFile(
|
|
793
|
+
function copyFile(_x17, _x18) {
|
|
748
794
|
return _copyFile.apply(this, arguments);
|
|
749
795
|
}
|
|
750
796
|
return copyFile;
|
|
@@ -624,34 +624,26 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
|
|
|
624
624
|
}, {
|
|
625
625
|
key: "registerCopyIntents",
|
|
626
626
|
value: function () {
|
|
627
|
-
var _registerCopyIntents = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12(
|
|
628
|
-
var
|
|
627
|
+
var _registerCopyIntents = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee12(files, traceContext, resolvedAuth) {
|
|
628
|
+
var metadata, options;
|
|
629
629
|
return _regenerator.default.wrap(function _callee12$(_context12) {
|
|
630
630
|
while (1) switch (_context12.prev = _context12.next) {
|
|
631
631
|
case 0:
|
|
632
|
-
files = ids.map(function (id) {
|
|
633
|
-
return {
|
|
634
|
-
id: id,
|
|
635
|
-
collection: collectionName
|
|
636
|
-
};
|
|
637
|
-
});
|
|
638
632
|
metadata = {
|
|
639
633
|
method: 'POST',
|
|
640
634
|
endpoint: '/file/copy/intents'
|
|
641
635
|
};
|
|
642
636
|
options = _objectSpread(_objectSpread({}, metadata), {}, {
|
|
643
|
-
authContext: {
|
|
644
|
-
collectionName: collectionName
|
|
645
|
-
},
|
|
646
637
|
headers: jsonHeaders,
|
|
647
638
|
body: JSON.stringify({
|
|
648
639
|
files: files
|
|
649
640
|
}),
|
|
650
|
-
traceContext: traceContext
|
|
641
|
+
traceContext: traceContext,
|
|
642
|
+
resolvedAuth: resolvedAuth
|
|
651
643
|
});
|
|
652
|
-
_context12.next =
|
|
644
|
+
_context12.next = 4;
|
|
653
645
|
return this.request('/file/copy/intents', options);
|
|
654
|
-
case
|
|
646
|
+
case 4:
|
|
655
647
|
case "end":
|
|
656
648
|
return _context12.stop();
|
|
657
649
|
}
|
|
@@ -678,6 +670,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
|
|
|
678
670
|
clientOptions,
|
|
679
671
|
traceContext,
|
|
680
672
|
addMediaClientParam,
|
|
673
|
+
resolvedAuth,
|
|
681
674
|
auth,
|
|
682
675
|
clientId,
|
|
683
676
|
extendedTraceContext,
|
|
@@ -695,11 +688,21 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
|
|
|
695
688
|
};
|
|
696
689
|
controller = _args13.length > 2 ? _args13[2] : undefined;
|
|
697
690
|
useMediaCdn = _args13.length > 3 ? _args13[3] : undefined;
|
|
698
|
-
method = options.method, endpoint = options.endpoint, authContext = options.authContext, params = options.params, headers = options.headers, body = options.body, clientOptions = options.clientOptions, traceContext = options.traceContext, addMediaClientParam = options.addMediaClientParam;
|
|
699
|
-
|
|
691
|
+
method = options.method, endpoint = options.endpoint, authContext = options.authContext, params = options.params, headers = options.headers, body = options.body, clientOptions = options.clientOptions, traceContext = options.traceContext, addMediaClientParam = options.addMediaClientParam, resolvedAuth = options.resolvedAuth;
|
|
692
|
+
if (!(resolvedAuth !== null && resolvedAuth !== void 0)) {
|
|
693
|
+
_context13.next = 8;
|
|
694
|
+
break;
|
|
695
|
+
}
|
|
696
|
+
_context13.t0 = resolvedAuth;
|
|
697
|
+
_context13.next = 11;
|
|
698
|
+
break;
|
|
699
|
+
case 8:
|
|
700
|
+
_context13.next = 10;
|
|
700
701
|
return this.resolveAuth(authContext);
|
|
701
|
-
case
|
|
702
|
-
|
|
702
|
+
case 10:
|
|
703
|
+
_context13.t0 = _context13.sent;
|
|
704
|
+
case 11:
|
|
705
|
+
auth = _context13.t0;
|
|
703
706
|
clientId = (0, _mediaCore.isClientBasedAuth)(auth) ? auth.clientId : undefined;
|
|
704
707
|
extendedTraceContext = (0, _helpers.extendTraceContext)(traceContext);
|
|
705
708
|
extendedParams = addMediaClientParam ? _objectSpread(_objectSpread({}, params), {}, {
|
|
@@ -709,7 +712,7 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
|
|
|
709
712
|
if (useMediaCdn) {
|
|
710
713
|
url = (0, _mediaCdn.mapToMediaCdnUrl)(url, auth.token);
|
|
711
714
|
}
|
|
712
|
-
_context13.next =
|
|
715
|
+
_context13.next = 19;
|
|
713
716
|
return (0, _request3.request)(url, {
|
|
714
717
|
method: method,
|
|
715
718
|
endpoint: endpoint,
|
|
@@ -720,12 +723,12 @@ var MediaStore = exports.MediaStore = /*#__PURE__*/function () {
|
|
|
720
723
|
clientOptions: clientOptions,
|
|
721
724
|
traceContext: extendedTraceContext
|
|
722
725
|
}, controller);
|
|
723
|
-
case
|
|
726
|
+
case 19:
|
|
724
727
|
response = _context13.sent;
|
|
725
728
|
setKeyValueInSessionStorage(MEDIA_API_REGION, response.headers.get('x-media-region'));
|
|
726
729
|
setKeyValueInSessionStorage(MEDIA_API_ENVIRONMENT, response.headers.get('x-media-env'));
|
|
727
730
|
return _context13.abrupt("return", response);
|
|
728
|
-
case
|
|
731
|
+
case 23:
|
|
729
732
|
case "end":
|
|
730
733
|
return _context13.stop();
|
|
731
734
|
}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.MAX_BATCH_SIZE = void 0;
|
|
8
|
+
exports.createCopyIntentRegisterationBatcher = createCopyIntentRegisterationBatcher;
|
|
9
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
10
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
11
|
+
var _dataloader = _interopRequireDefault(require("dataloader"));
|
|
12
|
+
var _mediaCommon = require("@atlaskit/media-common");
|
|
13
|
+
var MAX_BATCH_SIZE = exports.MAX_BATCH_SIZE = 100;
|
|
14
|
+
/**
|
|
15
|
+
* Returns a function that, given Array<DataloaderKey>, resolves to an array of same length containing either DataloaderResult or Error.
|
|
16
|
+
* Such contract is formalised by Dataloader 1.0, @see https://github.com/graphql/dataloader
|
|
17
|
+
*
|
|
18
|
+
* If an Error is resolved in the results, it must be at same position then their corresponding key:
|
|
19
|
+
* - Dataloader will re-throw that Error when accessing/loading that particular key
|
|
20
|
+
*
|
|
21
|
+
* @param mediaStore instance of MediaStore
|
|
22
|
+
*/
|
|
23
|
+
function createBatchCopyIntentRegisterationFunc(mediaStore) {
|
|
24
|
+
return /*#__PURE__*/function () {
|
|
25
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(keys) {
|
|
26
|
+
var keysByToken, items;
|
|
27
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
28
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
29
|
+
case 0:
|
|
30
|
+
keysByToken = keys.reduce(function (acc, key) {
|
|
31
|
+
var token = key.resolvedAuth.token;
|
|
32
|
+
acc[token] = acc[token] || [];
|
|
33
|
+
|
|
34
|
+
// de-duplicate ids in collection
|
|
35
|
+
var hasDuplicates = acc[token].some(function (_ref2) {
|
|
36
|
+
var id = _ref2.id,
|
|
37
|
+
collectionName = _ref2.collectionName;
|
|
38
|
+
return key.id === id && collectionName === key.collectionName;
|
|
39
|
+
});
|
|
40
|
+
if (!hasDuplicates) {
|
|
41
|
+
acc[token].push(key);
|
|
42
|
+
}
|
|
43
|
+
return acc;
|
|
44
|
+
}, {});
|
|
45
|
+
items = [];
|
|
46
|
+
_context2.next = 4;
|
|
47
|
+
return Promise.all(Object.keys(keysByToken).map( /*#__PURE__*/function () {
|
|
48
|
+
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(batchKey) {
|
|
49
|
+
var metadataTraceContext, files, resolvedAuth;
|
|
50
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
51
|
+
while (1) switch (_context.prev = _context.next) {
|
|
52
|
+
case 0:
|
|
53
|
+
metadataTraceContext = {
|
|
54
|
+
traceId: (0, _mediaCommon.getRandomHex)(8),
|
|
55
|
+
spanId: (0, _mediaCommon.getRandomHex)(8)
|
|
56
|
+
};
|
|
57
|
+
files = keysByToken[batchKey].map(function (key) {
|
|
58
|
+
return {
|
|
59
|
+
id: key.id,
|
|
60
|
+
collection: key.collectionName
|
|
61
|
+
};
|
|
62
|
+
}); // given these are batched by the token the assumption is that they have the same details.
|
|
63
|
+
resolvedAuth = keysByToken[batchKey][0].resolvedAuth;
|
|
64
|
+
_context.prev = 3;
|
|
65
|
+
_context.next = 6;
|
|
66
|
+
return mediaStore.registerCopyIntents(files, metadataTraceContext, resolvedAuth);
|
|
67
|
+
case 6:
|
|
68
|
+
_context.next = 11;
|
|
69
|
+
break;
|
|
70
|
+
case 8:
|
|
71
|
+
_context.prev = 8;
|
|
72
|
+
_context.t0 = _context["catch"](3);
|
|
73
|
+
files.forEach(function (_ref4) {
|
|
74
|
+
var id = _ref4.id,
|
|
75
|
+
collection = _ref4.collection;
|
|
76
|
+
items.push({
|
|
77
|
+
id: id,
|
|
78
|
+
collection: collection,
|
|
79
|
+
error: _context.t0
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
case 11:
|
|
83
|
+
case "end":
|
|
84
|
+
return _context.stop();
|
|
85
|
+
}
|
|
86
|
+
}, _callee, null, [[3, 8]]);
|
|
87
|
+
}));
|
|
88
|
+
return function (_x2) {
|
|
89
|
+
return _ref3.apply(this, arguments);
|
|
90
|
+
};
|
|
91
|
+
}()));
|
|
92
|
+
case 4:
|
|
93
|
+
return _context2.abrupt("return", keys.map(function (_ref5) {
|
|
94
|
+
var _items$find;
|
|
95
|
+
var id = _ref5.id,
|
|
96
|
+
collectionName = _ref5.collectionName;
|
|
97
|
+
return (_items$find = items.find(function (item) {
|
|
98
|
+
return item.id === id && item.collection === collectionName;
|
|
99
|
+
})) === null || _items$find === void 0 ? void 0 : _items$find.error;
|
|
100
|
+
}));
|
|
101
|
+
case 5:
|
|
102
|
+
case "end":
|
|
103
|
+
return _context2.stop();
|
|
104
|
+
}
|
|
105
|
+
}, _callee2);
|
|
106
|
+
}));
|
|
107
|
+
return function (_x) {
|
|
108
|
+
return _ref.apply(this, arguments);
|
|
109
|
+
};
|
|
110
|
+
}();
|
|
111
|
+
}
|
|
112
|
+
function createCopyIntentRegisterationBatcher(mediaStore) {
|
|
113
|
+
return new _dataloader.default(createBatchCopyIntentRegisterationFunc(mediaStore), {
|
|
114
|
+
maxBatchSize: MAX_BATCH_SIZE,
|
|
115
|
+
cacheKeyFn: function cacheKeyFn(_ref6) {
|
|
116
|
+
var id = _ref6.id,
|
|
117
|
+
_ref6$collectionName = _ref6.collectionName,
|
|
118
|
+
collectionName = _ref6$collectionName === void 0 ? 'default' : _ref6$collectionName,
|
|
119
|
+
resolvedAuth = _ref6.resolvedAuth;
|
|
120
|
+
return "".concat(id, "-").concat(collectionName, "-").concat(resolvedAuth.token);
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
@@ -25,6 +25,8 @@ import { shouldFetchRemoteFileStates } from '../../utils/shouldFetchRemoteFileSt
|
|
|
25
25
|
import { PollingFunction } from '../../utils/polling';
|
|
26
26
|
import { isEmptyFile } from '../../utils/detectEmptyFile';
|
|
27
27
|
import { mediaStore } from '@atlaskit/media-state';
|
|
28
|
+
import { createCopyIntentRegisterationBatcher } from '../../utils/createCopyIntentRegisterationBatcher';
|
|
29
|
+
import { defaultShouldRetryError } from '../../utils/request/helpers';
|
|
28
30
|
export { isFileFetcherError, FileFetcherError } from './error';
|
|
29
31
|
const isCopySourceFileWithToken = token => !!token.authProvider;
|
|
30
32
|
const isCopyDestinationWithToken = token => !!token.authProvider;
|
|
@@ -141,6 +143,7 @@ export class FileFetcherImpl {
|
|
|
141
143
|
this.mediaApi = mediaApi;
|
|
142
144
|
this.store = store;
|
|
143
145
|
this.dataloader = createFileDataloader(mediaApi);
|
|
146
|
+
this.copyIntentRegisterationBatcher = createCopyIntentRegisterationBatcher(mediaApi);
|
|
144
147
|
}
|
|
145
148
|
getFileState(id, options = {}) {
|
|
146
149
|
const {
|
|
@@ -381,6 +384,25 @@ export class FileFetcherImpl {
|
|
|
381
384
|
traceContext
|
|
382
385
|
});
|
|
383
386
|
}
|
|
387
|
+
async registerCopyIntent(id, collectionName) {
|
|
388
|
+
// pre-resolving auth to add it to the key
|
|
389
|
+
const auth = await this.mediaApi.resolveAuth({
|
|
390
|
+
collectionName
|
|
391
|
+
});
|
|
392
|
+
const key = {
|
|
393
|
+
id,
|
|
394
|
+
collectionName,
|
|
395
|
+
resolvedAuth: auth
|
|
396
|
+
};
|
|
397
|
+
const error = await this.copyIntentRegisterationBatcher.load(key);
|
|
398
|
+
if (error) {
|
|
399
|
+
// if the error is retryable then it should not be cached
|
|
400
|
+
if (defaultShouldRetryError(error)) {
|
|
401
|
+
this.copyIntentRegisterationBatcher.clear(key);
|
|
402
|
+
}
|
|
403
|
+
throw error;
|
|
404
|
+
}
|
|
405
|
+
}
|
|
384
406
|
async copyFileWithToken(source, destination, traceContext) {
|
|
385
407
|
const {
|
|
386
408
|
authProvider,
|
|
@@ -377,25 +377,19 @@ export class MediaStore {
|
|
|
377
377
|
};
|
|
378
378
|
return this.request('/v2/file/copy', options).then(createMapResponseToJson(metadata));
|
|
379
379
|
}
|
|
380
|
-
async registerCopyIntents(
|
|
381
|
-
const files = ids.map(id => ({
|
|
382
|
-
id,
|
|
383
|
-
collection: collectionName
|
|
384
|
-
}));
|
|
380
|
+
async registerCopyIntents(files, traceContext, resolvedAuth) {
|
|
385
381
|
const metadata = {
|
|
386
382
|
method: 'POST',
|
|
387
383
|
endpoint: '/file/copy/intents'
|
|
388
384
|
};
|
|
389
385
|
const options = {
|
|
390
386
|
...metadata,
|
|
391
|
-
authContext: {
|
|
392
|
-
collectionName
|
|
393
|
-
},
|
|
394
387
|
headers: jsonHeaders,
|
|
395
388
|
body: JSON.stringify({
|
|
396
389
|
files
|
|
397
390
|
}),
|
|
398
|
-
traceContext
|
|
391
|
+
traceContext,
|
|
392
|
+
resolvedAuth
|
|
399
393
|
};
|
|
400
394
|
await this.request('/file/copy/intents', options);
|
|
401
395
|
}
|
|
@@ -413,9 +407,10 @@ export class MediaStore {
|
|
|
413
407
|
body,
|
|
414
408
|
clientOptions,
|
|
415
409
|
traceContext,
|
|
416
|
-
addMediaClientParam
|
|
410
|
+
addMediaClientParam,
|
|
411
|
+
resolvedAuth
|
|
417
412
|
} = options;
|
|
418
|
-
const auth = await this.resolveAuth(authContext);
|
|
413
|
+
const auth = resolvedAuth !== null && resolvedAuth !== void 0 ? resolvedAuth : await this.resolveAuth(authContext);
|
|
419
414
|
const clientId = isClientBasedAuth(auth) ? auth.clientId : undefined;
|
|
420
415
|
const extendedTraceContext = extendTraceContext(traceContext);
|
|
421
416
|
const extendedParams = addMediaClientParam ? {
|