@atlaskit/media-client 16.0.1 → 17.1.1
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 +41 -0
- package/dist/cjs/client/collection-fetcher.js +4 -4
- package/dist/cjs/client/file-fetcher/index.js +5 -7
- package/dist/cjs/client/media-store/index.js +35 -16
- package/dist/cjs/constants.js +11 -2
- package/dist/cjs/index.js +2 -2
- package/dist/cjs/models/media.js +10 -2
- package/dist/cjs/uploader/calculateChunkSize.js +45 -0
- package/dist/cjs/uploader/error.js +67 -0
- package/dist/cjs/uploader/index.js +318 -0
- package/dist/cjs/utils/{toMediaSubscribable.js → mediaSubscribable/fromObservable.js} +4 -4
- package/dist/cjs/utils/mediaSubscribable/index.js +27 -0
- package/dist/cjs/utils/{mediaSubscribableToPromise.js → mediaSubscribable/toPromise.js} +3 -3
- package/dist/cjs/utils/mediaSubscribable/types.js +5 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/client/collection-fetcher.js +2 -2
- package/dist/es2019/client/file-fetcher/index.js +5 -6
- package/dist/es2019/client/media-store/index.js +16 -2
- package/dist/es2019/constants.js +5 -1
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/models/media.js +8 -1
- package/dist/es2019/uploader/calculateChunkSize.js +32 -0
- package/dist/es2019/uploader/error.js +30 -0
- package/dist/es2019/{uploader.js → uploader/index.js} +47 -10
- package/dist/es2019/utils/{toMediaSubscribable.js → mediaSubscribable/fromObservable.js} +3 -3
- package/dist/es2019/utils/mediaSubscribable/index.js +2 -0
- package/dist/es2019/utils/{mediaSubscribableToPromise.js → mediaSubscribable/toPromise.js} +1 -1
- package/dist/es2019/utils/mediaSubscribable/types.js +1 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/client/collection-fetcher.js +3 -3
- package/dist/esm/client/file-fetcher/index.js +6 -7
- package/dist/esm/client/media-client.js +1 -1
- package/dist/esm/client/media-store/index.js +36 -17
- package/dist/esm/client/media-store/resolveAuth.js +1 -1
- package/dist/esm/client/stargate-client.js +1 -1
- package/dist/esm/constants.js +5 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/models/media.js +8 -1
- package/dist/esm/uploader/calculateChunkSize.js +32 -0
- package/dist/esm/uploader/error.js +51 -0
- package/dist/esm/uploader/index.js +298 -0
- package/dist/esm/utils/createFileDataLoader.js +1 -1
- package/dist/esm/utils/getDimensionsFromBlob.js +1 -1
- package/dist/esm/utils/getVideoDimensionsFromBlob.js +1 -1
- package/dist/esm/utils/hashing/hasherCreator.js +1 -1
- package/dist/esm/utils/{toMediaSubscribable.js → mediaSubscribable/fromObservable.js} +3 -3
- package/dist/esm/utils/mediaSubscribable/index.js +2 -0
- package/dist/esm/utils/{mediaSubscribableToPromise.js → mediaSubscribable/toPromise.js} +1 -1
- package/dist/esm/utils/mediaSubscribable/types.js +1 -0
- package/dist/esm/utils/mobileUpload/helpers.js +1 -1
- package/dist/esm/utils/mobileUpload/stateMachine/index.js +1 -1
- package/dist/esm/utils/polling/index.js +1 -1
- package/dist/esm/utils/request/helpers.js +1 -1
- package/dist/esm/utils/request/index.js +1 -1
- package/dist/esm/utils/shouldFetchRemoteFileStates.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/client/collection-fetcher.d.ts +1 -1
- package/dist/types/client/file-fetcher/index.d.ts +1 -1
- package/dist/types/client/media-store/index.d.ts +9 -2
- package/dist/types/constants.d.ts +3 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/models/errors/types.d.ts +1 -1
- package/dist/types/models/media.d.ts +5 -0
- package/dist/types/uploader/calculateChunkSize.d.ts +11 -0
- package/dist/types/uploader/error.d.ts +29 -0
- package/dist/types/{uploader.d.ts → uploader/index.d.ts} +2 -2
- package/dist/types/utils/mediaSubscribable/fromObservable.d.ts +5 -0
- package/dist/types/utils/mediaSubscribable/index.d.ts +3 -0
- package/dist/types/utils/{mediaSubscribableToPromise.d.ts → mediaSubscribable/toPromise.d.ts} +3 -3
- package/dist/types/utils/mediaSubscribable/types.d.ts +16 -0
- package/dist/types/utils/safeUnsubscribe.d.ts +1 -1
- package/example-helpers/styles.ts +99 -0
- package/example-helpers/stylesWrapper.tsx +82 -0
- package/package.json +8 -7
- package/report.api.md +1389 -0
- package/dist/cjs/uploader.js +0 -210
- package/dist/esm/uploader.js +0 -194
- package/dist/types/utils/toMediaSubscribable.d.ts +0 -20
- package/example-helpers/styled.ts +0 -77
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.uploadFile = void 0;
|
|
9
|
+
|
|
10
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
+
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
|
+
|
|
14
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
|
+
|
|
16
|
+
var _chunkinator = require("@atlaskit/chunkinator");
|
|
17
|
+
|
|
18
|
+
var _from = require("rxjs/observable/from");
|
|
19
|
+
|
|
20
|
+
var _concatMap = require("rxjs/operators/concatMap");
|
|
21
|
+
|
|
22
|
+
var _hasherCreator = require("../utils/hashing/hasherCreator");
|
|
23
|
+
|
|
24
|
+
var _error = require("./error");
|
|
25
|
+
|
|
26
|
+
var _constants = require("../constants");
|
|
27
|
+
|
|
28
|
+
var _calculateChunkSize = require("./calculateChunkSize");
|
|
29
|
+
|
|
30
|
+
var _mediaCommon = require("@atlaskit/media-common");
|
|
31
|
+
|
|
32
|
+
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; }
|
|
33
|
+
|
|
34
|
+
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; }
|
|
35
|
+
|
|
36
|
+
var hashingFunction = /*#__PURE__*/function () {
|
|
37
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(blob) {
|
|
38
|
+
var hasher;
|
|
39
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
40
|
+
while (1) {
|
|
41
|
+
switch (_context.prev = _context.next) {
|
|
42
|
+
case 0:
|
|
43
|
+
_context.next = 2;
|
|
44
|
+
return (0, _hasherCreator.createHasher)();
|
|
45
|
+
|
|
46
|
+
case 2:
|
|
47
|
+
hasher = _context.sent;
|
|
48
|
+
return _context.abrupt("return", hasher.hash(blob));
|
|
49
|
+
|
|
50
|
+
case 4:
|
|
51
|
+
case "end":
|
|
52
|
+
return _context.stop();
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}, _callee);
|
|
56
|
+
}));
|
|
57
|
+
|
|
58
|
+
return function hashingFunction(_x) {
|
|
59
|
+
return _ref.apply(this, arguments);
|
|
60
|
+
};
|
|
61
|
+
}();
|
|
62
|
+
|
|
63
|
+
var createProbingFunction = function createProbingFunction(store, deferredUploadId, collectionName) {
|
|
64
|
+
return /*#__PURE__*/function () {
|
|
65
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(chunks) {
|
|
66
|
+
var response, results;
|
|
67
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
68
|
+
while (1) {
|
|
69
|
+
switch (_context2.prev = _context2.next) {
|
|
70
|
+
case 0:
|
|
71
|
+
_context2.t0 = store;
|
|
72
|
+
_context2.t1 = hashedChunks(chunks);
|
|
73
|
+
_context2.t2 = collectionName;
|
|
74
|
+
|
|
75
|
+
if (!(0, _mediaCommon.getMediaFeatureFlag)('mediaUploadApiV2', store.featureFlags)) {
|
|
76
|
+
_context2.next = 9;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
_context2.next = 6;
|
|
81
|
+
return deferredUploadId;
|
|
82
|
+
|
|
83
|
+
case 6:
|
|
84
|
+
_context2.t3 = _context2.sent;
|
|
85
|
+
_context2.next = 10;
|
|
86
|
+
break;
|
|
87
|
+
|
|
88
|
+
case 9:
|
|
89
|
+
_context2.t3 = undefined;
|
|
90
|
+
|
|
91
|
+
case 10:
|
|
92
|
+
_context2.t4 = _context2.t3;
|
|
93
|
+
_context2.t5 = {
|
|
94
|
+
collectionName: _context2.t2,
|
|
95
|
+
uploadId: _context2.t4
|
|
96
|
+
};
|
|
97
|
+
_context2.next = 14;
|
|
98
|
+
return _context2.t0.probeChunks.call(_context2.t0, _context2.t1, _context2.t5);
|
|
99
|
+
|
|
100
|
+
case 14:
|
|
101
|
+
response = _context2.sent;
|
|
102
|
+
results = response.data.results;
|
|
103
|
+
return _context2.abrupt("return", Object.values(results).map(function (result) {
|
|
104
|
+
return result.exists;
|
|
105
|
+
}));
|
|
106
|
+
|
|
107
|
+
case 17:
|
|
108
|
+
case "end":
|
|
109
|
+
return _context2.stop();
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}, _callee2);
|
|
113
|
+
}));
|
|
114
|
+
|
|
115
|
+
return function (_x2) {
|
|
116
|
+
return _ref2.apply(this, arguments);
|
|
117
|
+
};
|
|
118
|
+
}();
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
var createUploadingFunction = function createUploadingFunction(store, deferredUploadId, collectionName) {
|
|
122
|
+
return /*#__PURE__*/function () {
|
|
123
|
+
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(chunk) {
|
|
124
|
+
var options;
|
|
125
|
+
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
126
|
+
while (1) {
|
|
127
|
+
switch (_context3.prev = _context3.next) {
|
|
128
|
+
case 0:
|
|
129
|
+
if (!(0, _mediaCommon.getMediaFeatureFlag)('mediaUploadApiV2', store.featureFlags)) {
|
|
130
|
+
_context3.next = 8;
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
_context3.t1 = chunk.partNumber;
|
|
135
|
+
_context3.next = 4;
|
|
136
|
+
return deferredUploadId;
|
|
137
|
+
|
|
138
|
+
case 4:
|
|
139
|
+
_context3.t2 = _context3.sent;
|
|
140
|
+
_context3.t0 = {
|
|
141
|
+
partNumber: _context3.t1,
|
|
142
|
+
uploadId: _context3.t2
|
|
143
|
+
};
|
|
144
|
+
_context3.next = 9;
|
|
145
|
+
break;
|
|
146
|
+
|
|
147
|
+
case 8:
|
|
148
|
+
_context3.t0 = {};
|
|
149
|
+
|
|
150
|
+
case 9:
|
|
151
|
+
options = _context3.t0;
|
|
152
|
+
_context3.next = 12;
|
|
153
|
+
return store.uploadChunk(chunk.hash, chunk.blob, _objectSpread({
|
|
154
|
+
collectionName: collectionName
|
|
155
|
+
}, options));
|
|
156
|
+
|
|
157
|
+
case 12:
|
|
158
|
+
return _context3.abrupt("return", _context3.sent);
|
|
159
|
+
|
|
160
|
+
case 13:
|
|
161
|
+
case "end":
|
|
162
|
+
return _context3.stop();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}, _callee3);
|
|
166
|
+
}));
|
|
167
|
+
|
|
168
|
+
return function (_x3) {
|
|
169
|
+
return _ref3.apply(this, arguments);
|
|
170
|
+
};
|
|
171
|
+
}();
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
var createProcessingFunction = function createProcessingFunction(store, deferredUploadId, collection) {
|
|
175
|
+
var offset = 0;
|
|
176
|
+
return /*#__PURE__*/function () {
|
|
177
|
+
var _ref4 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(chunks) {
|
|
178
|
+
return _regenerator.default.wrap(function _callee4$(_context4) {
|
|
179
|
+
while (1) {
|
|
180
|
+
switch (_context4.prev = _context4.next) {
|
|
181
|
+
case 0:
|
|
182
|
+
_context4.t0 = store;
|
|
183
|
+
_context4.next = 3;
|
|
184
|
+
return deferredUploadId;
|
|
185
|
+
|
|
186
|
+
case 3:
|
|
187
|
+
_context4.t1 = _context4.sent;
|
|
188
|
+
_context4.t2 = {
|
|
189
|
+
chunks: hashedChunks(chunks),
|
|
190
|
+
offset: offset
|
|
191
|
+
};
|
|
192
|
+
_context4.t3 = collection;
|
|
193
|
+
_context4.next = 8;
|
|
194
|
+
return _context4.t0.appendChunksToUpload.call(_context4.t0, _context4.t1, _context4.t2, _context4.t3);
|
|
195
|
+
|
|
196
|
+
case 8:
|
|
197
|
+
offset += chunks.length;
|
|
198
|
+
|
|
199
|
+
case 9:
|
|
200
|
+
case "end":
|
|
201
|
+
return _context4.stop();
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}, _callee4);
|
|
205
|
+
}));
|
|
206
|
+
|
|
207
|
+
return function (_x4) {
|
|
208
|
+
return _ref4.apply(this, arguments);
|
|
209
|
+
};
|
|
210
|
+
}();
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
var createFileFromUpload = /*#__PURE__*/function () {
|
|
214
|
+
var _ref5 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5(file, store, uploadableFileUpfrontIds, uploadId) {
|
|
215
|
+
var collection, name, mimeType, id, occurrenceKey;
|
|
216
|
+
return _regenerator.default.wrap(function _callee5$(_context5) {
|
|
217
|
+
while (1) {
|
|
218
|
+
switch (_context5.prev = _context5.next) {
|
|
219
|
+
case 0:
|
|
220
|
+
collection = file.collection, name = file.name, mimeType = file.mimeType;
|
|
221
|
+
id = uploadableFileUpfrontIds.id, occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
|
|
222
|
+
return _context5.abrupt("return", store.createFileFromUpload({
|
|
223
|
+
uploadId: uploadId,
|
|
224
|
+
name: name,
|
|
225
|
+
mimeType: mimeType
|
|
226
|
+
}, {
|
|
227
|
+
occurrenceKey: occurrenceKey,
|
|
228
|
+
collection: collection,
|
|
229
|
+
replaceFileId: id
|
|
230
|
+
}));
|
|
231
|
+
|
|
232
|
+
case 3:
|
|
233
|
+
case "end":
|
|
234
|
+
return _context5.stop();
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}, _callee5);
|
|
238
|
+
}));
|
|
239
|
+
|
|
240
|
+
return function createFileFromUpload(_x5, _x6, _x7, _x8) {
|
|
241
|
+
return _ref5.apply(this, arguments);
|
|
242
|
+
};
|
|
243
|
+
}();
|
|
244
|
+
|
|
245
|
+
var uploadFile = function uploadFile(file, store, uploadableFileUpfrontIds, callbacks) {
|
|
246
|
+
var content = file.content,
|
|
247
|
+
collection = file.collection;
|
|
248
|
+
var deferredUploadId = uploadableFileUpfrontIds.deferredUploadId,
|
|
249
|
+
id = uploadableFileUpfrontIds.id,
|
|
250
|
+
occurrenceKey = uploadableFileUpfrontIds.occurrenceKey;
|
|
251
|
+
var chunkSize = _constants.CHUNK_SIZE;
|
|
252
|
+
|
|
253
|
+
try {
|
|
254
|
+
if (content instanceof Blob && (0, _mediaCommon.getMediaFeatureFlag)('mediaUploadApiV2', store.featureFlags)) {
|
|
255
|
+
chunkSize = (0, _calculateChunkSize.calculateChunkSize)(content.size);
|
|
256
|
+
}
|
|
257
|
+
} catch (err) {
|
|
258
|
+
if (err instanceof Error && err.message === _calculateChunkSize.fileSizeError) {
|
|
259
|
+
callbacks === null || callbacks === void 0 ? void 0 : callbacks.onUploadFinish(new _error.UploaderError(err.message, id, {
|
|
260
|
+
collectionName: collection,
|
|
261
|
+
occurrenceKey: occurrenceKey
|
|
262
|
+
}));
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return {
|
|
266
|
+
cancel: function cancel() {
|
|
267
|
+
callbacks === null || callbacks === void 0 ? void 0 : callbacks.onUploadFinish('canceled');
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
var chunkinatorObservable = (0, _chunkinator.chunkinator)(content, {
|
|
273
|
+
hashingFunction: hashingFunction,
|
|
274
|
+
hashingConcurrency: 5,
|
|
275
|
+
probingBatchSize: 100,
|
|
276
|
+
chunkSize: chunkSize,
|
|
277
|
+
uploadingConcurrency: 3,
|
|
278
|
+
uploadingFunction: createUploadingFunction(store, deferredUploadId, collection),
|
|
279
|
+
probingFunction: createProbingFunction(store, deferredUploadId, collection),
|
|
280
|
+
processingBatchSize: _constants.PROCESSING_BATCH_SIZE,
|
|
281
|
+
processingFunction: createProcessingFunction(store, deferredUploadId, collection)
|
|
282
|
+
}, {
|
|
283
|
+
onProgress: function onProgress(progress) {
|
|
284
|
+
if (callbacks) {
|
|
285
|
+
callbacks.onProgress(progress);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
var onUploadFinish = callbacks && callbacks.onUploadFinish || function () {};
|
|
291
|
+
|
|
292
|
+
var subscription = (0, _from.from)(deferredUploadId).pipe((0, _concatMap.concatMap)(function (uploadId) {
|
|
293
|
+
return chunkinatorObservable.pipe((0, _concatMap.concatMap)(function () {
|
|
294
|
+
return (0, _from.from)(createFileFromUpload(file, store, uploadableFileUpfrontIds, uploadId));
|
|
295
|
+
}));
|
|
296
|
+
})).subscribe({
|
|
297
|
+
error: function error(err) {
|
|
298
|
+
return onUploadFinish(err);
|
|
299
|
+
},
|
|
300
|
+
complete: function complete() {
|
|
301
|
+
return onUploadFinish();
|
|
302
|
+
}
|
|
303
|
+
});
|
|
304
|
+
return {
|
|
305
|
+
cancel: function cancel() {
|
|
306
|
+
subscription.unsubscribe();
|
|
307
|
+
onUploadFinish('canceled');
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
exports.uploadFile = uploadFile;
|
|
313
|
+
|
|
314
|
+
var hashedChunks = function hashedChunks(chunks) {
|
|
315
|
+
return chunks.map(function (chunk) {
|
|
316
|
+
return chunk.hash;
|
|
317
|
+
});
|
|
318
|
+
};
|
|
@@ -4,11 +4,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createMediaSubscribable = createMediaSubscribable;
|
|
7
|
-
exports.
|
|
7
|
+
exports.fromObservable = fromObservable;
|
|
8
8
|
|
|
9
|
-
var _createMediaSubject = require("
|
|
9
|
+
var _createMediaSubject = require("../createMediaSubject");
|
|
10
10
|
|
|
11
|
-
function
|
|
11
|
+
function fromObservable(observable) {
|
|
12
12
|
return {
|
|
13
13
|
subscribe: function subscribe(observer) {
|
|
14
14
|
var subscription = // This is needed to handle "subscribe" function overload.
|
|
@@ -24,5 +24,5 @@ function toMediaSubscribable(observable) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
function createMediaSubscribable(mediaSubscribableItem) {
|
|
27
|
-
return
|
|
27
|
+
return fromObservable((0, _createMediaSubject.createMediaSubject)(mediaSubscribableItem));
|
|
28
28
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "createMediaSubscribable", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _fromObservable.createMediaSubscribable;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "fromObservable", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function get() {
|
|
15
|
+
return _fromObservable.fromObservable;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "toPromise", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function get() {
|
|
21
|
+
return _toPromise.toPromise;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
var _toPromise = require("./toPromise");
|
|
26
|
+
|
|
27
|
+
var _fromObservable = require("./fromObservable");
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.toPromise = void 0;
|
|
7
7
|
|
|
8
8
|
var _Subscription = require("rxjs/Subscription");
|
|
9
9
|
|
|
@@ -13,7 +13,7 @@ var _Subscription = require("rxjs/Subscription");
|
|
|
13
13
|
* @param mediaSubscribable a given MediaSubscribable<MediaSubscribableItem>
|
|
14
14
|
* @param subscription a default Subscription (this parameter exists for testing purpose)
|
|
15
15
|
*/
|
|
16
|
-
var
|
|
16
|
+
var toPromise = function toPromise(mediaSubscribable) {
|
|
17
17
|
var subscription = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _Subscription.Subscription();
|
|
18
18
|
return new Promise(function (resolve, reject) {
|
|
19
19
|
return subscription.add(mediaSubscribable.subscribe({
|
|
@@ -29,4 +29,4 @@ var mediaSubscribableToPromise = function mediaSubscribableToPromise(mediaSubscr
|
|
|
29
29
|
});
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
exports.
|
|
32
|
+
exports.toPromise = toPromise;
|
package/dist/cjs/version.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ReplaySubject } from 'rxjs/ReplaySubject';
|
|
2
2
|
import { getFileStreamsCache } from '../file-streams-cache';
|
|
3
3
|
import { mapMediaFileToFileState } from '../models/file-state';
|
|
4
|
-
import {
|
|
4
|
+
import { fromObservable } from '../utils/mediaSubscribable';
|
|
5
5
|
export const collectionCache = {};
|
|
6
6
|
|
|
7
7
|
const createCacheEntry = () => ({
|
|
@@ -67,7 +67,7 @@ export class CollectionFetcher {
|
|
|
67
67
|
collection.nextInclusiveStartKey = nextInclusiveStartKey;
|
|
68
68
|
subject.next(collection.items);
|
|
69
69
|
}).catch(error => subject.error(error));
|
|
70
|
-
return
|
|
70
|
+
return fromObservable(subject);
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
async removeFile(id, collectionName, occurrenceKey) {
|
|
@@ -21,14 +21,13 @@ import { createFileDataloader } from '../../utils/createFileDataLoader';
|
|
|
21
21
|
import { getMediaTypeFromUploadableFile } from '../../utils/getMediaTypeFromUploadableFile';
|
|
22
22
|
import { overrideMediaTypeIfUnknown } from '../../utils/overrideMediaTypeIfUnknown';
|
|
23
23
|
import { convertBase64ToBlob } from '../../utils/convertBase64ToBlob';
|
|
24
|
-
import {
|
|
24
|
+
import { toPromise, fromObservable } from '../../utils/mediaSubscribable';
|
|
25
25
|
import { getDimensionsFromBlob } from '../../utils/getDimensionsFromBlob';
|
|
26
26
|
import { createMediaSubject } from '../../utils/createMediaSubject';
|
|
27
27
|
import { isMimeTypeSupportedByBrowser, getMediaTypeFromMimeType } from '@atlaskit/media-common/mediaTypeUtils';
|
|
28
28
|
import { shouldFetchRemoteFileStates, shouldFetchRemoteFileStatesObservable } from '../../utils/shouldFetchRemoteFileStates';
|
|
29
29
|
import { PollingFunction } from '../../utils/polling';
|
|
30
30
|
import { isEmptyFile } from '../../utils/detectEmptyFile';
|
|
31
|
-
import { toMediaSubscribable } from '../../utils/toMediaSubscribable';
|
|
32
31
|
export { isFileFetcherError, FileFetcherError } from './error';
|
|
33
32
|
export class FileFetcherImpl {
|
|
34
33
|
constructor(mediaStore) {
|
|
@@ -91,14 +90,14 @@ export class FileFetcherImpl {
|
|
|
91
90
|
collectionName,
|
|
92
91
|
occurrenceKey
|
|
93
92
|
}));
|
|
94
|
-
return
|
|
93
|
+
return fromObservable(subject);
|
|
95
94
|
}
|
|
96
95
|
|
|
97
|
-
return
|
|
96
|
+
return fromObservable(getFileStreamsCache().getOrInsert(id, () => this.createDownloadFileStream(id, collectionName)));
|
|
98
97
|
}
|
|
99
98
|
|
|
100
99
|
getCurrentState(id, options) {
|
|
101
|
-
return
|
|
100
|
+
return toPromise(this.getFileState(id, options));
|
|
102
101
|
}
|
|
103
102
|
|
|
104
103
|
getArtifactURL(artifacts, artifactName, collectionName) {
|
|
@@ -307,7 +306,7 @@ export class FileFetcherImpl {
|
|
|
307
306
|
});
|
|
308
307
|
}
|
|
309
308
|
|
|
310
|
-
return
|
|
309
|
+
return fromObservable(subject);
|
|
311
310
|
}
|
|
312
311
|
|
|
313
312
|
async downloadBinary(id, name = 'download', collectionName) {
|
|
@@ -122,12 +122,20 @@ export class MediaStore {
|
|
|
122
122
|
return this.request(`/upload`, options).then(createMapResponseToJson(metadata));
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
async uploadChunk(etag, blob,
|
|
125
|
+
async uploadChunk(etag, blob, {
|
|
126
|
+
collectionName,
|
|
127
|
+
uploadId,
|
|
128
|
+
partNumber
|
|
129
|
+
} = {}) {
|
|
126
130
|
const metadata = {
|
|
127
131
|
method: 'PUT',
|
|
128
132
|
endpoint: '/chunk/{etag}'
|
|
129
133
|
};
|
|
130
134
|
const options = { ...metadata,
|
|
135
|
+
params: {
|
|
136
|
+
uploadId,
|
|
137
|
+
partNumber
|
|
138
|
+
},
|
|
131
139
|
authContext: {
|
|
132
140
|
collectionName
|
|
133
141
|
},
|
|
@@ -136,12 +144,18 @@ export class MediaStore {
|
|
|
136
144
|
await this.request(`/chunk/${etag}`, options);
|
|
137
145
|
}
|
|
138
146
|
|
|
139
|
-
probeChunks(chunks,
|
|
147
|
+
probeChunks(chunks, {
|
|
148
|
+
collectionName,
|
|
149
|
+
uploadId
|
|
150
|
+
} = {}) {
|
|
140
151
|
const metadata = {
|
|
141
152
|
method: 'POST',
|
|
142
153
|
endpoint: '/chunk/probe'
|
|
143
154
|
};
|
|
144
155
|
const options = { ...metadata,
|
|
156
|
+
params: {
|
|
157
|
+
uploadId
|
|
158
|
+
},
|
|
145
159
|
authContext: {
|
|
146
160
|
collectionName
|
|
147
161
|
},
|
package/dist/es2019/constants.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
+
import { DATA_UNIT } from './models/media';
|
|
1
2
|
export const RECENTS_COLLECTION = 'recents';
|
|
2
3
|
export const FILE_CACHE_MAX_AGE = 60 * 60 * 24 * 30; // Retain for 30 days
|
|
3
4
|
|
|
4
|
-
export const MAX_RESOLUTION = 4096;
|
|
5
|
+
export const MAX_RESOLUTION = 4096;
|
|
6
|
+
export const CHUNK_SIZE = 4 * DATA_UNIT.MB;
|
|
7
|
+
export const PROCESSING_BATCH_SIZE = 1000;
|
|
8
|
+
export const MAX_UPLOAD_FILE_SIZE = 2 * DATA_UNIT.TB;
|
package/dist/es2019/index.js
CHANGED
|
@@ -25,7 +25,7 @@ export { isFileIdentifier, isExternalImageIdentifier, isDifferentIdentifier } fr
|
|
|
25
25
|
export { withMediaClient, getMediaClient } from './utils/with-media-client-hoc';
|
|
26
26
|
export { globalMediaEventEmitter } from './globalMediaEventEmitter';
|
|
27
27
|
export { isMediaBlobUrl, getAttrsFromUrl, addFileAttrsToUrl, objectToQueryString } from './utils/url';
|
|
28
|
-
export { createMediaSubscribable } from './utils/
|
|
28
|
+
export { createMediaSubscribable } from './utils/mediaSubscribable';
|
|
29
29
|
export { RECENTS_COLLECTION, MAX_RESOLUTION } from './constants'; // TODO MEX-659 Remove these exports when all the usages from media-client are replaced with media-common.
|
|
30
30
|
|
|
31
31
|
import { getMediaTypeFromMimeType as _getMediaTypeFromMimeType, isImageMimeTypeSupportedByBrowser as _isImageMimeTypeSupportedByBrowser, isDocumentMimeTypeSupportedByBrowser as _isDocumentMimeTypeSupportedByBrowser, isMimeTypeSupportedByBrowser as _isMimeTypeSupportedByBrowser, isImageMimeTypeSupportedByServer as _isImageMimeTypeSupportedByServer, isDocumentMimeTypeSupportedByServer as _isDocumentMimeTypeSupportedByServer, isAudioMimeTypeSupportedByServer as _isAudioMimeTypeSupportedByServer, isVideoMimeTypeSupportedByServer as _isVideoMimeTypeSupportedByServer, isUnknownMimeTypeSupportedByServer as _isUnknownMimeTypeSupportedByServer, isMimeTypeSupportedByServer as _isMimeTypeSupportedByServer } from '@atlaskit/media-common/mediaTypeUtils';
|
|
@@ -9,4 +9,11 @@ export const isPreviewableType = (type, featureFlags) => {
|
|
|
9
9
|
|
|
10
10
|
return defaultPreviewableTypes.indexOf(type) > -1;
|
|
11
11
|
};
|
|
12
|
-
export const isMediaCollectionItemFullDetails = mediaCollectionItem => !!mediaCollectionItem['mediaType'] && !!mediaCollectionItem['mimeType'] && !!mediaCollectionItem['processingStatus'];
|
|
12
|
+
export const isMediaCollectionItemFullDetails = mediaCollectionItem => !!mediaCollectionItem['mediaType'] && !!mediaCollectionItem['mimeType'] && !!mediaCollectionItem['processingStatus'];
|
|
13
|
+
export let DATA_UNIT;
|
|
14
|
+
|
|
15
|
+
(function (DATA_UNIT) {
|
|
16
|
+
DATA_UNIT[DATA_UNIT["MB"] = 1048576] = "MB";
|
|
17
|
+
DATA_UNIT[DATA_UNIT["GB"] = 1073741824] = "GB";
|
|
18
|
+
DATA_UNIT[DATA_UNIT["TB"] = 1099511627776] = "TB";
|
|
19
|
+
})(DATA_UNIT || (DATA_UNIT = {}));
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { DATA_UNIT } from '../models/media';
|
|
2
|
+
import { MAX_UPLOAD_FILE_SIZE } from '../constants';
|
|
3
|
+
export const fileSizeError = 'fileSizeExceedsLimit';
|
|
4
|
+
/**
|
|
5
|
+
* This is a helper to dynamically calculate the chunk size for a given file size.
|
|
6
|
+
*
|
|
7
|
+
* @param fileSize The size of a file to calculate the chunk size for.
|
|
8
|
+
* @returns A number of bytes per chunk or Throws an Error if the file size exceeds 2TB
|
|
9
|
+
*
|
|
10
|
+
* @see {@link https://product-fabric.atlassian.net/wiki/spaces/FIL/pages/3221881143/Rule+of+thumb+for+chunk+sizes#Given-the-following-conditions}
|
|
11
|
+
*
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export const calculateChunkSize = fileSize => {
|
|
15
|
+
if (fileSize > MAX_UPLOAD_FILE_SIZE) {
|
|
16
|
+
throw new Error(fileSizeError);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (fileSize <= 5 * DATA_UNIT.GB) {
|
|
20
|
+
return 5 * DATA_UNIT.MB;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (fileSize > 5 * DATA_UNIT.GB && fileSize <= 50 * DATA_UNIT.GB) {
|
|
24
|
+
return 50 * DATA_UNIT.MB;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (fileSize > 50 * DATA_UNIT.GB && fileSize <= 0.95 * DATA_UNIT.TB) {
|
|
28
|
+
return 100 * DATA_UNIT.MB;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return 210 * DATA_UNIT.MB;
|
|
32
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { BaseMediaClientError } from '../models/errors';
|
|
2
|
+
export class UploaderError extends BaseMediaClientError {
|
|
3
|
+
constructor(reason, id, metadata) {
|
|
4
|
+
super(reason);
|
|
5
|
+
this.reason = reason;
|
|
6
|
+
this.id = id;
|
|
7
|
+
this.metadata = metadata;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
get attributes() {
|
|
11
|
+
const {
|
|
12
|
+
reason,
|
|
13
|
+
id,
|
|
14
|
+
metadata: {
|
|
15
|
+
collectionName,
|
|
16
|
+
occurrenceKey
|
|
17
|
+
} = {}
|
|
18
|
+
} = this;
|
|
19
|
+
return {
|
|
20
|
+
reason,
|
|
21
|
+
id,
|
|
22
|
+
collectionName,
|
|
23
|
+
occurrenceKey
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
export function isUploaderError(err) {
|
|
29
|
+
return err instanceof UploaderError;
|
|
30
|
+
}
|