@atlaskit/media-client 20.2.1 → 21.1.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 +35 -0
- package/dist/cjs/client/file-fetcher/error.js +4 -4
- package/dist/cjs/client/file-fetcher/index.js +275 -287
- package/dist/cjs/client/media-client.js +48 -34
- package/dist/cjs/client/media-store/index.js +367 -314
- package/dist/cjs/client/media-store/resolveAuth.js +30 -32
- package/dist/cjs/client/stargate-client.js +14 -16
- package/dist/cjs/index.js +6 -13
- package/dist/cjs/models/media.js +8 -9
- package/dist/cjs/uploader/error.js +4 -4
- package/dist/cjs/uploader/index.js +88 -96
- package/dist/cjs/utils/convertBase64ToBlob.js +2 -2
- package/dist/cjs/utils/createFileDataLoader.js +67 -70
- package/dist/cjs/utils/getDimensionsFromBlob.js +23 -25
- package/dist/cjs/utils/getVideoDimensionsFromBlob.js +24 -26
- package/dist/cjs/utils/hashing/hasherCreator.js +32 -34
- package/dist/cjs/utils/mediaSubscribable/fromObservable.js +2 -2
- package/dist/cjs/utils/mobileUpload/error.js +4 -4
- package/dist/cjs/utils/mobileUpload/helpers.js +41 -43
- package/dist/cjs/utils/mobileUpload/stateMachine/index.js +14 -16
- package/dist/cjs/utils/parseJwt.js +52 -0
- package/dist/cjs/utils/polling/index.js +40 -42
- package/dist/cjs/utils/request/errors.js +9 -9
- package/dist/cjs/utils/request/helpers.js +143 -155
- package/dist/cjs/utils/request/index.js +24 -26
- package/dist/cjs/utils/shouldFetchRemoteFileStates.js +39 -41
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/client/file-fetcher/index.js +1 -3
- package/dist/es2019/client/media-client.js +3 -2
- package/dist/es2019/client/media-store/index.js +58 -15
- package/dist/es2019/index.js +2 -3
- package/dist/es2019/models/media.js +6 -4
- package/dist/es2019/uploader/index.js +3 -0
- package/dist/es2019/utils/mediaSubscribable/fromObservable.js +2 -2
- package/dist/es2019/utils/mediaSubscribable/toPromise.js +10 -12
- package/dist/es2019/utils/parseJwt.js +46 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/client/file-fetcher/error.js +4 -4
- package/dist/esm/client/file-fetcher/index.js +273 -286
- package/dist/esm/client/media-client.js +46 -32
- package/dist/esm/client/media-store/index.js +367 -314
- package/dist/esm/client/media-store/resolveAuth.js +30 -32
- package/dist/esm/client/stargate-client.js +14 -16
- package/dist/esm/index.js +2 -3
- package/dist/esm/models/media.js +6 -6
- package/dist/esm/uploader/error.js +4 -4
- package/dist/esm/uploader/index.js +89 -96
- package/dist/esm/utils/convertBase64ToBlob.js +2 -2
- package/dist/esm/utils/createFileDataLoader.js +65 -69
- package/dist/esm/utils/getDimensionsFromBlob.js +23 -25
- package/dist/esm/utils/getVideoDimensionsFromBlob.js +24 -26
- package/dist/esm/utils/hashing/hasherCreator.js +28 -30
- package/dist/esm/utils/mediaSubscribable/fromObservable.js +2 -2
- package/dist/esm/utils/mobileUpload/error.js +4 -4
- package/dist/esm/utils/mobileUpload/helpers.js +41 -43
- package/dist/esm/utils/mobileUpload/stateMachine/index.js +14 -16
- package/dist/esm/utils/parseJwt.js +46 -0
- package/dist/esm/utils/polling/index.js +40 -42
- package/dist/esm/utils/request/errors.js +9 -9
- package/dist/esm/utils/request/helpers.js +143 -155
- package/dist/esm/utils/request/index.js +24 -26
- package/dist/esm/utils/shouldFetchRemoteFileStates.js +39 -41
- package/dist/esm/version.json +1 -1
- package/dist/types/client/__mocks__/media-client.d.ts +0 -2
- package/dist/types/client/file-fetcher/index.d.ts +4 -4
- package/dist/types/client/media-client.d.ts +1 -2
- package/dist/types/client/media-store/index.d.ts +17 -13
- package/dist/types/index.d.ts +4 -6
- package/dist/types/models/file-state.d.ts +2 -2
- package/dist/types/models/media.d.ts +1 -21
- package/dist/types/utils/createFileDataLoader.d.ts +2 -2
- package/dist/types/utils/createMediaSubject.d.ts +2 -2
- package/dist/types/utils/detectEmptyFile.d.ts +2 -2
- package/dist/types/utils/mediaSubscribable/fromObservable.d.ts +3 -3
- package/dist/types/utils/mediaSubscribable/toPromise.d.ts +2 -2
- package/dist/types/utils/mediaSubscribable/types.d.ts +9 -8
- package/dist/types/utils/parseJwt.d.ts +1 -0
- package/package.json +2 -2
- package/report.api.md +77 -126
- package/dist/cjs/client/collection-fetcher.js +0 -98
- package/dist/cjs/models/media-subscribable.js +0 -5
- package/dist/cjs/utils/deprecatedEndpointError.js +0 -43
- package/dist/es2019/client/collection-fetcher.js +0 -38
- package/dist/es2019/models/media-subscribable.js +0 -1
- package/dist/es2019/utils/deprecatedEndpointError.js +0 -20
- package/dist/esm/client/collection-fetcher.js +0 -89
- package/dist/esm/models/media-subscribable.js +0 -1
- package/dist/esm/utils/deprecatedEndpointError.js +0 -34
- package/dist/types/client/collection-fetcher.d.ts +0 -42
- package/dist/types/models/media-subscribable.d.ts +0 -3
- package/dist/types/utils/deprecatedEndpointError.d.ts +0 -16
|
@@ -51,11 +51,13 @@ var _polling = require("../../utils/polling");
|
|
|
51
51
|
var _detectEmptyFile = require("../../utils/detectEmptyFile");
|
|
52
52
|
var _mediaCommon = require("@atlaskit/media-common");
|
|
53
53
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
54
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
54
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } // import setimmediate to temporary fix dataloader 2.0.0 bug
|
|
55
|
+
// @see https://github.com/graphql/dataloader/issues/249
|
|
55
56
|
var FileFetcherImpl = /*#__PURE__*/function () {
|
|
56
57
|
function FileFetcherImpl(mediaStore, featureFlags) {
|
|
57
58
|
var _this = this;
|
|
58
59
|
(0, _classCallCheck2.default)(this, FileFetcherImpl);
|
|
60
|
+
// TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
|
|
59
61
|
(0, _defineProperty2.default)(this, "createDownloadFileStream", function (id, collectionName, occurrenceKey) {
|
|
60
62
|
var subject = (0, _createMediaSubject.createMediaSubject)();
|
|
61
63
|
var poll = new _polling.PollingFunction();
|
|
@@ -67,50 +69,48 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
67
69
|
poll.execute( /*#__PURE__*/(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
68
70
|
var response, fileState;
|
|
69
71
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
70
|
-
while (1) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
_context.next = 5;
|
|
82
|
-
break;
|
|
83
|
-
}
|
|
84
|
-
throw new _error.FileFetcherError('emptyItems', id, {
|
|
85
|
-
collectionName: collectionName,
|
|
86
|
-
occurrenceKey: occurrenceKey
|
|
87
|
-
});
|
|
88
|
-
case 5:
|
|
89
|
-
if (!(0, _detectEmptyFile.isEmptyFile)(response)) {
|
|
90
|
-
_context.next = 7;
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
throw new _error.FileFetcherError('zeroVersionFile', id, {
|
|
94
|
-
collectionName: collectionName,
|
|
95
|
-
occurrenceKey: occurrenceKey
|
|
96
|
-
});
|
|
97
|
-
case 7:
|
|
98
|
-
fileState = (0, _fileState.mapMediaItemToFileState)(id, response);
|
|
99
|
-
subject.next(fileState);
|
|
100
|
-
_context.t0 = fileState.status;
|
|
101
|
-
_context.next = _context.t0 === 'processing' ? 12 : _context.t0 === 'processed' ? 14 : 16;
|
|
72
|
+
while (1) switch (_context.prev = _context.next) {
|
|
73
|
+
case 0:
|
|
74
|
+
_context.next = 2;
|
|
75
|
+
return _this.dataloader.load({
|
|
76
|
+
id: id,
|
|
77
|
+
collectionName: collectionName
|
|
78
|
+
});
|
|
79
|
+
case 2:
|
|
80
|
+
response = _context.sent;
|
|
81
|
+
if (response) {
|
|
82
|
+
_context.next = 5;
|
|
102
83
|
break;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
84
|
+
}
|
|
85
|
+
throw new _error.FileFetcherError('emptyItems', id, {
|
|
86
|
+
collectionName: collectionName,
|
|
87
|
+
occurrenceKey: occurrenceKey
|
|
88
|
+
});
|
|
89
|
+
case 5:
|
|
90
|
+
if (!(0, _detectEmptyFile.isEmptyFile)(response)) {
|
|
91
|
+
_context.next = 7;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
throw new _error.FileFetcherError('zeroVersionFile', id, {
|
|
95
|
+
collectionName: collectionName,
|
|
96
|
+
occurrenceKey: occurrenceKey
|
|
97
|
+
});
|
|
98
|
+
case 7:
|
|
99
|
+
fileState = (0, _fileState.mapMediaItemToFileState)(id, response);
|
|
100
|
+
subject.next(fileState);
|
|
101
|
+
_context.t0 = fileState.status;
|
|
102
|
+
_context.next = _context.t0 === 'processing' ? 12 : _context.t0 === 'processed' ? 14 : 16;
|
|
103
|
+
break;
|
|
104
|
+
case 12:
|
|
105
|
+
// the only case for continuing polling, otherwise this function is run once only
|
|
106
|
+
poll.next();
|
|
107
|
+
return _context.abrupt("break", 16);
|
|
108
|
+
case 14:
|
|
109
|
+
subject.complete();
|
|
110
|
+
return _context.abrupt("break", 16);
|
|
111
|
+
case 16:
|
|
112
|
+
case "end":
|
|
113
|
+
return _context.stop();
|
|
114
114
|
}
|
|
115
115
|
}, _callee);
|
|
116
116
|
})));
|
|
@@ -189,8 +189,6 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
189
189
|
value: function getFileBinaryURL(id, collectionName) {
|
|
190
190
|
return this.mediaStore.getFileBinaryURL(id, collectionName);
|
|
191
191
|
}
|
|
192
|
-
|
|
193
|
-
// TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
|
|
194
192
|
}, {
|
|
195
193
|
key: "touchFiles",
|
|
196
194
|
value: function touchFiles(descriptors, collection, traceContext) {
|
|
@@ -229,120 +227,114 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
229
227
|
var _this3 = this;
|
|
230
228
|
var uploadableFileUpfrontIds, id, occurrenceKey, subject, deferredBlob, preview, name, fileState;
|
|
231
229
|
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
232
|
-
while (1) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
var
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (!blob) {
|
|
255
|
-
reject('Could not fetch the blob');
|
|
256
|
-
}
|
|
257
|
-
resolve({
|
|
258
|
-
value: blob,
|
|
259
|
-
origin: 'remote'
|
|
260
|
-
});
|
|
261
|
-
case 5:
|
|
262
|
-
case "end":
|
|
263
|
-
return _context2.stop();
|
|
230
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
231
|
+
case 0:
|
|
232
|
+
uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
|
|
233
|
+
id = uploadableFileUpfrontIds.id, occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
|
|
234
|
+
subject = (0, _createMediaSubject.createMediaSubject)();
|
|
235
|
+
deferredBlob = fetch(url).then(function (response) {
|
|
236
|
+
return response.blob();
|
|
237
|
+
}).catch(function () {
|
|
238
|
+
return undefined;
|
|
239
|
+
});
|
|
240
|
+
preview = new Promise( /*#__PURE__*/function () {
|
|
241
|
+
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(resolve, reject) {
|
|
242
|
+
var blob;
|
|
243
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
244
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
245
|
+
case 0:
|
|
246
|
+
_context2.next = 2;
|
|
247
|
+
return deferredBlob;
|
|
248
|
+
case 2:
|
|
249
|
+
blob = _context2.sent;
|
|
250
|
+
if (!blob) {
|
|
251
|
+
reject('Could not fetch the blob');
|
|
264
252
|
}
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
mediaType: 'unknown',
|
|
278
|
-
mimeType: '',
|
|
279
|
-
id: id,
|
|
280
|
-
occurrenceKey: occurrenceKey,
|
|
281
|
-
preview: preview
|
|
253
|
+
resolve({
|
|
254
|
+
value: blob,
|
|
255
|
+
origin: 'remote'
|
|
256
|
+
});
|
|
257
|
+
case 5:
|
|
258
|
+
case "end":
|
|
259
|
+
return _context2.stop();
|
|
260
|
+
}
|
|
261
|
+
}, _callee2);
|
|
262
|
+
}));
|
|
263
|
+
return function (_x4, _x5) {
|
|
264
|
+
return _ref3.apply(this, arguments);
|
|
282
265
|
};
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
subject.next({
|
|
312
|
-
status: 'processing',
|
|
313
|
-
name: name,
|
|
314
|
-
size: size,
|
|
315
|
-
mediaType: mediaType,
|
|
316
|
-
mimeType: type,
|
|
317
|
-
id: id,
|
|
318
|
-
occurrenceKey: occurrenceKey,
|
|
319
|
-
preview: preview
|
|
320
|
-
});
|
|
321
|
-
// we don't want to wait for the file to be upload
|
|
322
|
-
_this3.upload(file, undefined, uploadableFileUpfrontIds, traceContext);
|
|
323
|
-
_context3.next = 12;
|
|
324
|
-
return (0, _getDimensionsFromBlob.getDimensionsFromBlob)(mediaType, blob);
|
|
325
|
-
case 12:
|
|
326
|
-
dimensions = _context3.sent;
|
|
327
|
-
resolve({
|
|
328
|
-
dimensions: dimensions,
|
|
329
|
-
uploadableFileUpfrontIds: uploadableFileUpfrontIds
|
|
330
|
-
});
|
|
331
|
-
case 14:
|
|
332
|
-
case "end":
|
|
333
|
-
return _context3.stop();
|
|
266
|
+
}());
|
|
267
|
+
name = url.split('/').pop() || ''; // we create a initial fileState with the minimum info that we have at this point
|
|
268
|
+
fileState = {
|
|
269
|
+
status: 'processing',
|
|
270
|
+
name: name,
|
|
271
|
+
size: 0,
|
|
272
|
+
mediaType: 'unknown',
|
|
273
|
+
mimeType: '',
|
|
274
|
+
id: id,
|
|
275
|
+
occurrenceKey: occurrenceKey,
|
|
276
|
+
preview: preview
|
|
277
|
+
};
|
|
278
|
+
subject.next(fileState);
|
|
279
|
+
// we save it into the cache as soon as possible, in case someone subscribes
|
|
280
|
+
(0, _fileStreamsCache.getFileStreamsCache)().set(id, subject);
|
|
281
|
+
return _context4.abrupt("return", new Promise( /*#__PURE__*/function () {
|
|
282
|
+
var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(resolve, reject) {
|
|
283
|
+
var blob, type, size, file, mediaType, dimensions;
|
|
284
|
+
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
285
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
286
|
+
case 0:
|
|
287
|
+
_context3.next = 2;
|
|
288
|
+
return deferredBlob;
|
|
289
|
+
case 2:
|
|
290
|
+
blob = _context3.sent;
|
|
291
|
+
if (blob) {
|
|
292
|
+
_context3.next = 5;
|
|
293
|
+
break;
|
|
334
294
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
295
|
+
return _context3.abrupt("return", reject('Could not download remote file'));
|
|
296
|
+
case 5:
|
|
297
|
+
type = blob.type, size = blob.size;
|
|
298
|
+
file = {
|
|
299
|
+
content: blob,
|
|
300
|
+
mimeType: type,
|
|
301
|
+
collection: collection,
|
|
302
|
+
name: name
|
|
303
|
+
};
|
|
304
|
+
mediaType = (0, _mediaTypeUtils.getMediaTypeFromMimeType)(type); // we emit a richer state after the blob is fetched
|
|
305
|
+
subject.next({
|
|
306
|
+
status: 'processing',
|
|
307
|
+
name: name,
|
|
308
|
+
size: size,
|
|
309
|
+
mediaType: mediaType,
|
|
310
|
+
mimeType: type,
|
|
311
|
+
id: id,
|
|
312
|
+
occurrenceKey: occurrenceKey,
|
|
313
|
+
preview: preview
|
|
314
|
+
});
|
|
315
|
+
// we don't want to wait for the file to be upload
|
|
316
|
+
_this3.upload(file, undefined, uploadableFileUpfrontIds, traceContext);
|
|
317
|
+
_context3.next = 12;
|
|
318
|
+
return (0, _getDimensionsFromBlob.getDimensionsFromBlob)(mediaType, blob);
|
|
319
|
+
case 12:
|
|
320
|
+
dimensions = _context3.sent;
|
|
321
|
+
resolve({
|
|
322
|
+
dimensions: dimensions,
|
|
323
|
+
uploadableFileUpfrontIds: uploadableFileUpfrontIds
|
|
324
|
+
});
|
|
325
|
+
case 14:
|
|
326
|
+
case "end":
|
|
327
|
+
return _context3.stop();
|
|
328
|
+
}
|
|
329
|
+
}, _callee3);
|
|
330
|
+
}));
|
|
331
|
+
return function (_x6, _x7) {
|
|
332
|
+
return _ref4.apply(this, arguments);
|
|
333
|
+
};
|
|
334
|
+
}()));
|
|
335
|
+
case 10:
|
|
336
|
+
case "end":
|
|
337
|
+
return _context4.stop();
|
|
346
338
|
}
|
|
347
339
|
}, _callee4, this);
|
|
348
340
|
}));
|
|
@@ -502,27 +494,25 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
502
494
|
url,
|
|
503
495
|
_args5 = arguments;
|
|
504
496
|
return _regenerator.default.wrap(function _callee5$(_context5) {
|
|
505
|
-
while (1) {
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
return _context5.stop();
|
|
525
|
-
}
|
|
497
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
498
|
+
case 0:
|
|
499
|
+
name = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : 'download';
|
|
500
|
+
collectionName = _args5.length > 2 ? _args5[2] : undefined;
|
|
501
|
+
_context5.next = 4;
|
|
502
|
+
return this.mediaStore.getFileBinaryURL(id, collectionName);
|
|
503
|
+
case 4:
|
|
504
|
+
url = _context5.sent;
|
|
505
|
+
(0, _downloadUrl.downloadUrl)(url, {
|
|
506
|
+
name: name
|
|
507
|
+
});
|
|
508
|
+
_globalMediaEventEmitter.globalMediaEventEmitter.emit('media-viewed', {
|
|
509
|
+
fileId: id,
|
|
510
|
+
isUserCollection: collectionName === _constants.RECENTS_COLLECTION,
|
|
511
|
+
viewingLevel: 'download'
|
|
512
|
+
});
|
|
513
|
+
case 7:
|
|
514
|
+
case "end":
|
|
515
|
+
return _context5.stop();
|
|
526
516
|
}
|
|
527
517
|
}, _callee5, this);
|
|
528
518
|
}));
|
|
@@ -565,119 +555,117 @@ var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
565
555
|
_fileCache,
|
|
566
556
|
_args6 = arguments;
|
|
567
557
|
return _regenerator.default.wrap(function _callee6$(_context6) {
|
|
568
|
-
while (1) {
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
owner: owner
|
|
592
|
-
}
|
|
593
|
-
};
|
|
594
|
-
params = {
|
|
595
|
-
collection: destinationCollectionName,
|
|
596
|
-
replaceFileId: replaceFileId,
|
|
597
|
-
occurrenceKey: occurrenceKey
|
|
598
|
-
};
|
|
599
|
-
cache = (0, _fileStreamsCache.getFileStreamsCache)();
|
|
600
|
-
_context6.prev = 14;
|
|
601
|
-
_context6.next = 17;
|
|
602
|
-
return mediaStore.copyFileWithToken(body, params, traceContext);
|
|
603
|
-
case 17:
|
|
604
|
-
_yield$mediaStore$cop = _context6.sent;
|
|
605
|
-
copiedFile = _yield$mediaStore$cop.data;
|
|
606
|
-
// if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
|
|
607
|
-
copiedFileWithMimeType = _objectSpread(_objectSpread({}, copiedFile), mimeType ? {
|
|
608
|
-
mimeType: mimeType
|
|
609
|
-
} : undefined);
|
|
610
|
-
copiedId = copiedFileWithMimeType.id, copiedMimeType = copiedFileWithMimeType.mimeType; // backend may return an "unknown" mediaType just after the copy
|
|
611
|
-
// it's better to deduce it from "copiedMimeType" using getMediaTypeFromMimeType()
|
|
612
|
-
mediaType = copiedMimeType ? (0, _mediaTypeUtils.getMediaTypeFromMimeType)(copiedMimeType) : 'unknown';
|
|
613
|
-
copiedFileState = (0, _fileState.mapMediaFileToFileState)({
|
|
614
|
-
data: copiedFileWithMimeType
|
|
615
|
-
});
|
|
616
|
-
fileCache = cache.get(copiedId);
|
|
617
|
-
subject = fileCache || (0, _createMediaSubject.createMediaSubject)(); // if we were passed a "preview", we propagate it into the copiedFileState
|
|
618
|
-
previewOverride = !(0, _fileState.isErrorFileState)(copiedFileState) && !!preview ? {
|
|
619
|
-
preview: preview
|
|
620
|
-
} : {};
|
|
621
|
-
_context6.t2 = !(0, _fileState.isFinalFileState)(copiedFileState) &&
|
|
622
|
-
// mimeType should always be returned by "copyFileWithToken"
|
|
623
|
-
// but in case it's not, we don't want to penalize "copyFile"
|
|
624
|
-
copiedMimeType;
|
|
625
|
-
if (!_context6.t2) {
|
|
626
|
-
_context6.next = 31;
|
|
627
|
-
break;
|
|
628
|
-
}
|
|
629
|
-
_context6.next = 30;
|
|
630
|
-
return (0, _shouldFetchRemoteFileStates.shouldFetchRemoteFileStates)(mediaType, copiedMimeType, preview);
|
|
631
|
-
case 30:
|
|
632
|
-
_context6.t2 = _context6.sent;
|
|
633
|
-
case 31:
|
|
634
|
-
if (!_context6.t2) {
|
|
635
|
-
_context6.next = 36;
|
|
636
|
-
break;
|
|
558
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
559
|
+
case 0:
|
|
560
|
+
options = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {};
|
|
561
|
+
traceContext = _args6.length > 3 ? _args6[3] : undefined;
|
|
562
|
+
authProvider = source.authProvider, sourceCollection = source.collection, id = source.id;
|
|
563
|
+
destinationAuthProvider = destination.authProvider, destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
|
|
564
|
+
preview = options.preview, mimeType = options.mimeType;
|
|
565
|
+
mediaStore = destination.mediaStore || new _mediaStore.MediaStore({
|
|
566
|
+
authProvider: destinationAuthProvider
|
|
567
|
+
});
|
|
568
|
+
_context6.t0 = _mediaCore.authToOwner;
|
|
569
|
+
_context6.next = 9;
|
|
570
|
+
return authProvider({
|
|
571
|
+
collectionName: sourceCollection
|
|
572
|
+
});
|
|
573
|
+
case 9:
|
|
574
|
+
_context6.t1 = _context6.sent;
|
|
575
|
+
owner = (0, _context6.t0)(_context6.t1);
|
|
576
|
+
body = {
|
|
577
|
+
sourceFile: {
|
|
578
|
+
id: id,
|
|
579
|
+
collection: sourceCollection,
|
|
580
|
+
owner: owner
|
|
637
581
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
582
|
+
};
|
|
583
|
+
params = {
|
|
584
|
+
collection: destinationCollectionName,
|
|
585
|
+
replaceFileId: replaceFileId,
|
|
586
|
+
occurrenceKey: occurrenceKey
|
|
587
|
+
};
|
|
588
|
+
cache = (0, _fileStreamsCache.getFileStreamsCache)();
|
|
589
|
+
_context6.prev = 14;
|
|
590
|
+
_context6.next = 17;
|
|
591
|
+
return mediaStore.copyFileWithToken(body, params, traceContext);
|
|
592
|
+
case 17:
|
|
593
|
+
_yield$mediaStore$cop = _context6.sent;
|
|
594
|
+
copiedFile = _yield$mediaStore$cop.data;
|
|
595
|
+
// if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
|
|
596
|
+
copiedFileWithMimeType = _objectSpread(_objectSpread({}, copiedFile), mimeType ? {
|
|
597
|
+
mimeType: mimeType
|
|
598
|
+
} : undefined);
|
|
599
|
+
copiedId = copiedFileWithMimeType.id, copiedMimeType = copiedFileWithMimeType.mimeType; // backend may return an "unknown" mediaType just after the copy
|
|
600
|
+
// it's better to deduce it from "copiedMimeType" using getMediaTypeFromMimeType()
|
|
601
|
+
mediaType = copiedMimeType ? (0, _mediaTypeUtils.getMediaTypeFromMimeType)(copiedMimeType) : 'unknown';
|
|
602
|
+
copiedFileState = (0, _fileState.mapMediaFileToFileState)({
|
|
603
|
+
data: copiedFileWithMimeType
|
|
604
|
+
});
|
|
605
|
+
fileCache = cache.get(copiedId);
|
|
606
|
+
subject = fileCache || (0, _createMediaSubject.createMediaSubject)(); // if we were passed a "preview", we propagate it into the copiedFileState
|
|
607
|
+
previewOverride = !(0, _fileState.isErrorFileState)(copiedFileState) && !!preview ? {
|
|
608
|
+
preview: preview
|
|
609
|
+
} : {};
|
|
610
|
+
_context6.t2 = !(0, _fileState.isFinalFileState)(copiedFileState) &&
|
|
611
|
+
// mimeType should always be returned by "copyFileWithToken"
|
|
612
|
+
// but in case it's not, we don't want to penalize "copyFile"
|
|
613
|
+
copiedMimeType;
|
|
614
|
+
if (!_context6.t2) {
|
|
615
|
+
_context6.next = 31;
|
|
651
616
|
break;
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
617
|
+
}
|
|
618
|
+
_context6.next = 30;
|
|
619
|
+
return (0, _shouldFetchRemoteFileStates.shouldFetchRemoteFileStates)(mediaType, copiedMimeType, preview);
|
|
620
|
+
case 30:
|
|
621
|
+
_context6.t2 = _context6.sent;
|
|
622
|
+
case 31:
|
|
623
|
+
if (!_context6.t2) {
|
|
624
|
+
_context6.next = 36;
|
|
625
|
+
break;
|
|
626
|
+
}
|
|
627
|
+
subject.next(_objectSpread(_objectSpread(_objectSpread({}, copiedFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(copiedFileState, mediaType)), previewOverride));
|
|
628
|
+
processingSubscription = this.createDownloadFileStream(copiedId, destinationCollectionName, occurrenceKey).subscribe({
|
|
629
|
+
next: function next(remoteFileState) {
|
|
630
|
+
return subject.next(_objectSpread(_objectSpread(_objectSpread({}, remoteFileState), (0, _overrideMediaTypeIfUnknown.overrideMediaTypeIfUnknown)(remoteFileState, mediaType)), !(0, _fileState.isErrorFileState)(remoteFileState) && previewOverride));
|
|
631
|
+
},
|
|
632
|
+
error: function error(err) {
|
|
633
|
+
return subject.error(err);
|
|
634
|
+
},
|
|
635
|
+
complete: function complete() {
|
|
636
|
+
return subject.complete();
|
|
666
637
|
}
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
638
|
+
});
|
|
639
|
+
_context6.next = 37;
|
|
640
|
+
break;
|
|
641
|
+
case 36:
|
|
642
|
+
if (!(0, _fileState.isProcessingFileState)(copiedFileState)) {
|
|
643
|
+
subject.next(_objectSpread(_objectSpread({}, copiedFileState), !(0, _fileState.isErrorFileState)(copiedFileState) && previewOverride));
|
|
644
|
+
}
|
|
645
|
+
case 37:
|
|
646
|
+
if (!cache.has(copiedId)) {
|
|
647
|
+
(0, _fileStreamsCache.getFileStreamsCache)().set(copiedId, subject);
|
|
648
|
+
}
|
|
649
|
+
return _context6.abrupt("return", copiedFile);
|
|
650
|
+
case 41:
|
|
651
|
+
_context6.prev = 41;
|
|
652
|
+
_context6.t3 = _context6["catch"](14);
|
|
653
|
+
if (processingSubscription) {
|
|
654
|
+
processingSubscription.unsubscribe();
|
|
655
|
+
}
|
|
656
|
+
if (replaceFileId) {
|
|
657
|
+
_fileCache = cache.get(replaceFileId);
|
|
658
|
+
if (_fileCache) {
|
|
659
|
+
_fileCache.error(_context6.t3);
|
|
660
|
+
} else {
|
|
661
|
+
// Create a new subject with the error state for new subscriptions
|
|
662
|
+
cache.set(id, (0, _createMediaSubject.createMediaSubject)(_context6.t3));
|
|
675
663
|
}
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
664
|
+
}
|
|
665
|
+
throw _context6.t3;
|
|
666
|
+
case 46:
|
|
667
|
+
case "end":
|
|
668
|
+
return _context6.stop();
|
|
681
669
|
}
|
|
682
670
|
}, _callee6, this, [[14, 41]]);
|
|
683
671
|
}));
|