@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
|
@@ -40,6 +40,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
40
40
|
function FileFetcherImpl(mediaStore, featureFlags) {
|
|
41
41
|
var _this = this;
|
|
42
42
|
_classCallCheck(this, FileFetcherImpl);
|
|
43
|
+
// TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
|
|
43
44
|
_defineProperty(this, "createDownloadFileStream", function (id, collectionName, occurrenceKey) {
|
|
44
45
|
var subject = createMediaSubject();
|
|
45
46
|
var poll = new PollingFunction();
|
|
@@ -51,50 +52,48 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
51
52
|
poll.execute( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
52
53
|
var response, fileState;
|
|
53
54
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
54
|
-
while (1) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
_context.next = 5;
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
throw new FileFetcherError('emptyItems', id, {
|
|
69
|
-
collectionName: collectionName,
|
|
70
|
-
occurrenceKey: occurrenceKey
|
|
71
|
-
});
|
|
72
|
-
case 5:
|
|
73
|
-
if (!isEmptyFile(response)) {
|
|
74
|
-
_context.next = 7;
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
throw new FileFetcherError('zeroVersionFile', id, {
|
|
78
|
-
collectionName: collectionName,
|
|
79
|
-
occurrenceKey: occurrenceKey
|
|
80
|
-
});
|
|
81
|
-
case 7:
|
|
82
|
-
fileState = mapMediaItemToFileState(id, response);
|
|
83
|
-
subject.next(fileState);
|
|
84
|
-
_context.t0 = fileState.status;
|
|
85
|
-
_context.next = _context.t0 === 'processing' ? 12 : _context.t0 === 'processed' ? 14 : 16;
|
|
55
|
+
while (1) switch (_context.prev = _context.next) {
|
|
56
|
+
case 0:
|
|
57
|
+
_context.next = 2;
|
|
58
|
+
return _this.dataloader.load({
|
|
59
|
+
id: id,
|
|
60
|
+
collectionName: collectionName
|
|
61
|
+
});
|
|
62
|
+
case 2:
|
|
63
|
+
response = _context.sent;
|
|
64
|
+
if (response) {
|
|
65
|
+
_context.next = 5;
|
|
86
66
|
break;
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
67
|
+
}
|
|
68
|
+
throw new FileFetcherError('emptyItems', id, {
|
|
69
|
+
collectionName: collectionName,
|
|
70
|
+
occurrenceKey: occurrenceKey
|
|
71
|
+
});
|
|
72
|
+
case 5:
|
|
73
|
+
if (!isEmptyFile(response)) {
|
|
74
|
+
_context.next = 7;
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
throw new FileFetcherError('zeroVersionFile', id, {
|
|
78
|
+
collectionName: collectionName,
|
|
79
|
+
occurrenceKey: occurrenceKey
|
|
80
|
+
});
|
|
81
|
+
case 7:
|
|
82
|
+
fileState = mapMediaItemToFileState(id, response);
|
|
83
|
+
subject.next(fileState);
|
|
84
|
+
_context.t0 = fileState.status;
|
|
85
|
+
_context.next = _context.t0 === 'processing' ? 12 : _context.t0 === 'processed' ? 14 : 16;
|
|
86
|
+
break;
|
|
87
|
+
case 12:
|
|
88
|
+
// the only case for continuing polling, otherwise this function is run once only
|
|
89
|
+
poll.next();
|
|
90
|
+
return _context.abrupt("break", 16);
|
|
91
|
+
case 14:
|
|
92
|
+
subject.complete();
|
|
93
|
+
return _context.abrupt("break", 16);
|
|
94
|
+
case 16:
|
|
95
|
+
case "end":
|
|
96
|
+
return _context.stop();
|
|
98
97
|
}
|
|
99
98
|
}, _callee);
|
|
100
99
|
})));
|
|
@@ -173,8 +172,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
173
172
|
value: function getFileBinaryURL(id, collectionName) {
|
|
174
173
|
return this.mediaStore.getFileBinaryURL(id, collectionName);
|
|
175
174
|
}
|
|
176
|
-
|
|
177
|
-
// TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
|
|
178
175
|
}, {
|
|
179
176
|
key: "touchFiles",
|
|
180
177
|
value: function touchFiles(descriptors, collection, traceContext) {
|
|
@@ -213,120 +210,114 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
213
210
|
var _this3 = this;
|
|
214
211
|
var uploadableFileUpfrontIds, id, occurrenceKey, subject, deferredBlob, preview, name, fileState;
|
|
215
212
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
216
|
-
while (1) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
var
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (!blob) {
|
|
239
|
-
reject('Could not fetch the blob');
|
|
240
|
-
}
|
|
241
|
-
resolve({
|
|
242
|
-
value: blob,
|
|
243
|
-
origin: 'remote'
|
|
244
|
-
});
|
|
245
|
-
case 5:
|
|
246
|
-
case "end":
|
|
247
|
-
return _context2.stop();
|
|
213
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
214
|
+
case 0:
|
|
215
|
+
uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
|
|
216
|
+
id = uploadableFileUpfrontIds.id, occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
|
|
217
|
+
subject = createMediaSubject();
|
|
218
|
+
deferredBlob = fetch(url).then(function (response) {
|
|
219
|
+
return response.blob();
|
|
220
|
+
}).catch(function () {
|
|
221
|
+
return undefined;
|
|
222
|
+
});
|
|
223
|
+
preview = new Promise( /*#__PURE__*/function () {
|
|
224
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(resolve, reject) {
|
|
225
|
+
var blob;
|
|
226
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
227
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
228
|
+
case 0:
|
|
229
|
+
_context2.next = 2;
|
|
230
|
+
return deferredBlob;
|
|
231
|
+
case 2:
|
|
232
|
+
blob = _context2.sent;
|
|
233
|
+
if (!blob) {
|
|
234
|
+
reject('Could not fetch the blob');
|
|
248
235
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
mediaType: 'unknown',
|
|
262
|
-
mimeType: '',
|
|
263
|
-
id: id,
|
|
264
|
-
occurrenceKey: occurrenceKey,
|
|
265
|
-
preview: preview
|
|
236
|
+
resolve({
|
|
237
|
+
value: blob,
|
|
238
|
+
origin: 'remote'
|
|
239
|
+
});
|
|
240
|
+
case 5:
|
|
241
|
+
case "end":
|
|
242
|
+
return _context2.stop();
|
|
243
|
+
}
|
|
244
|
+
}, _callee2);
|
|
245
|
+
}));
|
|
246
|
+
return function (_x4, _x5) {
|
|
247
|
+
return _ref3.apply(this, arguments);
|
|
266
248
|
};
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
subject.next({
|
|
296
|
-
status: 'processing',
|
|
297
|
-
name: name,
|
|
298
|
-
size: size,
|
|
299
|
-
mediaType: mediaType,
|
|
300
|
-
mimeType: type,
|
|
301
|
-
id: id,
|
|
302
|
-
occurrenceKey: occurrenceKey,
|
|
303
|
-
preview: preview
|
|
304
|
-
});
|
|
305
|
-
// we don't want to wait for the file to be upload
|
|
306
|
-
_this3.upload(file, undefined, uploadableFileUpfrontIds, traceContext);
|
|
307
|
-
_context3.next = 12;
|
|
308
|
-
return getDimensionsFromBlob(mediaType, blob);
|
|
309
|
-
case 12:
|
|
310
|
-
dimensions = _context3.sent;
|
|
311
|
-
resolve({
|
|
312
|
-
dimensions: dimensions,
|
|
313
|
-
uploadableFileUpfrontIds: uploadableFileUpfrontIds
|
|
314
|
-
});
|
|
315
|
-
case 14:
|
|
316
|
-
case "end":
|
|
317
|
-
return _context3.stop();
|
|
249
|
+
}());
|
|
250
|
+
name = url.split('/').pop() || ''; // we create a initial fileState with the minimum info that we have at this point
|
|
251
|
+
fileState = {
|
|
252
|
+
status: 'processing',
|
|
253
|
+
name: name,
|
|
254
|
+
size: 0,
|
|
255
|
+
mediaType: 'unknown',
|
|
256
|
+
mimeType: '',
|
|
257
|
+
id: id,
|
|
258
|
+
occurrenceKey: occurrenceKey,
|
|
259
|
+
preview: preview
|
|
260
|
+
};
|
|
261
|
+
subject.next(fileState);
|
|
262
|
+
// we save it into the cache as soon as possible, in case someone subscribes
|
|
263
|
+
getFileStreamsCache().set(id, subject);
|
|
264
|
+
return _context4.abrupt("return", new Promise( /*#__PURE__*/function () {
|
|
265
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resolve, reject) {
|
|
266
|
+
var blob, type, size, file, mediaType, dimensions;
|
|
267
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
268
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
269
|
+
case 0:
|
|
270
|
+
_context3.next = 2;
|
|
271
|
+
return deferredBlob;
|
|
272
|
+
case 2:
|
|
273
|
+
blob = _context3.sent;
|
|
274
|
+
if (blob) {
|
|
275
|
+
_context3.next = 5;
|
|
276
|
+
break;
|
|
318
277
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
278
|
+
return _context3.abrupt("return", reject('Could not download remote file'));
|
|
279
|
+
case 5:
|
|
280
|
+
type = blob.type, size = blob.size;
|
|
281
|
+
file = {
|
|
282
|
+
content: blob,
|
|
283
|
+
mimeType: type,
|
|
284
|
+
collection: collection,
|
|
285
|
+
name: name
|
|
286
|
+
};
|
|
287
|
+
mediaType = getMediaTypeFromMimeType(type); // we emit a richer state after the blob is fetched
|
|
288
|
+
subject.next({
|
|
289
|
+
status: 'processing',
|
|
290
|
+
name: name,
|
|
291
|
+
size: size,
|
|
292
|
+
mediaType: mediaType,
|
|
293
|
+
mimeType: type,
|
|
294
|
+
id: id,
|
|
295
|
+
occurrenceKey: occurrenceKey,
|
|
296
|
+
preview: preview
|
|
297
|
+
});
|
|
298
|
+
// we don't want to wait for the file to be upload
|
|
299
|
+
_this3.upload(file, undefined, uploadableFileUpfrontIds, traceContext);
|
|
300
|
+
_context3.next = 12;
|
|
301
|
+
return getDimensionsFromBlob(mediaType, blob);
|
|
302
|
+
case 12:
|
|
303
|
+
dimensions = _context3.sent;
|
|
304
|
+
resolve({
|
|
305
|
+
dimensions: dimensions,
|
|
306
|
+
uploadableFileUpfrontIds: uploadableFileUpfrontIds
|
|
307
|
+
});
|
|
308
|
+
case 14:
|
|
309
|
+
case "end":
|
|
310
|
+
return _context3.stop();
|
|
311
|
+
}
|
|
312
|
+
}, _callee3);
|
|
313
|
+
}));
|
|
314
|
+
return function (_x6, _x7) {
|
|
315
|
+
return _ref4.apply(this, arguments);
|
|
316
|
+
};
|
|
317
|
+
}()));
|
|
318
|
+
case 10:
|
|
319
|
+
case "end":
|
|
320
|
+
return _context4.stop();
|
|
330
321
|
}
|
|
331
322
|
}, _callee4, this);
|
|
332
323
|
}));
|
|
@@ -486,27 +477,25 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
486
477
|
url,
|
|
487
478
|
_args5 = arguments;
|
|
488
479
|
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
489
|
-
while (1) {
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
return _context5.stop();
|
|
509
|
-
}
|
|
480
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
481
|
+
case 0:
|
|
482
|
+
name = _args5.length > 1 && _args5[1] !== undefined ? _args5[1] : 'download';
|
|
483
|
+
collectionName = _args5.length > 2 ? _args5[2] : undefined;
|
|
484
|
+
_context5.next = 4;
|
|
485
|
+
return this.mediaStore.getFileBinaryURL(id, collectionName);
|
|
486
|
+
case 4:
|
|
487
|
+
url = _context5.sent;
|
|
488
|
+
downloadUrl(url, {
|
|
489
|
+
name: name
|
|
490
|
+
});
|
|
491
|
+
globalMediaEventEmitter.emit('media-viewed', {
|
|
492
|
+
fileId: id,
|
|
493
|
+
isUserCollection: collectionName === RECENTS_COLLECTION,
|
|
494
|
+
viewingLevel: 'download'
|
|
495
|
+
});
|
|
496
|
+
case 7:
|
|
497
|
+
case "end":
|
|
498
|
+
return _context5.stop();
|
|
510
499
|
}
|
|
511
500
|
}, _callee5, this);
|
|
512
501
|
}));
|
|
@@ -549,119 +538,117 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
549
538
|
_fileCache,
|
|
550
539
|
_args6 = arguments;
|
|
551
540
|
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
552
|
-
while (1) {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
owner: owner
|
|
576
|
-
}
|
|
577
|
-
};
|
|
578
|
-
params = {
|
|
579
|
-
collection: destinationCollectionName,
|
|
580
|
-
replaceFileId: replaceFileId,
|
|
581
|
-
occurrenceKey: occurrenceKey
|
|
582
|
-
};
|
|
583
|
-
cache = getFileStreamsCache();
|
|
584
|
-
_context6.prev = 14;
|
|
585
|
-
_context6.next = 17;
|
|
586
|
-
return mediaStore.copyFileWithToken(body, params, traceContext);
|
|
587
|
-
case 17:
|
|
588
|
-
_yield$mediaStore$cop = _context6.sent;
|
|
589
|
-
copiedFile = _yield$mediaStore$cop.data;
|
|
590
|
-
// if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
|
|
591
|
-
copiedFileWithMimeType = _objectSpread(_objectSpread({}, copiedFile), mimeType ? {
|
|
592
|
-
mimeType: mimeType
|
|
593
|
-
} : undefined);
|
|
594
|
-
copiedId = copiedFileWithMimeType.id, copiedMimeType = copiedFileWithMimeType.mimeType; // backend may return an "unknown" mediaType just after the copy
|
|
595
|
-
// it's better to deduce it from "copiedMimeType" using getMediaTypeFromMimeType()
|
|
596
|
-
mediaType = copiedMimeType ? getMediaTypeFromMimeType(copiedMimeType) : 'unknown';
|
|
597
|
-
copiedFileState = mapMediaFileToFileState({
|
|
598
|
-
data: copiedFileWithMimeType
|
|
599
|
-
});
|
|
600
|
-
fileCache = cache.get(copiedId);
|
|
601
|
-
subject = fileCache || createMediaSubject(); // if we were passed a "preview", we propagate it into the copiedFileState
|
|
602
|
-
previewOverride = !isErrorFileState(copiedFileState) && !!preview ? {
|
|
603
|
-
preview: preview
|
|
604
|
-
} : {};
|
|
605
|
-
_context6.t2 = !isFinalFileState(copiedFileState) &&
|
|
606
|
-
// mimeType should always be returned by "copyFileWithToken"
|
|
607
|
-
// but in case it's not, we don't want to penalize "copyFile"
|
|
608
|
-
copiedMimeType;
|
|
609
|
-
if (!_context6.t2) {
|
|
610
|
-
_context6.next = 31;
|
|
611
|
-
break;
|
|
612
|
-
}
|
|
613
|
-
_context6.next = 30;
|
|
614
|
-
return shouldFetchRemoteFileStates(mediaType, copiedMimeType, preview);
|
|
615
|
-
case 30:
|
|
616
|
-
_context6.t2 = _context6.sent;
|
|
617
|
-
case 31:
|
|
618
|
-
if (!_context6.t2) {
|
|
619
|
-
_context6.next = 36;
|
|
620
|
-
break;
|
|
541
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
542
|
+
case 0:
|
|
543
|
+
options = _args6.length > 2 && _args6[2] !== undefined ? _args6[2] : {};
|
|
544
|
+
traceContext = _args6.length > 3 ? _args6[3] : undefined;
|
|
545
|
+
authProvider = source.authProvider, sourceCollection = source.collection, id = source.id;
|
|
546
|
+
destinationAuthProvider = destination.authProvider, destinationCollectionName = destination.collection, replaceFileId = destination.replaceFileId, occurrenceKey = destination.occurrenceKey;
|
|
547
|
+
preview = options.preview, mimeType = options.mimeType;
|
|
548
|
+
mediaStore = destination.mediaStore || new MediaStore({
|
|
549
|
+
authProvider: destinationAuthProvider
|
|
550
|
+
});
|
|
551
|
+
_context6.t0 = authToOwner;
|
|
552
|
+
_context6.next = 9;
|
|
553
|
+
return authProvider({
|
|
554
|
+
collectionName: sourceCollection
|
|
555
|
+
});
|
|
556
|
+
case 9:
|
|
557
|
+
_context6.t1 = _context6.sent;
|
|
558
|
+
owner = (0, _context6.t0)(_context6.t1);
|
|
559
|
+
body = {
|
|
560
|
+
sourceFile: {
|
|
561
|
+
id: id,
|
|
562
|
+
collection: sourceCollection,
|
|
563
|
+
owner: owner
|
|
621
564
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
565
|
+
};
|
|
566
|
+
params = {
|
|
567
|
+
collection: destinationCollectionName,
|
|
568
|
+
replaceFileId: replaceFileId,
|
|
569
|
+
occurrenceKey: occurrenceKey
|
|
570
|
+
};
|
|
571
|
+
cache = getFileStreamsCache();
|
|
572
|
+
_context6.prev = 14;
|
|
573
|
+
_context6.next = 17;
|
|
574
|
+
return mediaStore.copyFileWithToken(body, params, traceContext);
|
|
575
|
+
case 17:
|
|
576
|
+
_yield$mediaStore$cop = _context6.sent;
|
|
577
|
+
copiedFile = _yield$mediaStore$cop.data;
|
|
578
|
+
// if we were passed a "mimeType", we propagate it into copiedFileWithMimeType
|
|
579
|
+
copiedFileWithMimeType = _objectSpread(_objectSpread({}, copiedFile), mimeType ? {
|
|
580
|
+
mimeType: mimeType
|
|
581
|
+
} : undefined);
|
|
582
|
+
copiedId = copiedFileWithMimeType.id, copiedMimeType = copiedFileWithMimeType.mimeType; // backend may return an "unknown" mediaType just after the copy
|
|
583
|
+
// it's better to deduce it from "copiedMimeType" using getMediaTypeFromMimeType()
|
|
584
|
+
mediaType = copiedMimeType ? getMediaTypeFromMimeType(copiedMimeType) : 'unknown';
|
|
585
|
+
copiedFileState = mapMediaFileToFileState({
|
|
586
|
+
data: copiedFileWithMimeType
|
|
587
|
+
});
|
|
588
|
+
fileCache = cache.get(copiedId);
|
|
589
|
+
subject = fileCache || createMediaSubject(); // if we were passed a "preview", we propagate it into the copiedFileState
|
|
590
|
+
previewOverride = !isErrorFileState(copiedFileState) && !!preview ? {
|
|
591
|
+
preview: preview
|
|
592
|
+
} : {};
|
|
593
|
+
_context6.t2 = !isFinalFileState(copiedFileState) &&
|
|
594
|
+
// mimeType should always be returned by "copyFileWithToken"
|
|
595
|
+
// but in case it's not, we don't want to penalize "copyFile"
|
|
596
|
+
copiedMimeType;
|
|
597
|
+
if (!_context6.t2) {
|
|
598
|
+
_context6.next = 31;
|
|
635
599
|
break;
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
600
|
+
}
|
|
601
|
+
_context6.next = 30;
|
|
602
|
+
return shouldFetchRemoteFileStates(mediaType, copiedMimeType, preview);
|
|
603
|
+
case 30:
|
|
604
|
+
_context6.t2 = _context6.sent;
|
|
605
|
+
case 31:
|
|
606
|
+
if (!_context6.t2) {
|
|
607
|
+
_context6.next = 36;
|
|
608
|
+
break;
|
|
609
|
+
}
|
|
610
|
+
subject.next(_objectSpread(_objectSpread(_objectSpread({}, copiedFileState), overrideMediaTypeIfUnknown(copiedFileState, mediaType)), previewOverride));
|
|
611
|
+
processingSubscription = this.createDownloadFileStream(copiedId, destinationCollectionName, occurrenceKey).subscribe({
|
|
612
|
+
next: function next(remoteFileState) {
|
|
613
|
+
return subject.next(_objectSpread(_objectSpread(_objectSpread({}, remoteFileState), overrideMediaTypeIfUnknown(remoteFileState, mediaType)), !isErrorFileState(remoteFileState) && previewOverride));
|
|
614
|
+
},
|
|
615
|
+
error: function error(err) {
|
|
616
|
+
return subject.error(err);
|
|
617
|
+
},
|
|
618
|
+
complete: function complete() {
|
|
619
|
+
return subject.complete();
|
|
650
620
|
}
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
621
|
+
});
|
|
622
|
+
_context6.next = 37;
|
|
623
|
+
break;
|
|
624
|
+
case 36:
|
|
625
|
+
if (!isProcessingFileState(copiedFileState)) {
|
|
626
|
+
subject.next(_objectSpread(_objectSpread({}, copiedFileState), !isErrorFileState(copiedFileState) && previewOverride));
|
|
627
|
+
}
|
|
628
|
+
case 37:
|
|
629
|
+
if (!cache.has(copiedId)) {
|
|
630
|
+
getFileStreamsCache().set(copiedId, subject);
|
|
631
|
+
}
|
|
632
|
+
return _context6.abrupt("return", copiedFile);
|
|
633
|
+
case 41:
|
|
634
|
+
_context6.prev = 41;
|
|
635
|
+
_context6.t3 = _context6["catch"](14);
|
|
636
|
+
if (processingSubscription) {
|
|
637
|
+
processingSubscription.unsubscribe();
|
|
638
|
+
}
|
|
639
|
+
if (replaceFileId) {
|
|
640
|
+
_fileCache = cache.get(replaceFileId);
|
|
641
|
+
if (_fileCache) {
|
|
642
|
+
_fileCache.error(_context6.t3);
|
|
643
|
+
} else {
|
|
644
|
+
// Create a new subject with the error state for new subscriptions
|
|
645
|
+
cache.set(id, createMediaSubject(_context6.t3));
|
|
659
646
|
}
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
647
|
+
}
|
|
648
|
+
throw _context6.t3;
|
|
649
|
+
case 46:
|
|
650
|
+
case "end":
|
|
651
|
+
return _context6.stop();
|
|
665
652
|
}
|
|
666
653
|
}, _callee6, this, [[14, 41]]);
|
|
667
654
|
}));
|