@atlaskit/media-client 20.0.1 → 20.0.2
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 +6 -0
- package/dist/cjs/client/collection-fetcher.js +4 -44
- package/dist/cjs/client/file-fetcher/error.js +3 -19
- package/dist/cjs/client/file-fetcher/index.js +72 -191
- package/dist/cjs/client/media-client.js +2 -26
- package/dist/cjs/client/media-store/error.js +1 -17
- package/dist/cjs/client/media-store/index.js +13 -103
- package/dist/cjs/client/media-store/resolveAuth.js +2 -23
- package/dist/cjs/client/mobile-upload.js +9 -22
- package/dist/cjs/client/stargate-client.js +0 -12
- package/dist/cjs/constants.js +0 -3
- package/dist/cjs/file-streams-cache.js +0 -11
- package/dist/cjs/globalMediaEventEmitter.js +0 -3
- package/dist/cjs/identifier.js +0 -8
- package/dist/cjs/index.js +0 -38
- package/dist/cjs/models/artifacts.js +0 -4
- package/dist/cjs/models/auth-headers.js +0 -2
- package/dist/cjs/models/auth-query-parameters.js +0 -2
- package/dist/cjs/models/errors/helpers.js +0 -2
- package/dist/cjs/models/errors/index.js +4 -20
- package/dist/cjs/models/file-state.js +10 -36
- package/dist/cjs/models/media.js +2 -8
- package/dist/cjs/upload-controller.js +0 -6
- package/dist/cjs/uploader/calculateChunkSize.js +1 -10
- package/dist/cjs/uploader/error.js +3 -19
- package/dist/cjs/uploader/index.js +3 -43
- package/dist/cjs/utils/checkWebpSupport.js +3 -7
- package/dist/cjs/utils/convertBase64ToBlob.js +0 -5
- package/dist/cjs/utils/createFileDataLoader.js +4 -28
- package/dist/cjs/utils/createMediaSubject.js +0 -4
- package/dist/cjs/utils/detectEmptyFile.js +8 -15
- package/dist/cjs/utils/getDimensionsFromBlob.js +0 -14
- package/dist/cjs/utils/getImageDimensionsFromBlob.js +0 -4
- package/dist/cjs/utils/getMediaTypeFromUploadableFile.js +0 -3
- package/dist/cjs/utils/getVideoDimensionsFromBlob.js +2 -8
- package/dist/cjs/utils/hashing/hasherCreator.js +0 -20
- package/dist/cjs/utils/hashing/simpleHasher.js +0 -12
- package/dist/cjs/utils/hashing/workerHasher.js +3 -24
- package/dist/cjs/utils/imageResizeModeToFileImageMode.js +0 -2
- package/dist/cjs/utils/isImageRemote.js +0 -5
- package/dist/cjs/utils/mediaSubscribable/fromObservable.js +2 -4
- package/dist/cjs/utils/mediaSubscribable/index.js +0 -2
- package/dist/cjs/utils/mediaSubscribable/toPromise.js +1 -3
- package/dist/cjs/utils/mobileUpload/error.js +3 -19
- package/dist/cjs/utils/mobileUpload/helpers.js +2 -26
- package/dist/cjs/utils/mobileUpload/index.js +0 -4
- package/dist/cjs/utils/mobileUpload/servicesCache.js +0 -2
- package/dist/cjs/utils/mobileUpload/stateMachine/index.js +0 -22
- package/dist/cjs/utils/mobileUpload/stateMachine/states/processing.js +0 -2
- package/dist/cjs/utils/mobileUpload/stateMachine/states/uploading.js +0 -7
- package/dist/cjs/utils/overrideMediaTypeIfUnknown.js +0 -4
- package/dist/cjs/utils/polling/errors.js +1 -17
- package/dist/cjs/utils/polling/index.js +1 -30
- package/dist/cjs/utils/request/errors.js +8 -24
- package/dist/cjs/utils/request/helpers.js +19 -103
- package/dist/cjs/utils/request/index.js +15 -26
- package/dist/cjs/utils/safeUnsubscribe.js +0 -2
- package/dist/cjs/utils/setTimeoutPromise.js +0 -4
- package/dist/cjs/utils/shouldFetchRemoteFileStates.js +0 -21
- package/dist/cjs/utils/url.js +4 -27
- package/dist/cjs/utils/with-media-client-hoc.js +12 -28
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/client/collection-fetcher.js +6 -18
- package/dist/es2019/client/file-fetcher/error.js +0 -2
- package/dist/es2019/client/file-fetcher/index.js +49 -91
- package/dist/es2019/client/media-client.js +3 -13
- package/dist/es2019/client/media-store/error.js +0 -2
- package/dist/es2019/client/media-store/index.js +37 -52
- package/dist/es2019/client/media-store/resolveAuth.js +1 -5
- package/dist/es2019/client/mobile-upload.js +0 -8
- package/dist/es2019/client/stargate-client.js +0 -3
- package/dist/es2019/constants.js +0 -1
- package/dist/es2019/file-streams-cache.js +0 -11
- package/dist/es2019/globalMediaEventEmitter.js +0 -4
- package/dist/es2019/index.js +4 -11
- package/dist/es2019/models/artifacts.js +0 -2
- package/dist/es2019/models/errors/index.js +5 -4
- package/dist/es2019/models/file-state.js +6 -7
- package/dist/es2019/models/media.js +2 -3
- package/dist/es2019/upload-controller.js +0 -3
- package/dist/es2019/uploader/calculateChunkSize.js +1 -4
- package/dist/es2019/uploader/error.js +0 -2
- package/dist/es2019/uploader/index.js +0 -13
- package/dist/es2019/utils/checkWebpSupport.js +3 -4
- package/dist/es2019/utils/convertBase64ToBlob.js +0 -2
- package/dist/es2019/utils/createFileDataLoader.js +6 -9
- package/dist/es2019/utils/createMediaSubject.js +0 -2
- package/dist/es2019/utils/detectEmptyFile.js +1 -5
- package/dist/es2019/utils/getDimensionsFromBlob.js +0 -3
- package/dist/es2019/utils/getImageDimensionsFromBlob.js +0 -2
- package/dist/es2019/utils/getVideoDimensionsFromBlob.js +2 -1
- package/dist/es2019/utils/hashing/hasherCreator.js +0 -2
- package/dist/es2019/utils/hashing/simpleHasher.js +0 -3
- package/dist/es2019/utils/hashing/workerHasher.js +1 -16
- package/dist/es2019/utils/isImageRemote.js +0 -2
- package/dist/es2019/utils/mediaSubscribable/fromObservable.js +2 -1
- package/dist/es2019/utils/mediaSubscribable/toPromise.js +1 -1
- package/dist/es2019/utils/mobileUpload/error.js +0 -2
- package/dist/es2019/utils/mobileUpload/helpers.js +2 -7
- package/dist/es2019/utils/mobileUpload/stateMachine/index.js +0 -2
- package/dist/es2019/utils/mobileUpload/stateMachine/states/uploading.js +2 -1
- package/dist/es2019/utils/overrideMediaTypeIfUnknown.js +0 -1
- package/dist/es2019/utils/polling/errors.js +0 -2
- package/dist/es2019/utils/polling/index.js +3 -20
- package/dist/es2019/utils/request/errors.js +0 -2
- package/dist/es2019/utils/request/helpers.js +24 -35
- package/dist/es2019/utils/request/index.js +2 -2
- package/dist/es2019/utils/shouldFetchRemoteFileStates.js +1 -5
- package/dist/es2019/utils/url.js +6 -14
- package/dist/es2019/utils/with-media-client-hoc.js +10 -7
- package/dist/es2019/version.json +1 -1
- package/dist/esm/client/collection-fetcher.js +4 -34
- package/dist/esm/client/file-fetcher/error.js +3 -12
- package/dist/esm/client/file-fetcher/index.js +74 -161
- package/dist/esm/client/media-client.js +3 -16
- package/dist/esm/client/media-store/error.js +1 -10
- package/dist/esm/client/media-store/index.js +13 -89
- package/dist/esm/client/media-store/resolveAuth.js +2 -13
- package/dist/esm/client/mobile-upload.js +9 -15
- package/dist/esm/client/stargate-client.js +0 -7
- package/dist/esm/constants.js +0 -1
- package/dist/esm/file-streams-cache.js +0 -6
- package/dist/esm/globalMediaEventEmitter.js +0 -1
- package/dist/esm/index.js +4 -11
- package/dist/esm/models/artifacts.js +0 -2
- package/dist/esm/models/errors/index.js +5 -12
- package/dist/esm/models/file-state.js +10 -17
- package/dist/esm/models/media.js +2 -3
- package/dist/esm/upload-controller.js +0 -2
- package/dist/esm/uploader/calculateChunkSize.js +1 -4
- package/dist/esm/uploader/error.js +3 -12
- package/dist/esm/uploader/index.js +3 -32
- package/dist/esm/utils/checkWebpSupport.js +3 -4
- package/dist/esm/utils/convertBase64ToBlob.js +0 -3
- package/dist/esm/utils/createFileDataLoader.js +4 -18
- package/dist/esm/utils/createMediaSubject.js +0 -2
- package/dist/esm/utils/detectEmptyFile.js +8 -12
- package/dist/esm/utils/getDimensionsFromBlob.js +0 -7
- package/dist/esm/utils/getImageDimensionsFromBlob.js +0 -2
- package/dist/esm/utils/getVideoDimensionsFromBlob.js +2 -3
- package/dist/esm/utils/hashing/hasherCreator.js +0 -9
- package/dist/esm/utils/hashing/simpleHasher.js +0 -4
- package/dist/esm/utils/hashing/workerHasher.js +3 -18
- package/dist/esm/utils/isImageRemote.js +0 -3
- package/dist/esm/utils/mediaSubscribable/fromObservable.js +2 -1
- package/dist/esm/utils/mediaSubscribable/toPromise.js +1 -1
- package/dist/esm/utils/mobileUpload/error.js +3 -12
- package/dist/esm/utils/mobileUpload/helpers.js +2 -11
- package/dist/esm/utils/mobileUpload/stateMachine/index.js +0 -6
- package/dist/esm/utils/mobileUpload/stateMachine/states/uploading.js +0 -3
- package/dist/esm/utils/overrideMediaTypeIfUnknown.js +0 -1
- package/dist/esm/utils/polling/errors.js +1 -10
- package/dist/esm/utils/polling/index.js +1 -27
- package/dist/esm/utils/request/errors.js +8 -17
- package/dist/esm/utils/request/helpers.js +22 -76
- package/dist/esm/utils/request/index.js +15 -20
- package/dist/esm/utils/shouldFetchRemoteFileStates.js +1 -15
- package/dist/esm/utils/url.js +4 -18
- package/dist/esm/utils/with-media-client-hoc.js +12 -17
- package/dist/esm/version.json +1 -1
- package/package.json +7 -5
|
@@ -2,19 +2,16 @@ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
|
2
2
|
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
3
|
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
4
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
|
-
|
|
6
5
|
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; }
|
|
7
|
-
|
|
8
6
|
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) { _defineProperty(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; }
|
|
9
|
-
|
|
10
7
|
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
11
8
|
import { Subscription } from 'rxjs/Subscription';
|
|
12
9
|
import { of } from 'rxjs/observable/of';
|
|
13
10
|
import { map } from 'rxjs/operators/map';
|
|
14
11
|
import { concatMap } from 'rxjs/operators/concatMap';
|
|
15
|
-
import uuid from 'uuid/v4';
|
|
12
|
+
import uuid from 'uuid/v4';
|
|
13
|
+
// import setimmediate to temporary fix dataloader 2.0.0 bug
|
|
16
14
|
// @see https://github.com/graphql/dataloader/issues/249
|
|
17
|
-
|
|
18
15
|
import 'setimmediate';
|
|
19
16
|
import { authToOwner } from '@atlaskit/media-core';
|
|
20
17
|
import { downloadUrl } from '@atlaskit/media-common/downloadUrl';
|
|
@@ -42,17 +39,15 @@ export { isFileFetcherError, FileFetcherError } from './error';
|
|
|
42
39
|
export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
43
40
|
function FileFetcherImpl(mediaStore, featureFlags) {
|
|
44
41
|
var _this = this;
|
|
45
|
-
|
|
46
42
|
_classCallCheck(this, FileFetcherImpl);
|
|
47
|
-
|
|
48
43
|
_defineProperty(this, "createDownloadFileStream", function (id, collectionName, occurrenceKey) {
|
|
49
44
|
var subject = createMediaSubject();
|
|
50
|
-
var poll = new PollingFunction();
|
|
45
|
+
var poll = new PollingFunction();
|
|
51
46
|
|
|
47
|
+
// ensure subject errors if polling exceeds max iterations or uncaught exception in executor
|
|
52
48
|
poll.onError = function (error) {
|
|
53
49
|
return subject.error(error);
|
|
54
50
|
};
|
|
55
|
-
|
|
56
51
|
poll.execute( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
57
52
|
var response, fileState;
|
|
58
53
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
@@ -64,47 +59,38 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
64
59
|
id: id,
|
|
65
60
|
collectionName: collectionName
|
|
66
61
|
});
|
|
67
|
-
|
|
68
62
|
case 2:
|
|
69
63
|
response = _context.sent;
|
|
70
|
-
|
|
71
64
|
if (response) {
|
|
72
65
|
_context.next = 5;
|
|
73
66
|
break;
|
|
74
67
|
}
|
|
75
|
-
|
|
76
68
|
throw new FileFetcherError('emptyItems', id, {
|
|
77
69
|
collectionName: collectionName,
|
|
78
70
|
occurrenceKey: occurrenceKey
|
|
79
71
|
});
|
|
80
|
-
|
|
81
72
|
case 5:
|
|
82
73
|
if (!isEmptyFile(response)) {
|
|
83
74
|
_context.next = 7;
|
|
84
75
|
break;
|
|
85
76
|
}
|
|
86
|
-
|
|
87
77
|
throw new FileFetcherError('zeroVersionFile', id, {
|
|
88
78
|
collectionName: collectionName,
|
|
89
79
|
occurrenceKey: occurrenceKey
|
|
90
80
|
});
|
|
91
|
-
|
|
92
81
|
case 7:
|
|
93
82
|
fileState = mapMediaItemToFileState(id, response);
|
|
94
83
|
subject.next(fileState);
|
|
95
84
|
_context.t0 = fileState.status;
|
|
96
85
|
_context.next = _context.t0 === 'processing' ? 12 : _context.t0 === 'processed' ? 14 : 16;
|
|
97
86
|
break;
|
|
98
|
-
|
|
99
87
|
case 12:
|
|
100
88
|
// the only case for continuing polling, otherwise this function is run once only
|
|
101
89
|
poll.next();
|
|
102
90
|
return _context.abrupt("break", 16);
|
|
103
|
-
|
|
104
91
|
case 14:
|
|
105
92
|
subject.complete();
|
|
106
93
|
return _context.abrupt("break", 16);
|
|
107
|
-
|
|
108
94
|
case 16:
|
|
109
95
|
case "end":
|
|
110
96
|
return _context.stop();
|
|
@@ -114,27 +100,23 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
114
100
|
})));
|
|
115
101
|
return subject;
|
|
116
102
|
});
|
|
117
|
-
|
|
118
103
|
_defineProperty(this, "getUploadingFileStateBase", function (file, upfrontId) {
|
|
119
104
|
// TODO: DO not modify the input parameter 'content' attribute
|
|
120
105
|
if (typeof file.content === 'string') {
|
|
121
106
|
file.content = convertBase64ToBlob(file.content);
|
|
122
107
|
}
|
|
123
|
-
|
|
124
108
|
var content = file.content,
|
|
125
|
-
|
|
126
|
-
|
|
109
|
+
_file$name = file.name,
|
|
110
|
+
name = _file$name === void 0 ? '' : _file$name;
|
|
127
111
|
var id = upfrontId.id,
|
|
128
|
-
|
|
129
|
-
var preview;
|
|
130
|
-
|
|
112
|
+
occurrenceKey = upfrontId.occurrenceKey;
|
|
113
|
+
var preview;
|
|
114
|
+
// TODO [MSW-796]: get file size for base64
|
|
131
115
|
var size = 0;
|
|
132
116
|
var mimeType = '';
|
|
133
|
-
|
|
134
117
|
if (content instanceof Blob) {
|
|
135
118
|
size = content.size;
|
|
136
119
|
mimeType = content.type;
|
|
137
|
-
|
|
138
120
|
if (isMimeTypeSupportedByBrowser(content.type)) {
|
|
139
121
|
preview = {
|
|
140
122
|
value: content,
|
|
@@ -142,7 +124,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
142
124
|
};
|
|
143
125
|
}
|
|
144
126
|
}
|
|
145
|
-
|
|
146
127
|
var mediaType = getMediaTypeFromUploadableFile(file);
|
|
147
128
|
return {
|
|
148
129
|
id: id,
|
|
@@ -154,21 +135,17 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
154
135
|
preview: preview
|
|
155
136
|
};
|
|
156
137
|
});
|
|
157
|
-
|
|
158
138
|
this.mediaStore = mediaStore;
|
|
159
139
|
this.featureFlags = featureFlags;
|
|
160
140
|
this.dataloader = createFileDataloader(mediaStore);
|
|
161
141
|
}
|
|
162
|
-
|
|
163
142
|
_createClass(FileFetcherImpl, [{
|
|
164
143
|
key: "getFileState",
|
|
165
144
|
value: function getFileState(id) {
|
|
166
145
|
var _this2 = this;
|
|
167
|
-
|
|
168
146
|
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
169
147
|
var collectionName = options.collectionName,
|
|
170
|
-
|
|
171
|
-
|
|
148
|
+
occurrenceKey = options.occurrenceKey;
|
|
172
149
|
if (!isValidId(id)) {
|
|
173
150
|
var subject = createMediaSubject();
|
|
174
151
|
subject.error(new FileFetcherError('invalidFileId', id, {
|
|
@@ -177,7 +154,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
177
154
|
}));
|
|
178
155
|
return fromObservable(subject);
|
|
179
156
|
}
|
|
180
|
-
|
|
181
157
|
return fromObservable(getFileStreamsCache().getOrInsert(id, function () {
|
|
182
158
|
return _this2.createDownloadFileStream(id, collectionName);
|
|
183
159
|
}));
|
|
@@ -196,8 +172,9 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
196
172
|
key: "getFileBinaryURL",
|
|
197
173
|
value: function getFileBinaryURL(id, collectionName) {
|
|
198
174
|
return this.mediaStore.getFileBinaryURL(id, collectionName);
|
|
199
|
-
}
|
|
175
|
+
}
|
|
200
176
|
|
|
177
|
+
// TODO: ----- ADD TICKET TO PASS TRACE ID to this.dataloader.load
|
|
201
178
|
}, {
|
|
202
179
|
key: "touchFiles",
|
|
203
180
|
value: function touchFiles(descriptors, collection, traceContext) {
|
|
@@ -234,7 +211,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
234
211
|
value: function () {
|
|
235
212
|
var _uploadExternal = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(url, collection, traceContext) {
|
|
236
213
|
var _this3 = this;
|
|
237
|
-
|
|
238
214
|
var uploadableFileUpfrontIds, id, occurrenceKey, subject, deferredBlob, preview, name, fileState;
|
|
239
215
|
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
240
216
|
while (1) {
|
|
@@ -257,19 +233,15 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
257
233
|
case 0:
|
|
258
234
|
_context2.next = 2;
|
|
259
235
|
return deferredBlob;
|
|
260
|
-
|
|
261
236
|
case 2:
|
|
262
237
|
blob = _context2.sent;
|
|
263
|
-
|
|
264
238
|
if (!blob) {
|
|
265
239
|
reject('Could not fetch the blob');
|
|
266
240
|
}
|
|
267
|
-
|
|
268
241
|
resolve({
|
|
269
242
|
value: blob,
|
|
270
243
|
origin: 'remote'
|
|
271
244
|
});
|
|
272
|
-
|
|
273
245
|
case 5:
|
|
274
246
|
case "end":
|
|
275
247
|
return _context2.stop();
|
|
@@ -277,13 +249,11 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
277
249
|
}
|
|
278
250
|
}, _callee2);
|
|
279
251
|
}));
|
|
280
|
-
|
|
281
252
|
return function (_x4, _x5) {
|
|
282
253
|
return _ref3.apply(this, arguments);
|
|
283
254
|
};
|
|
284
255
|
}());
|
|
285
256
|
name = url.split('/').pop() || ''; // we create a initial fileState with the minimum info that we have at this point
|
|
286
|
-
|
|
287
257
|
fileState = {
|
|
288
258
|
status: 'processing',
|
|
289
259
|
name: name,
|
|
@@ -294,8 +264,8 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
294
264
|
occurrenceKey: occurrenceKey,
|
|
295
265
|
preview: preview
|
|
296
266
|
};
|
|
297
|
-
subject.next(fileState);
|
|
298
|
-
|
|
267
|
+
subject.next(fileState);
|
|
268
|
+
// we save it into the cache as soon as possible, in case someone subscribes
|
|
299
269
|
getFileStreamsCache().set(id, subject);
|
|
300
270
|
return _context4.abrupt("return", new Promise( /*#__PURE__*/function () {
|
|
301
271
|
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(resolve, reject) {
|
|
@@ -306,17 +276,13 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
306
276
|
case 0:
|
|
307
277
|
_context3.next = 2;
|
|
308
278
|
return deferredBlob;
|
|
309
|
-
|
|
310
279
|
case 2:
|
|
311
280
|
blob = _context3.sent;
|
|
312
|
-
|
|
313
281
|
if (blob) {
|
|
314
282
|
_context3.next = 5;
|
|
315
283
|
break;
|
|
316
284
|
}
|
|
317
|
-
|
|
318
285
|
return _context3.abrupt("return", reject('Could not download remote file'));
|
|
319
|
-
|
|
320
286
|
case 5:
|
|
321
287
|
type = blob.type, size = blob.size;
|
|
322
288
|
file = {
|
|
@@ -326,7 +292,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
326
292
|
name: name
|
|
327
293
|
};
|
|
328
294
|
mediaType = getMediaTypeFromMimeType(type); // we emit a richer state after the blob is fetched
|
|
329
|
-
|
|
330
295
|
subject.next({
|
|
331
296
|
status: 'processing',
|
|
332
297
|
name: name,
|
|
@@ -336,20 +301,17 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
336
301
|
id: id,
|
|
337
302
|
occurrenceKey: occurrenceKey,
|
|
338
303
|
preview: preview
|
|
339
|
-
});
|
|
340
|
-
|
|
304
|
+
});
|
|
305
|
+
// we don't want to wait for the file to be upload
|
|
341
306
|
_this3.upload(file, undefined, uploadableFileUpfrontIds, traceContext);
|
|
342
|
-
|
|
343
307
|
_context3.next = 12;
|
|
344
308
|
return getDimensionsFromBlob(mediaType, blob);
|
|
345
|
-
|
|
346
309
|
case 12:
|
|
347
310
|
dimensions = _context3.sent;
|
|
348
311
|
resolve({
|
|
349
312
|
dimensions: dimensions,
|
|
350
313
|
uploadableFileUpfrontIds: uploadableFileUpfrontIds
|
|
351
314
|
});
|
|
352
|
-
|
|
353
315
|
case 14:
|
|
354
316
|
case "end":
|
|
355
317
|
return _context3.stop();
|
|
@@ -357,12 +319,10 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
357
319
|
}
|
|
358
320
|
}, _callee3);
|
|
359
321
|
}));
|
|
360
|
-
|
|
361
322
|
return function (_x6, _x7) {
|
|
362
323
|
return _ref4.apply(this, arguments);
|
|
363
324
|
};
|
|
364
325
|
}()));
|
|
365
|
-
|
|
366
326
|
case 10:
|
|
367
327
|
case "end":
|
|
368
328
|
return _context4.stop();
|
|
@@ -370,27 +330,24 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
370
330
|
}
|
|
371
331
|
}, _callee4, this);
|
|
372
332
|
}));
|
|
373
|
-
|
|
374
333
|
function uploadExternal(_x, _x2, _x3) {
|
|
375
334
|
return _uploadExternal.apply(this, arguments);
|
|
376
335
|
}
|
|
377
|
-
|
|
378
336
|
return uploadExternal;
|
|
379
337
|
}()
|
|
380
338
|
}, {
|
|
381
339
|
key: "uploadAwlaysPullFileStates",
|
|
382
|
-
value:
|
|
340
|
+
value:
|
|
341
|
+
// TODO: make this the public upload method when the FF is removed
|
|
383
342
|
function uploadAwlaysPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext) {
|
|
384
343
|
var _this4 = this;
|
|
385
|
-
|
|
386
344
|
var collection = file.collection;
|
|
387
345
|
var upfrontId = uploadableFileUpfrontIds || this.generateUploadableFileUpfrontIds(collection, traceContext);
|
|
388
346
|
var id = upfrontId.id,
|
|
389
|
-
|
|
347
|
+
occurrenceKey = upfrontId.occurrenceKey;
|
|
390
348
|
var stateBase = this.getUploadingFileStateBase(file, upfrontId);
|
|
391
349
|
var subject = createMediaSubject();
|
|
392
350
|
getFileStreamsCache().set(id, subject);
|
|
393
|
-
|
|
394
351
|
var onProgress = function onProgress(progress) {
|
|
395
352
|
subject.next(_objectSpread(_objectSpread({
|
|
396
353
|
status: 'uploading'
|
|
@@ -398,33 +355,29 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
398
355
|
progress: progress
|
|
399
356
|
}));
|
|
400
357
|
};
|
|
401
|
-
|
|
402
358
|
var processingSubscription = new Subscription();
|
|
403
|
-
|
|
404
359
|
var onUploadFinish = function onUploadFinish(error) {
|
|
405
360
|
if (error) {
|
|
406
361
|
return subject.error(error);
|
|
407
362
|
}
|
|
408
|
-
|
|
409
363
|
processingSubscription = _this4.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(function (remoteFileState) {
|
|
410
364
|
return _objectSpread(_objectSpread(_objectSpread({}, stateBase), remoteFileState), overrideMediaTypeIfUnknown(remoteFileState, stateBase.mediaType));
|
|
411
365
|
})).subscribe(subject);
|
|
412
366
|
};
|
|
413
|
-
|
|
414
367
|
var _uploadFile = uploadFile(file, this.mediaStore, upfrontId, {
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
368
|
+
onUploadFinish: onUploadFinish,
|
|
369
|
+
onProgress: onProgress
|
|
370
|
+
}, traceContext),
|
|
371
|
+
cancel = _uploadFile.cancel;
|
|
420
372
|
controller === null || controller === void 0 ? void 0 : controller.setAbort(function () {
|
|
421
|
-
cancel();
|
|
373
|
+
cancel();
|
|
374
|
+
// TODO: filestate should turn to "Aborted" or something.
|
|
422
375
|
// Consider canceling an upload that is already finished
|
|
423
|
-
|
|
424
376
|
processingSubscription.unsubscribe();
|
|
425
|
-
});
|
|
426
|
-
// (otherwise in newUploadService file-converting event will be emitted before files-added)
|
|
377
|
+
});
|
|
427
378
|
|
|
379
|
+
// We should report progress asynchronously, since this is what consumer expects
|
|
380
|
+
// (otherwise in newUploadService file-converting event will be emitted before files-added)
|
|
428
381
|
setTimeout(onProgress, 0, 0);
|
|
429
382
|
return fromObservable(subject);
|
|
430
383
|
}
|
|
@@ -432,34 +385,28 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
432
385
|
key: "uploadConditionallyPullFileStates",
|
|
433
386
|
value: function uploadConditionallyPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext) {
|
|
434
387
|
var _this5 = this;
|
|
435
|
-
|
|
436
388
|
if (typeof file.content === 'string') {
|
|
437
389
|
file.content = convertBase64ToBlob(file.content);
|
|
438
390
|
}
|
|
439
|
-
|
|
440
391
|
var content = file.content,
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
392
|
+
_file$name2 = file.name,
|
|
393
|
+
name = _file$name2 === void 0 ? '' : _file$name2,
|
|
394
|
+
collection = file.collection;
|
|
445
395
|
if (!uploadableFileUpfrontIds) {
|
|
446
396
|
uploadableFileUpfrontIds = this.generateUploadableFileUpfrontIds(collection, traceContext);
|
|
447
397
|
}
|
|
448
|
-
|
|
449
398
|
var id = uploadableFileUpfrontIds.id;
|
|
450
399
|
var occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
|
|
451
400
|
var mimeType = '';
|
|
452
401
|
var size = 0;
|
|
453
|
-
var preview;
|
|
454
|
-
|
|
402
|
+
var preview;
|
|
403
|
+
// TODO [MSW-796]: get file size for base64
|
|
455
404
|
var mediaType = getMediaTypeFromUploadableFile(file);
|
|
456
405
|
var subject = createMediaSubject();
|
|
457
406
|
var processingSubscription = new Subscription();
|
|
458
|
-
|
|
459
407
|
if (content instanceof Blob) {
|
|
460
408
|
size = content.size;
|
|
461
409
|
mimeType = content.type;
|
|
462
|
-
|
|
463
410
|
if (isMimeTypeSupportedByBrowser(content.type)) {
|
|
464
411
|
preview = {
|
|
465
412
|
value: content,
|
|
@@ -467,7 +414,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
467
414
|
};
|
|
468
415
|
}
|
|
469
416
|
}
|
|
470
|
-
|
|
471
417
|
var stateBase = {
|
|
472
418
|
id: id,
|
|
473
419
|
occurrenceKey: occurrenceKey,
|
|
@@ -477,7 +423,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
477
423
|
mimeType: mimeType,
|
|
478
424
|
preview: preview
|
|
479
425
|
};
|
|
480
|
-
|
|
481
426
|
var onProgress = function onProgress(progress) {
|
|
482
427
|
subject.next(_objectSpread(_objectSpread({
|
|
483
428
|
status: 'uploading'
|
|
@@ -485,68 +430,61 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
485
430
|
progress: progress
|
|
486
431
|
}));
|
|
487
432
|
};
|
|
488
|
-
|
|
489
433
|
var onUploadFinish = function onUploadFinish(error) {
|
|
490
434
|
if (error) {
|
|
491
435
|
return subject.error(error);
|
|
492
436
|
}
|
|
493
|
-
|
|
494
437
|
processingSubscription.add(shouldFetchRemoteFileStatesObservable(mediaType, mimeType, preview).pipe(concatMap(function (shouldFetchRemoteFileStates) {
|
|
495
438
|
if (shouldFetchRemoteFileStates) {
|
|
496
439
|
return _this5.createDownloadFileStream(id, collection, occurrenceKey).pipe(map(function (remoteFileState) {
|
|
497
440
|
return _objectSpread(_objectSpread(_objectSpread({}, stateBase), remoteFileState), overrideMediaTypeIfUnknown(remoteFileState, mediaType));
|
|
498
441
|
}));
|
|
499
442
|
}
|
|
500
|
-
|
|
501
443
|
return of(_objectSpread({
|
|
502
444
|
status: 'processing',
|
|
503
445
|
representations: {}
|
|
504
446
|
}, stateBase));
|
|
505
447
|
})).subscribe(subject));
|
|
506
448
|
};
|
|
507
|
-
|
|
508
449
|
var _uploadFile2 = uploadFile(file, this.mediaStore, uploadableFileUpfrontIds, {
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
450
|
+
onUploadFinish: onUploadFinish,
|
|
451
|
+
onProgress: onProgress
|
|
452
|
+
}, traceContext),
|
|
453
|
+
cancel = _uploadFile2.cancel;
|
|
454
|
+
getFileStreamsCache().set(id, subject);
|
|
513
455
|
|
|
514
|
-
|
|
456
|
+
// We should report progress asynchronously, since this is what consumer expects
|
|
515
457
|
// (otherwise in newUploadService file-converting event will be emitted before files-added)
|
|
516
|
-
|
|
517
458
|
setTimeout(function () {
|
|
518
459
|
onProgress(0);
|
|
519
460
|
}, 0);
|
|
520
|
-
|
|
521
461
|
if (controller) {
|
|
522
462
|
controller.setAbort(function () {
|
|
523
463
|
cancel();
|
|
524
464
|
processingSubscription.unsubscribe();
|
|
525
465
|
});
|
|
526
466
|
}
|
|
527
|
-
|
|
528
467
|
return fromObservable(subject);
|
|
529
468
|
}
|
|
530
469
|
}, {
|
|
531
470
|
key: "upload",
|
|
532
471
|
value: function upload(file, controller, uploadableFileUpfrontIds, traceContext) {
|
|
533
472
|
var shouldAlwaysFetchFileState = getMediaFeatureFlag('fetchFileStateAfterUpload', this.featureFlags);
|
|
534
|
-
|
|
535
473
|
if (shouldAlwaysFetchFileState) {
|
|
536
474
|
return this.uploadAwlaysPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext);
|
|
537
475
|
}
|
|
538
|
-
|
|
539
476
|
return this.uploadConditionallyPullFileStates(file, controller, uploadableFileUpfrontIds, traceContext);
|
|
540
|
-
}
|
|
477
|
+
}
|
|
541
478
|
|
|
479
|
+
// TODO: ----- ADD TICKET
|
|
542
480
|
}, {
|
|
543
481
|
key: "downloadBinary",
|
|
544
482
|
value: function () {
|
|
545
483
|
var _downloadBinary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(id) {
|
|
546
484
|
var name,
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
485
|
+
collectionName,
|
|
486
|
+
url,
|
|
487
|
+
_args5 = arguments;
|
|
550
488
|
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
551
489
|
while (1) {
|
|
552
490
|
switch (_context5.prev = _context5.next) {
|
|
@@ -555,7 +493,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
555
493
|
collectionName = _args5.length > 2 ? _args5[2] : undefined;
|
|
556
494
|
_context5.next = 4;
|
|
557
495
|
return this.mediaStore.getFileBinaryURL(id, collectionName);
|
|
558
|
-
|
|
559
496
|
case 4:
|
|
560
497
|
url = _context5.sent;
|
|
561
498
|
downloadUrl(url, {
|
|
@@ -566,7 +503,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
566
503
|
isUserCollection: collectionName === RECENTS_COLLECTION,
|
|
567
504
|
viewingLevel: 'download'
|
|
568
505
|
});
|
|
569
|
-
|
|
570
506
|
case 7:
|
|
571
507
|
case "end":
|
|
572
508
|
return _context5.stop();
|
|
@@ -574,11 +510,9 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
574
510
|
}
|
|
575
511
|
}, _callee5, this);
|
|
576
512
|
}));
|
|
577
|
-
|
|
578
513
|
function downloadBinary(_x8) {
|
|
579
514
|
return _downloadBinary.apply(this, arguments);
|
|
580
515
|
}
|
|
581
|
-
|
|
582
516
|
return downloadBinary;
|
|
583
517
|
}()
|
|
584
518
|
}, {
|
|
@@ -586,35 +520,34 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
586
520
|
value: function () {
|
|
587
521
|
var _copyFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(source, destination) {
|
|
588
522
|
var options,
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
523
|
+
traceContext,
|
|
524
|
+
authProvider,
|
|
525
|
+
sourceCollection,
|
|
526
|
+
id,
|
|
527
|
+
destinationAuthProvider,
|
|
528
|
+
destinationCollectionName,
|
|
529
|
+
replaceFileId,
|
|
530
|
+
occurrenceKey,
|
|
531
|
+
preview,
|
|
532
|
+
mimeType,
|
|
533
|
+
mediaStore,
|
|
534
|
+
owner,
|
|
535
|
+
body,
|
|
536
|
+
params,
|
|
537
|
+
cache,
|
|
538
|
+
processingSubscription,
|
|
539
|
+
_yield$mediaStore$cop,
|
|
540
|
+
copiedFile,
|
|
541
|
+
copiedFileWithMimeType,
|
|
542
|
+
copiedId,
|
|
543
|
+
copiedMimeType,
|
|
544
|
+
mediaType,
|
|
545
|
+
copiedFileState,
|
|
546
|
+
fileCache,
|
|
547
|
+
subject,
|
|
548
|
+
previewOverride,
|
|
549
|
+
_fileCache,
|
|
550
|
+
_args6 = arguments;
|
|
618
551
|
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
619
552
|
while (1) {
|
|
620
553
|
switch (_context6.prev = _context6.next) {
|
|
@@ -632,7 +565,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
632
565
|
return authProvider({
|
|
633
566
|
collectionName: sourceCollection
|
|
634
567
|
});
|
|
635
|
-
|
|
636
568
|
case 9:
|
|
637
569
|
_context6.t1 = _context6.sent;
|
|
638
570
|
owner = (0, _context6.t0)(_context6.t1);
|
|
@@ -652,7 +584,6 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
652
584
|
_context6.prev = 14;
|
|
653
585
|
_context6.next = 17;
|
|
654
586
|
return mediaStore.copyFileWithToken(body, params, traceContext);
|
|
655
|
-
|
|
656
587
|
case 17:
|
|
657
588
|
_yield$mediaStore$cop = _context6.sent;
|
|
658
589
|
copiedFile = _yield$mediaStore$cop.data;
|
|
@@ -662,38 +593,32 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
662
593
|
} : undefined);
|
|
663
594
|
copiedId = copiedFileWithMimeType.id, copiedMimeType = copiedFileWithMimeType.mimeType; // backend may return an "unknown" mediaType just after the copy
|
|
664
595
|
// it's better to deduce it from "copiedMimeType" using getMediaTypeFromMimeType()
|
|
665
|
-
|
|
666
596
|
mediaType = copiedMimeType ? getMediaTypeFromMimeType(copiedMimeType) : 'unknown';
|
|
667
597
|
copiedFileState = mapMediaFileToFileState({
|
|
668
598
|
data: copiedFileWithMimeType
|
|
669
599
|
});
|
|
670
600
|
fileCache = cache.get(copiedId);
|
|
671
601
|
subject = fileCache || createMediaSubject(); // if we were passed a "preview", we propagate it into the copiedFileState
|
|
672
|
-
|
|
673
602
|
previewOverride = !isErrorFileState(copiedFileState) && !!preview ? {
|
|
674
603
|
preview: preview
|
|
675
604
|
} : {};
|
|
676
|
-
_context6.t2 = !isFinalFileState(copiedFileState) &&
|
|
605
|
+
_context6.t2 = !isFinalFileState(copiedFileState) &&
|
|
606
|
+
// mimeType should always be returned by "copyFileWithToken"
|
|
677
607
|
// but in case it's not, we don't want to penalize "copyFile"
|
|
678
608
|
copiedMimeType;
|
|
679
|
-
|
|
680
609
|
if (!_context6.t2) {
|
|
681
610
|
_context6.next = 31;
|
|
682
611
|
break;
|
|
683
612
|
}
|
|
684
|
-
|
|
685
613
|
_context6.next = 30;
|
|
686
614
|
return shouldFetchRemoteFileStates(mediaType, copiedMimeType, preview);
|
|
687
|
-
|
|
688
615
|
case 30:
|
|
689
616
|
_context6.t2 = _context6.sent;
|
|
690
|
-
|
|
691
617
|
case 31:
|
|
692
618
|
if (!_context6.t2) {
|
|
693
619
|
_context6.next = 36;
|
|
694
620
|
break;
|
|
695
621
|
}
|
|
696
|
-
|
|
697
622
|
subject.next(_objectSpread(_objectSpread(_objectSpread({}, copiedFileState), overrideMediaTypeIfUnknown(copiedFileState, mediaType)), previewOverride));
|
|
698
623
|
processingSubscription = this.createDownloadFileStream(copiedId, destinationCollectionName, occurrenceKey).subscribe({
|
|
699
624
|
next: function next(remoteFileState) {
|
|
@@ -708,30 +633,23 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
708
633
|
});
|
|
709
634
|
_context6.next = 37;
|
|
710
635
|
break;
|
|
711
|
-
|
|
712
636
|
case 36:
|
|
713
637
|
if (!isProcessingFileState(copiedFileState)) {
|
|
714
638
|
subject.next(_objectSpread(_objectSpread({}, copiedFileState), !isErrorFileState(copiedFileState) && previewOverride));
|
|
715
639
|
}
|
|
716
|
-
|
|
717
640
|
case 37:
|
|
718
641
|
if (!cache.has(copiedId)) {
|
|
719
642
|
getFileStreamsCache().set(copiedId, subject);
|
|
720
643
|
}
|
|
721
|
-
|
|
722
644
|
return _context6.abrupt("return", copiedFile);
|
|
723
|
-
|
|
724
645
|
case 41:
|
|
725
646
|
_context6.prev = 41;
|
|
726
647
|
_context6.t3 = _context6["catch"](14);
|
|
727
|
-
|
|
728
648
|
if (processingSubscription) {
|
|
729
649
|
processingSubscription.unsubscribe();
|
|
730
650
|
}
|
|
731
|
-
|
|
732
651
|
if (replaceFileId) {
|
|
733
652
|
_fileCache = cache.get(replaceFileId);
|
|
734
|
-
|
|
735
653
|
if (_fileCache) {
|
|
736
654
|
_fileCache.error(_context6.t3);
|
|
737
655
|
} else {
|
|
@@ -739,9 +657,7 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
739
657
|
cache.set(id, createMediaSubject(_context6.t3));
|
|
740
658
|
}
|
|
741
659
|
}
|
|
742
|
-
|
|
743
660
|
throw _context6.t3;
|
|
744
|
-
|
|
745
661
|
case 46:
|
|
746
662
|
case "end":
|
|
747
663
|
return _context6.stop();
|
|
@@ -749,14 +665,11 @@ export var FileFetcherImpl = /*#__PURE__*/function () {
|
|
|
749
665
|
}
|
|
750
666
|
}, _callee6, this, [[14, 41]]);
|
|
751
667
|
}));
|
|
752
|
-
|
|
753
668
|
function copyFile(_x9, _x10) {
|
|
754
669
|
return _copyFile.apply(this, arguments);
|
|
755
670
|
}
|
|
756
|
-
|
|
757
671
|
return copyFile;
|
|
758
672
|
}()
|
|
759
673
|
}]);
|
|
760
|
-
|
|
761
674
|
return FileFetcherImpl;
|
|
762
675
|
}();
|