@atlaskit/media-client 23.2.0 → 24.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 +13 -0
- package/dist/cjs/client/file-fetcher/index.js +110 -34
- package/dist/cjs/client/media-client.js +18 -6
- package/dist/cjs/client/media-store/index.js +1 -2
- package/dist/cjs/client/mobile-upload.js +38 -2
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/utils/with-media-client-hoc.js +8 -16
- package/dist/es2019/client/file-fetcher/index.js +101 -28
- package/dist/es2019/client/media-client.js +15 -7
- package/dist/es2019/client/media-store/index.js +1 -2
- package/dist/es2019/client/mobile-upload.js +33 -2
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/utils/with-media-client-hoc.js +8 -16
- package/dist/esm/client/file-fetcher/index.js +106 -30
- package/dist/esm/client/media-client.js +19 -7
- package/dist/esm/client/media-store/index.js +1 -2
- package/dist/esm/client/mobile-upload.js +38 -2
- package/dist/esm/index.js +1 -0
- package/dist/esm/utils/with-media-client-hoc.js +8 -16
- package/dist/types/client/events.d.ts +1 -1
- package/dist/types/client/file-fetcher/index.d.ts +10 -6
- package/dist/types/client/media-client.d.ts +10 -5
- package/dist/types/client/media-store/index.d.ts +3 -4
- package/dist/types/client/mobile-upload.d.ts +6 -2
- package/dist/types/file-streams-cache.d.ts +1 -1
- package/dist/types/index.d.ts +4 -2
- package/dist/types/models/artifacts.d.ts +1 -14
- package/dist/types/models/file-state.d.ts +4 -73
- package/dist/types/models/media.d.ts +1 -1
- package/dist/types/models/mobile-upload.d.ts +1 -1
- package/dist/types/utils/createMediaSubject.d.ts +1 -1
- package/dist/types/utils/mediaSubscribable/fromObservable.d.ts +1 -1
- package/dist/types/utils/mediaSubscribable/toPromise.d.ts +1 -1
- package/dist/types/utils/mediaSubscribable/types.d.ts +1 -1
- package/dist/types/utils/mobileUpload/helpers.d.ts +1 -1
- package/dist/types/utils/mobileUpload/stateMachine/index.d.ts +1 -1
- package/dist/types/utils/mobileUpload/stateMachine/types.d.ts +1 -1
- package/dist/types/utils/overrideMediaTypeIfUnknown.d.ts +1 -1
- package/dist/types/utils/shouldFetchRemoteFileStates.d.ts +1 -1
- package/dist/types/utils/with-media-client-hoc.d.ts +2 -3
- package/dist/types-ts4.5/client/events.d.ts +1 -1
- package/dist/types-ts4.5/client/file-fetcher/index.d.ts +10 -6
- package/dist/types-ts4.5/client/media-client.d.ts +10 -5
- package/dist/types-ts4.5/client/media-store/index.d.ts +3 -4
- package/dist/types-ts4.5/client/mobile-upload.d.ts +6 -2
- package/dist/types-ts4.5/file-streams-cache.d.ts +1 -1
- package/dist/types-ts4.5/index.d.ts +4 -2
- package/dist/types-ts4.5/models/artifacts.d.ts +1 -14
- package/dist/types-ts4.5/models/file-state.d.ts +4 -73
- package/dist/types-ts4.5/models/media.d.ts +1 -1
- package/dist/types-ts4.5/models/mobile-upload.d.ts +1 -1
- package/dist/types-ts4.5/utils/createMediaSubject.d.ts +1 -1
- package/dist/types-ts4.5/utils/mediaSubscribable/fromObservable.d.ts +1 -1
- package/dist/types-ts4.5/utils/mediaSubscribable/toPromise.d.ts +1 -1
- package/dist/types-ts4.5/utils/mediaSubscribable/types.d.ts +1 -1
- package/dist/types-ts4.5/utils/mobileUpload/helpers.d.ts +1 -1
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/index.d.ts +1 -1
- package/dist/types-ts4.5/utils/mobileUpload/stateMachine/types.d.ts +1 -1
- package/dist/types-ts4.5/utils/overrideMediaTypeIfUnknown.d.ts +1 -1
- package/dist/types-ts4.5/utils/shouldFetchRemoteFileStates.d.ts +1 -1
- package/dist/types-ts4.5/utils/with-media-client-hoc.d.ts +2 -3
- package/package.json +5 -3
- package/report.api.md +51 -168
- package/tmp/api-report-tmp.d.ts +51 -160
|
@@ -13,7 +13,7 @@ import uuid from 'uuid/v4';
|
|
|
13
13
|
import 'setimmediate';
|
|
14
14
|
import { authToOwner } from '@atlaskit/media-core';
|
|
15
15
|
import { downloadUrl } from '@atlaskit/media-common/downloadUrl';
|
|
16
|
-
import { MediaStore } from '../media-store';
|
|
16
|
+
import { MediaStore as MediaApi } from '../media-store';
|
|
17
17
|
import { isErrorFileState, isFinalFileState, isProcessingFileState, mapMediaFileToFileState, mapMediaItemToFileState } from '../../models/file-state';
|
|
18
18
|
import { FileFetcherError } from './error';
|
|
19
19
|
import { uploadFile } from '../../uploader';
|
|
@@ -32,11 +32,34 @@ import { isMimeTypeSupportedByBrowser, getMediaTypeFromMimeType } from '@atlaski
|
|
|
32
32
|
import { shouldFetchRemoteFileStates } from '../../utils/shouldFetchRemoteFileStates';
|
|
33
33
|
import { PollingFunction } from '../../utils/polling';
|
|
34
34
|
import { isEmptyFile } from '../../utils/detectEmptyFile';
|
|
35
|
+
import { mediaStore } from '@atlaskit/media-state';
|
|
35
36
|
export { isFileFetcherError, FileFetcherError } from './error';
|
|
36
37
|
export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
37
|
-
function FileFetcherImpl(
|
|
38
|
+
function FileFetcherImpl(mediaApi) {
|
|
38
39
|
var _this = this;
|
|
40
|
+
var store = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : mediaStore;
|
|
39
41
|
_classCallCheck(this, FileFetcherImpl);
|
|
42
|
+
_defineProperty(this, "getErrorFileState", function (error, id, occurrenceKey) {
|
|
43
|
+
return typeof error === 'string' ? {
|
|
44
|
+
status: 'error',
|
|
45
|
+
id: id,
|
|
46
|
+
reason: error,
|
|
47
|
+
occurrenceKey: occurrenceKey,
|
|
48
|
+
message: error
|
|
49
|
+
} : {
|
|
50
|
+
status: 'error',
|
|
51
|
+
id: id,
|
|
52
|
+
reason: error === null || error === void 0 ? void 0 : error.reason,
|
|
53
|
+
details: error === null || error === void 0 ? void 0 : error.attributes,
|
|
54
|
+
occurrenceKey: occurrenceKey,
|
|
55
|
+
message: error === null || error === void 0 ? void 0 : error.message
|
|
56
|
+
};
|
|
57
|
+
});
|
|
58
|
+
_defineProperty(this, "setFileState", function (id, fileState) {
|
|
59
|
+
_this.store.setState(function (state) {
|
|
60
|
+
state.files[id] = fileState;
|
|
61
|
+
});
|
|
62
|
+
});
|
|
40
63
|
// TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
|
|
41
64
|
_defineProperty(this, "createDownloadFileStream", function (id, collectionName, occurrenceKey) {
|
|
42
65
|
var subject = createMediaSubject();
|
|
@@ -131,8 +154,9 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
131
154
|
preview: preview
|
|
132
155
|
};
|
|
133
156
|
});
|
|
134
|
-
this.
|
|
135
|
-
this.
|
|
157
|
+
this.mediaApi = mediaApi;
|
|
158
|
+
this.store = store;
|
|
159
|
+
this.dataloader = createFileDataloader(mediaApi);
|
|
136
160
|
}
|
|
137
161
|
_createClass(FileFetcherImpl, [{
|
|
138
162
|
key: "getFileState",
|
|
@@ -143,14 +167,34 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
143
167
|
occurrenceKey = options.occurrenceKey;
|
|
144
168
|
if (!isValidId(id)) {
|
|
145
169
|
var subject = createMediaSubject();
|
|
146
|
-
|
|
170
|
+
var err = new FileFetcherError('invalidFileId', id, {
|
|
147
171
|
collectionName: collectionName,
|
|
148
172
|
occurrenceKey: occurrenceKey
|
|
149
|
-
})
|
|
173
|
+
});
|
|
174
|
+
var errorFileState = {
|
|
175
|
+
status: 'error',
|
|
176
|
+
id: id,
|
|
177
|
+
reason: err === null || err === void 0 ? void 0 : err.reason,
|
|
178
|
+
message: err === null || err === void 0 ? void 0 : err.message,
|
|
179
|
+
occurrenceKey: occurrenceKey,
|
|
180
|
+
details: err === null || err === void 0 ? void 0 : err.attributes
|
|
181
|
+
};
|
|
182
|
+
subject.error(err);
|
|
183
|
+
this.setFileState(id, errorFileState);
|
|
150
184
|
return fromObservable(subject);
|
|
151
185
|
}
|
|
152
186
|
return fromObservable(getFileStreamsCache().getOrInsert(id, function () {
|
|
153
|
-
|
|
187
|
+
var subject = _this2.createDownloadFileStream(id, collectionName);
|
|
188
|
+
subject.subscribe({
|
|
189
|
+
next: function next(fileState) {
|
|
190
|
+
_this2.setFileState(id, fileState);
|
|
191
|
+
},
|
|
192
|
+
error: function error(err) {
|
|
193
|
+
var errorFileState = _this2.getErrorFileState(err, id, occurrenceKey);
|
|
194
|
+
_this2.setFileState(id, errorFileState);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
return subject;
|
|
154
198
|
}));
|
|
155
199
|
}
|
|
156
200
|
}, {
|
|
@@ -161,17 +205,17 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
161
205
|
}, {
|
|
162
206
|
key: "getArtifactURL",
|
|
163
207
|
value: function getArtifactURL(artifacts, artifactName, collectionName) {
|
|
164
|
-
return this.
|
|
208
|
+
return this.mediaApi.getArtifactURL(artifacts, artifactName, collectionName);
|
|
165
209
|
}
|
|
166
210
|
}, {
|
|
167
211
|
key: "getFileBinaryURL",
|
|
168
212
|
value: function getFileBinaryURL(id, collectionName) {
|
|
169
|
-
return this.
|
|
213
|
+
return this.mediaApi.getFileBinaryURL(id, collectionName);
|
|
170
214
|
}
|
|
171
215
|
}, {
|
|
172
216
|
key: "touchFiles",
|
|
173
217
|
value: function touchFiles(descriptors, collection, traceContext) {
|
|
174
|
-
return this.
|
|
218
|
+
return this.mediaApi.touchFiles({
|
|
175
219
|
descriptors: descriptors
|
|
176
220
|
}, {
|
|
177
221
|
collection: collection
|
|
@@ -257,6 +301,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
257
301
|
subject.next(fileState);
|
|
258
302
|
// we save it into the cache as soon as possible, in case someone subscribes
|
|
259
303
|
getFileStreamsCache().set(id, subject);
|
|
304
|
+
this.setFileState(id, fileState);
|
|
260
305
|
return _context4.abrupt("return", new Promise( /*#__PURE__*/function () {
|
|
261
306
|
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resolve, reject) {
|
|
262
307
|
var blob, type, size, file, mediaType, dimensions;
|
|
@@ -312,7 +357,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
312
357
|
return _ref4.apply(this, arguments);
|
|
313
358
|
};
|
|
314
359
|
}()));
|
|
315
|
-
case
|
|
360
|
+
case 11:
|
|
316
361
|
case "end":
|
|
317
362
|
return _context4.stop();
|
|
318
363
|
}
|
|
@@ -335,22 +380,37 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
335
380
|
var subject = createMediaSubject();
|
|
336
381
|
getFileStreamsCache().set(id, subject);
|
|
337
382
|
var onProgress = function onProgress(progress) {
|
|
338
|
-
|
|
383
|
+
var fileState = _objectSpread(_objectSpread({
|
|
339
384
|
status: 'uploading'
|
|
340
385
|
}, stateBase), {}, {
|
|
341
386
|
progress: progress
|
|
342
|
-
})
|
|
387
|
+
});
|
|
388
|
+
subject.next(fileState);
|
|
389
|
+
_this4.setFileState(id, fileState);
|
|
343
390
|
};
|
|
344
391
|
var processingSubscription = new Subscription();
|
|
345
392
|
var onUploadFinish = function onUploadFinish(error) {
|
|
346
393
|
if (error) {
|
|
394
|
+
var errorFileState = _this4.getErrorFileState(error, id, occurrenceKey);
|
|
395
|
+
_this4.setFileState(id, errorFileState);
|
|
347
396
|
return subject.error(error);
|
|
348
397
|
}
|
|
349
398
|
processingSubscription = _this4.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(function (remoteFileState) {
|
|
350
399
|
return _objectSpread(_objectSpread(_objectSpread({}, stateBase), remoteFileState), overrideMediaTypeIfUnknown(remoteFileState, stateBase.mediaType));
|
|
351
|
-
})).subscribe(
|
|
400
|
+
})).subscribe({
|
|
401
|
+
next: function next(fileState) {
|
|
402
|
+
subject.next(fileState);
|
|
403
|
+
_this4.setFileState(id, fileState);
|
|
404
|
+
},
|
|
405
|
+
error: function error(err) {
|
|
406
|
+
var errorFileState = _this4.getErrorFileState(err, id, occurrenceKey);
|
|
407
|
+
subject.error(err);
|
|
408
|
+
_this4.setFileState(id, errorFileState);
|
|
409
|
+
},
|
|
410
|
+
complete: subject.complete
|
|
411
|
+
});
|
|
352
412
|
};
|
|
353
|
-
var _uploadFile = uploadFile(file, this.
|
|
413
|
+
var _uploadFile = uploadFile(file, this.mediaApi, upfrontId, {
|
|
354
414
|
onUploadFinish: onUploadFinish,
|
|
355
415
|
onProgress: onProgress
|
|
356
416
|
}, traceContext),
|
|
@@ -367,8 +427,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
367
427
|
setTimeout(onProgress, 0, 0);
|
|
368
428
|
return fromObservable(subject);
|
|
369
429
|
}
|
|
370
|
-
|
|
371
|
-
// TODO: ----- ADD TICKET
|
|
372
430
|
}, {
|
|
373
431
|
key: "downloadBinary",
|
|
374
432
|
value: function () {
|
|
@@ -383,7 +441,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
383
441
|
name = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : 'download';
|
|
384
442
|
collectionName = _args5.length > 2 ? _args5[2] : undefined;
|
|
385
443
|
_context5.next = 4;
|
|
386
|
-
return this.
|
|
444
|
+
return this.mediaApi.getFileBinaryURL(id, collectionName);
|
|
387
445
|
case 4:
|
|
388
446
|
url = _context5.sent;
|
|
389
447
|
downloadUrl(url, {
|
|
@@ -409,6 +467,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
409
467
|
key: "copyFile",
|
|
410
468
|
value: function () {
|
|
411
469
|
var _copyFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(source, destination) {
|
|
470
|
+
var _this5 = this;
|
|
412
471
|
var options,
|
|
413
472
|
traceContext,
|
|
414
473
|
authProvider,
|
|
@@ -436,7 +495,12 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
436
495
|
fileCache,
|
|
437
496
|
subject,
|
|
438
497
|
previewOverride,
|
|
498
|
+
fileState,
|
|
499
|
+
_fileState,
|
|
439
500
|
_fileCache,
|
|
501
|
+
replaceFileState,
|
|
502
|
+
key,
|
|
503
|
+
errorFileState,
|
|
440
504
|
_args6 = arguments;
|
|
441
505
|
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
442
506
|
while (1) switch (_context6.prev = _context6.next) {
|
|
@@ -446,7 +510,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
446
510
|
authProvider = source.authProvider, sourceCollection = source.collection, id = source.id;
|
|
447
511
|
destinationAuthProvider = destination.authProvider, destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
|
|
448
512
|
preview = options.preview, mimeType = options.mimeType;
|
|
449
|
-
mediaStore = destination.mediaStore || new
|
|
513
|
+
mediaStore = destination.mediaStore || new MediaApi({
|
|
450
514
|
authProvider: destinationAuthProvider
|
|
451
515
|
});
|
|
452
516
|
_context6.t0 = authToOwner;
|
|
@@ -505,53 +569,65 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
505
569
|
_context6.t2 = _context6.sent;
|
|
506
570
|
case 31:
|
|
507
571
|
if (!_context6.t2) {
|
|
508
|
-
_context6.next =
|
|
572
|
+
_context6.next = 38;
|
|
509
573
|
break;
|
|
510
574
|
}
|
|
511
|
-
|
|
575
|
+
fileState = _objectSpread(_objectSpread(_objectSpread({}, copiedFileState), overrideMediaTypeIfUnknown(copiedFileState, mediaType)), previewOverride);
|
|
576
|
+
subject.next(fileState);
|
|
577
|
+
this.setFileState(copiedId, fileState);
|
|
512
578
|
processingSubscription = this.createDownloadFileStream(copiedId, destinationCollectionName, occurrenceKey).subscribe({
|
|
513
579
|
next: function next(remoteFileState) {
|
|
514
|
-
|
|
580
|
+
var fileState = _objectSpread(_objectSpread(_objectSpread({}, remoteFileState), overrideMediaTypeIfUnknown(remoteFileState, mediaType)), !isErrorFileState(remoteFileState) && previewOverride);
|
|
581
|
+
_this5.setFileState(copiedId, fileState);
|
|
582
|
+
return subject.next(fileState);
|
|
515
583
|
},
|
|
516
584
|
error: function error(err) {
|
|
585
|
+
var errorFileState = _this5.getErrorFileState(err, id, occurrenceKey);
|
|
586
|
+
_this5.setFileState(copiedId, errorFileState);
|
|
517
587
|
return subject.error(err);
|
|
518
588
|
},
|
|
519
589
|
complete: function complete() {
|
|
520
590
|
return subject.complete();
|
|
521
591
|
}
|
|
522
592
|
});
|
|
523
|
-
_context6.next =
|
|
593
|
+
_context6.next = 39;
|
|
524
594
|
break;
|
|
525
|
-
case
|
|
595
|
+
case 38:
|
|
526
596
|
if (!isProcessingFileState(copiedFileState)) {
|
|
527
|
-
|
|
597
|
+
_fileState = _objectSpread(_objectSpread({}, copiedFileState), !isErrorFileState(copiedFileState) && previewOverride);
|
|
598
|
+
subject.next(_fileState);
|
|
599
|
+
this.setFileState(copiedId, _fileState);
|
|
528
600
|
}
|
|
529
|
-
case
|
|
601
|
+
case 39:
|
|
530
602
|
if (!cache.has(copiedId)) {
|
|
531
603
|
getFileStreamsCache().set(copiedId, subject);
|
|
532
604
|
}
|
|
533
605
|
return _context6.abrupt("return", copiedFile);
|
|
534
|
-
case
|
|
535
|
-
_context6.prev =
|
|
606
|
+
case 43:
|
|
607
|
+
_context6.prev = 43;
|
|
536
608
|
_context6.t3 = _context6["catch"](14);
|
|
537
609
|
if (processingSubscription) {
|
|
538
610
|
processingSubscription.unsubscribe();
|
|
539
611
|
}
|
|
540
612
|
if (replaceFileId) {
|
|
541
613
|
_fileCache = cache.get(replaceFileId);
|
|
614
|
+
replaceFileState = this.store.getState().files[replaceFileId];
|
|
542
615
|
if (_fileCache) {
|
|
543
616
|
_fileCache.error(_context6.t3);
|
|
544
617
|
} else {
|
|
545
618
|
// Create a new subject with the error state for new subscriptions
|
|
546
619
|
cache.set(id, createMediaSubject(_context6.t3));
|
|
547
620
|
}
|
|
621
|
+
key = replaceFileState ? replaceFileId : id;
|
|
622
|
+
errorFileState = this.getErrorFileState(_context6.t3, id, occurrenceKey);
|
|
623
|
+
this.setFileState(key, errorFileState);
|
|
548
624
|
}
|
|
549
625
|
throw _context6.t3;
|
|
550
|
-
case
|
|
626
|
+
case 48:
|
|
551
627
|
case "end":
|
|
552
628
|
return _context6.stop();
|
|
553
629
|
}
|
|
554
|
-
}, _callee6, this, [[14,
|
|
630
|
+
}, _callee6, this, [[14, 43]]);
|
|
555
631
|
}));
|
|
556
632
|
function copyFile(_x9, _x10) {
|
|
557
633
|
return _copyFile.apply(this, arguments);
|
|
@@ -3,28 +3,40 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
|
3
3
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
4
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
5
5
|
import { EventEmitter2 } from 'eventemitter2';
|
|
6
|
-
import { MediaStore } from './media-store';
|
|
6
|
+
import { MediaStore as MediaApi } from './media-store';
|
|
7
7
|
import { FileFetcherImpl } from './file-fetcher';
|
|
8
8
|
import { StargateClient } from './stargate-client';
|
|
9
|
+
import { mediaStore } from '@atlaskit/media-state';
|
|
9
10
|
export var MediaClient = /*#__PURE__*/function () {
|
|
10
11
|
// mobile upload is lazily loaded
|
|
11
12
|
|
|
12
13
|
// Deprecated value introduced for backward compatibility with Context
|
|
13
14
|
|
|
14
|
-
function MediaClient(mediaClientConfig
|
|
15
|
+
function MediaClient(mediaClientConfig) {
|
|
16
|
+
var store = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : mediaStore;
|
|
17
|
+
var mediaApi = arguments.length > 2 ? arguments[2] : undefined;
|
|
15
18
|
_classCallCheck(this, MediaClient);
|
|
16
19
|
this.mediaClientConfig = mediaClientConfig;
|
|
17
|
-
this.
|
|
18
|
-
this.mediaStore = new
|
|
20
|
+
this.store = store;
|
|
21
|
+
this.mediaStore = mediaApi !== null && mediaApi !== void 0 ? mediaApi : new MediaApi({
|
|
19
22
|
authProvider: mediaClientConfig.authProvider,
|
|
20
23
|
initialAuth: mediaClientConfig.initialAuth
|
|
21
|
-
}
|
|
24
|
+
});
|
|
22
25
|
this.config = mediaClientConfig;
|
|
23
|
-
this.file = new FileFetcherImpl(this.mediaStore);
|
|
26
|
+
this.file = new FileFetcherImpl(this.mediaStore, this.store);
|
|
24
27
|
this.eventEmitter = new EventEmitter2();
|
|
25
28
|
this.stargate = new StargateClient(mediaClientConfig.stargateBaseUrl);
|
|
26
29
|
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @internal
|
|
33
|
+
*/
|
|
27
34
|
_createClass(MediaClient, [{
|
|
35
|
+
key: "__DO_NOT_USE__getMediaStore",
|
|
36
|
+
value: function __DO_NOT_USE__getMediaStore() {
|
|
37
|
+
return this.store;
|
|
38
|
+
}
|
|
39
|
+
}, {
|
|
28
40
|
key: "getImage",
|
|
29
41
|
value: function getImage(id, params, controller, fetchMaxRes, traceContext) {
|
|
30
42
|
return this.mediaStore.getImage(id, params, controller, fetchMaxRes, traceContext);
|
|
@@ -79,7 +91,7 @@ export var MediaClient = /*#__PURE__*/function () {
|
|
|
79
91
|
return import( /* webpackChunkName: "@atlaskit-internal_media-client-mobile-upload" */'./mobile-upload');
|
|
80
92
|
case 4:
|
|
81
93
|
module = _context2.sent;
|
|
82
|
-
this.mobileUpload = new module.MobileUploadImpl(this.mediaStore);
|
|
94
|
+
this.mobileUpload = new module.MobileUploadImpl(this.mediaStore, this.store);
|
|
83
95
|
return _context2.abrupt("return", this.mobileUpload);
|
|
84
96
|
case 7:
|
|
85
97
|
case "end":
|
|
@@ -31,7 +31,7 @@ var jsonHeaders = {
|
|
|
31
31
|
'Content-Type': 'application/json'
|
|
32
32
|
};
|
|
33
33
|
export var MediaStore = /*#__PURE__*/function () {
|
|
34
|
-
function MediaStore(config
|
|
34
|
+
function MediaStore(config) {
|
|
35
35
|
var _this = this;
|
|
36
36
|
_classCallCheck(this, MediaStore);
|
|
37
37
|
_defineProperty(this, "resolveAuth", function (authContext) {
|
|
@@ -41,7 +41,6 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
41
41
|
return resolveInitialAuth(_this.config.initialAuth);
|
|
42
42
|
});
|
|
43
43
|
this.config = config;
|
|
44
|
-
this.featureFlags = featureFlags;
|
|
45
44
|
}
|
|
46
45
|
_createClass(MediaStore, [{
|
|
47
46
|
key: "removeCollectionFile",
|
|
@@ -1,18 +1,45 @@
|
|
|
1
1
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
2
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
4
|
import { getMediaTypeFromMimeType } from '@atlaskit/media-common';
|
|
5
|
+
import { mediaStore } from '@atlaskit/media-state';
|
|
4
6
|
import { getFileStreamsCache } from '../file-streams-cache';
|
|
5
7
|
import { createFileDataloader } from '../utils/createFileDataLoader';
|
|
6
8
|
import { createServicesCache, createMobileUploadStateMachine, createMobileUploadService, createMobileFileStateSubject } from '../utils/mobileUpload';
|
|
7
9
|
export var MobileUploadImpl = /*#__PURE__*/function () {
|
|
8
|
-
function MobileUploadImpl(
|
|
10
|
+
function MobileUploadImpl(mediaApi) {
|
|
11
|
+
var _this = this;
|
|
12
|
+
var store = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : mediaStore;
|
|
9
13
|
_classCallCheck(this, MobileUploadImpl);
|
|
10
|
-
this
|
|
14
|
+
_defineProperty(this, "getErrorFileState", function (error, id, occurrenceKey) {
|
|
15
|
+
return typeof error === 'string' ? {
|
|
16
|
+
status: 'error',
|
|
17
|
+
id: id,
|
|
18
|
+
reason: error,
|
|
19
|
+
occurrenceKey: occurrenceKey,
|
|
20
|
+
message: error
|
|
21
|
+
} : {
|
|
22
|
+
status: 'error',
|
|
23
|
+
id: id,
|
|
24
|
+
reason: error === null || error === void 0 ? void 0 : error.reason,
|
|
25
|
+
details: error === null || error === void 0 ? void 0 : error.attributes,
|
|
26
|
+
occurrenceKey: occurrenceKey,
|
|
27
|
+
message: error === null || error === void 0 ? void 0 : error.message
|
|
28
|
+
};
|
|
29
|
+
});
|
|
30
|
+
_defineProperty(this, "setFileState", function (id, fileState) {
|
|
31
|
+
_this.store.setState(function (state) {
|
|
32
|
+
state.files[id] = fileState;
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
this.store = store;
|
|
36
|
+
this.dataloader = createFileDataloader(mediaApi);
|
|
11
37
|
this.servicesCache = createServicesCache();
|
|
12
38
|
}
|
|
13
39
|
_createClass(MobileUploadImpl, [{
|
|
14
40
|
key: "notifyUploadStart",
|
|
15
41
|
value: function notifyUploadStart(event) {
|
|
42
|
+
var _this2 = this;
|
|
16
43
|
var fileId = event.fileId,
|
|
17
44
|
collectionName = event.collectionName,
|
|
18
45
|
occurrenceKey = event.occurrenceKey,
|
|
@@ -36,6 +63,15 @@ export var MobileUploadImpl = /*#__PURE__*/function () {
|
|
|
36
63
|
};
|
|
37
64
|
var service = createMobileUploadService(createMobileUploadStateMachine(this.dataloader, initialState, collectionName));
|
|
38
65
|
var subject = createMobileFileStateSubject(service);
|
|
66
|
+
subject.subscribe({
|
|
67
|
+
next: function next(fileState) {
|
|
68
|
+
_this2.setFileState(fileId, fileState);
|
|
69
|
+
},
|
|
70
|
+
error: function error(err) {
|
|
71
|
+
var errorFileState = _this2.getErrorFileState(err, fileId, occurrenceKey);
|
|
72
|
+
_this2.setFileState(fileId, errorFileState);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
39
75
|
this.servicesCache.set(fileId, service);
|
|
40
76
|
getFileStreamsCache().set(fileId, subject);
|
|
41
77
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -24,6 +24,7 @@ export { globalMediaEventEmitter } from './globalMediaEventEmitter';
|
|
|
24
24
|
export { isMediaBlobUrl, getAttrsFromUrl, addFileAttrsToUrl, objectToQueryString } from './utils/url';
|
|
25
25
|
export { createMediaSubscribable, fromObservable } from './utils/mediaSubscribable';
|
|
26
26
|
export { RECENTS_COLLECTION, MAX_RESOLUTION } from './constants';
|
|
27
|
+
export { getFileStreamsCache } from './file-streams-cache';
|
|
27
28
|
|
|
28
29
|
// TODO MEX-659 Remove these exports when all the usages from media-client are replaced with media-common.
|
|
29
30
|
|
|
@@ -10,24 +10,16 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
|
|
|
10
10
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
11
11
|
import React from 'react';
|
|
12
12
|
import { MediaClient } from '../client/media-client';
|
|
13
|
-
var NO_FLAGS = 'NO_FLAGS';
|
|
14
13
|
var mediaClientsMap = new Map();
|
|
15
|
-
export var getMediaClient = function getMediaClient(mediaClientConfig
|
|
16
|
-
var
|
|
17
|
-
var flagsMapKey = featureFlags || NO_FLAGS;
|
|
18
|
-
var mediaClient = (_mediaClientsMap$get = mediaClientsMap.get(mediaClientConfig)) === null || _mediaClientsMap$get === void 0 ? void 0 : _mediaClientsMap$get.get(flagsMapKey);
|
|
14
|
+
export var getMediaClient = function getMediaClient(mediaClientConfig) {
|
|
15
|
+
var mediaClient = mediaClientsMap.get(mediaClientConfig);
|
|
19
16
|
if (!mediaClient) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
subMap = new Map();
|
|
23
|
-
mediaClientsMap.set(mediaClientConfig, subMap);
|
|
24
|
-
}
|
|
25
|
-
mediaClient = new MediaClient(mediaClientConfig, featureFlags);
|
|
26
|
-
subMap.set(flagsMapKey, mediaClient);
|
|
17
|
+
mediaClient = new MediaClient(mediaClientConfig);
|
|
18
|
+
mediaClientsMap.set(mediaClientConfig, mediaClient);
|
|
27
19
|
}
|
|
28
20
|
return mediaClient;
|
|
29
21
|
};
|
|
30
|
-
var createEmptyMediaClient = function createEmptyMediaClient(
|
|
22
|
+
var createEmptyMediaClient = function createEmptyMediaClient() {
|
|
31
23
|
var emptyConfig = {
|
|
32
24
|
authProvider: function authProvider() {
|
|
33
25
|
return Promise.resolve({
|
|
@@ -37,9 +29,9 @@ var createEmptyMediaClient = function createEmptyMediaClient(featureFlags) {
|
|
|
37
29
|
});
|
|
38
30
|
}
|
|
39
31
|
};
|
|
40
|
-
return new MediaClient(emptyConfig
|
|
32
|
+
return new MediaClient(emptyConfig);
|
|
41
33
|
};
|
|
42
|
-
export var withMediaClient = function withMediaClient(Component
|
|
34
|
+
export var withMediaClient = function withMediaClient(Component) {
|
|
43
35
|
return /*#__PURE__*/function (_React$Component) {
|
|
44
36
|
_inherits(_class, _React$Component);
|
|
45
37
|
var _super = _createSuper(_class);
|
|
@@ -54,7 +46,7 @@ export var withMediaClient = function withMediaClient(Component, featureFlags) {
|
|
|
54
46
|
var _this$props = this.props,
|
|
55
47
|
mediaClientConfig = _this$props.mediaClientConfig,
|
|
56
48
|
otherProps = _objectWithoutProperties(_this$props, _excluded);
|
|
57
|
-
var mediaClient = !mediaClientConfig ? createEmptyMediaClient(
|
|
49
|
+
var mediaClient = !mediaClientConfig ? createEmptyMediaClient() : getMediaClient(mediaClientConfig);
|
|
58
50
|
return /*#__PURE__*/React.createElement(Component, _extends({}, otherProps, {
|
|
59
51
|
mediaClient: mediaClient
|
|
60
52
|
}));
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import 'setimmediate';
|
|
2
2
|
import { AuthProvider } from '@atlaskit/media-core';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { MediaFileArtifacts } from '@atlaskit/media-state';
|
|
4
|
+
import { MediaStore as MediaApi, MediaStoreCopyFileWithTokenParams, TouchedFiles, TouchFileDescriptor } from '../media-store';
|
|
5
|
+
import { GetFileOptions } from '../../models/file-state';
|
|
5
6
|
import { MediaFile } from '../../models/media';
|
|
6
7
|
import { UploadableFile, UploadableFileUpfrontIds } from '../../uploader';
|
|
7
|
-
import { MediaFileArtifacts } from '../../models/artifacts';
|
|
8
8
|
import { UploadController } from '../../upload-controller';
|
|
9
9
|
import { MediaSubscribable } from '../../utils/mediaSubscribable';
|
|
10
10
|
import { Dimensions } from '../../utils/getDimensionsFromBlob';
|
|
11
11
|
import { MediaTraceContext } from '@atlaskit/media-common';
|
|
12
|
+
import { FilePreview, FileState, MediaStore } from '@atlaskit/media-state';
|
|
12
13
|
export type { FileFetcherErrorAttributes, FileFetcherErrorReason, } from './error';
|
|
13
14
|
export { isFileFetcherError, FileFetcherError } from './error';
|
|
14
15
|
export interface CopySourceFile {
|
|
@@ -18,7 +19,7 @@ export interface CopySourceFile {
|
|
|
18
19
|
}
|
|
19
20
|
export interface CopyDestination extends MediaStoreCopyFileWithTokenParams {
|
|
20
21
|
authProvider: AuthProvider;
|
|
21
|
-
mediaStore?:
|
|
22
|
+
mediaStore?: MediaApi;
|
|
22
23
|
}
|
|
23
24
|
export interface CopyFileOptions {
|
|
24
25
|
preview?: FilePreview | Promise<FilePreview>;
|
|
@@ -40,9 +41,12 @@ export interface FileFetcher {
|
|
|
40
41
|
getFileBinaryURL(id: string, collectionName?: string): Promise<string>;
|
|
41
42
|
}
|
|
42
43
|
export declare class FileFetcherImpl implements FileFetcher {
|
|
43
|
-
private readonly
|
|
44
|
+
private readonly mediaApi;
|
|
45
|
+
private readonly store;
|
|
44
46
|
private readonly dataloader;
|
|
45
|
-
constructor(
|
|
47
|
+
constructor(mediaApi: MediaApi, store?: MediaStore);
|
|
48
|
+
private getErrorFileState;
|
|
49
|
+
private setFileState;
|
|
46
50
|
getFileState(id: string, options?: GetFileOptions): MediaSubscribable;
|
|
47
51
|
getCurrentState(id: string, options?: GetFileOptions): Promise<FileState>;
|
|
48
52
|
getArtifactURL(artifacts: MediaFileArtifacts, artifactName: keyof MediaFileArtifacts, collectionName?: string): Promise<string>;
|
|
@@ -1,20 +1,25 @@
|
|
|
1
1
|
import { MediaClientConfig } from '@atlaskit/media-core';
|
|
2
|
-
import {
|
|
3
|
-
import { MediaStore, MediaStoreGetFileImageParams, ImageMetadata } from './media-store';
|
|
2
|
+
import { MediaTraceContext } from '@atlaskit/media-common';
|
|
3
|
+
import { MediaStore as MediaApi, MediaStoreGetFileImageParams, ImageMetadata } from './media-store';
|
|
4
4
|
import { FileFetcher } from './file-fetcher';
|
|
5
5
|
import { UploadEventPayloadMap, EventPayloadListener } from './events';
|
|
6
6
|
import { StargateClient } from './stargate-client';
|
|
7
7
|
import { MobileUpload } from '../models/mobile-upload';
|
|
8
|
+
import { MediaStore } from '@atlaskit/media-state';
|
|
8
9
|
export declare class MediaClient {
|
|
9
10
|
readonly mediaClientConfig: MediaClientConfig;
|
|
10
|
-
readonly
|
|
11
|
-
readonly mediaStore:
|
|
11
|
+
private readonly store;
|
|
12
|
+
readonly mediaStore: MediaApi;
|
|
12
13
|
readonly file: FileFetcher;
|
|
13
14
|
readonly stargate: StargateClient;
|
|
14
15
|
private readonly eventEmitter;
|
|
15
16
|
private mobileUpload?;
|
|
16
17
|
readonly config: MediaClientConfig;
|
|
17
|
-
constructor(mediaClientConfig: MediaClientConfig,
|
|
18
|
+
constructor(mediaClientConfig: MediaClientConfig, store?: MediaStore, mediaApi?: MediaApi);
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
__DO_NOT_USE__getMediaStore(): MediaStore;
|
|
18
23
|
getImage(id: string, params?: MediaStoreGetFileImageParams, controller?: AbortController, fetchMaxRes?: boolean, traceContext?: MediaTraceContext): Promise<Blob>;
|
|
19
24
|
getImageUrl(id: string, params?: MediaStoreGetFileImageParams): Promise<string>;
|
|
20
25
|
getImageUrlSync(id: string, params?: MediaStoreGetFileImageParams): string;
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { AsapBasedAuth, AuthContext, ClientAltBasedAuth, MediaApiConfig, Auth } from '@atlaskit/media-core';
|
|
2
|
-
import {
|
|
3
|
-
import { MediaFileArtifacts } from '
|
|
2
|
+
import { MediaTraceContext } from '@atlaskit/media-common';
|
|
3
|
+
import { MediaFileArtifacts } from '@atlaskit/media-state';
|
|
4
4
|
import { MediaChunksProbe, MediaItemDetails, MediaFile, MediaUpload } from '../../models/media';
|
|
5
5
|
import { ClientOptions, RequestHeaders, RequestMethod, RequestParams, RequestMetadata } from '../../utils/request/types';
|
|
6
6
|
export type { MediaStoreErrorReason, MediaStoreErrorAttributes } from './error';
|
|
7
7
|
export { MediaStoreError, isMediaStoreError } from './error';
|
|
8
8
|
export declare class MediaStore {
|
|
9
9
|
private readonly config;
|
|
10
|
-
|
|
11
|
-
constructor(config: MediaApiConfig, featureFlags?: MediaFeatureFlags | undefined);
|
|
10
|
+
constructor(config: MediaApiConfig);
|
|
12
11
|
removeCollectionFile(id: string, collectionName: string, occurrenceKey?: string, traceContext?: MediaTraceContext): Promise<void>;
|
|
13
12
|
createUpload(createUpTo?: number, collectionName?: string, traceContext?: MediaTraceContext): Promise<MediaStoreResponse<MediaUpload[]>>;
|
|
14
13
|
uploadChunk(etag: string, blob: Blob, uploadId: string, partNumber: number, collectionName?: string, traceContext?: MediaTraceContext): Promise<void>;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
+
import { MediaStore } from '@atlaskit/media-state';
|
|
1
2
|
import { MobileUpload, MobileUploadStartEvent, MobileUploadProgressEvent, MobileUploadEndEvent, MobileUploadErrorEvent } from '../models/mobile-upload';
|
|
2
|
-
import { MediaStore } from './media-store';
|
|
3
|
+
import { MediaStore as MediaApi } from './media-store';
|
|
3
4
|
export declare class MobileUploadImpl implements MobileUpload {
|
|
5
|
+
private readonly store;
|
|
4
6
|
private readonly dataloader;
|
|
5
7
|
private readonly servicesCache;
|
|
6
|
-
constructor(
|
|
8
|
+
constructor(mediaApi: MediaApi, store?: MediaStore);
|
|
7
9
|
notifyUploadStart(event: MobileUploadStartEvent): void;
|
|
8
10
|
notifyUploadProgress(event: MobileUploadProgressEvent): void;
|
|
9
11
|
notifyUploadEnd(event: MobileUploadEndEvent): void;
|
|
10
12
|
notifyUploadError(event: MobileUploadErrorEvent): void;
|
|
13
|
+
private getErrorFileState;
|
|
14
|
+
private setFileState;
|
|
11
15
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LRUMap } from 'lru_map';
|
|
2
2
|
import { ReplaySubject } from 'rxjs/ReplaySubject';
|
|
3
|
-
import { FileState } from '
|
|
3
|
+
import { FileState } from '@atlaskit/media-state';
|
|
4
4
|
export declare class StreamsCache<T> {
|
|
5
5
|
private readonly streams;
|
|
6
6
|
constructor(streams: LRUMap<string, ReplaySubject<T>>);
|