@atlaskit/media-client 25.0.3 → 26.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/cjs/client/media-store/MediaStore.js +0 -22
- package/dist/cjs/test-helpers/MockedMediaApi/MockedMediaApi.js +432 -0
- package/dist/cjs/test-helpers/MockedMediaApi/helpers.js +184 -0
- package/dist/cjs/test-helpers/MockedMediaApi/index.js +55 -0
- package/dist/cjs/test-helpers/index.js +49 -0
- package/dist/cjs/uploader/index.js +36 -72
- package/dist/es2019/client/media-store/MediaStore.js +0 -21
- package/dist/es2019/test-helpers/MockedMediaApi/MockedMediaApi.js +161 -0
- package/dist/es2019/test-helpers/MockedMediaApi/helpers.js +166 -0
- package/dist/es2019/test-helpers/MockedMediaApi/index.js +2 -0
- package/dist/es2019/test-helpers/index.js +2 -1
- package/dist/es2019/uploader/index.js +0 -7
- package/dist/esm/client/media-store/MediaStore.js +0 -22
- package/dist/esm/test-helpers/MockedMediaApi/MockedMediaApi.js +425 -0
- package/dist/esm/test-helpers/MockedMediaApi/helpers.js +176 -0
- package/dist/esm/test-helpers/MockedMediaApi/index.js +2 -0
- package/dist/esm/test-helpers/index.js +2 -1
- package/dist/esm/uploader/index.js +36 -72
- package/dist/types/client/media-store/MediaStore.d.ts +1 -2
- package/dist/types/client/media-store/types.d.ts +1 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/models/media.d.ts +0 -7
- package/dist/types/test-helpers/MockedMediaApi/MockedMediaApi.d.ts +16 -0
- package/dist/types/test-helpers/MockedMediaApi/helpers.d.ts +23 -0
- package/dist/types/test-helpers/MockedMediaApi/index.d.ts +3 -0
- package/dist/types/test-helpers/index.d.ts +2 -0
- package/dist/types-ts4.5/client/media-store/MediaStore.d.ts +1 -2
- package/dist/types-ts4.5/client/media-store/types.d.ts +1 -2
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/models/media.d.ts +0 -7
- package/dist/types-ts4.5/test-helpers/MockedMediaApi/MockedMediaApi.d.ts +16 -0
- package/dist/types-ts4.5/test-helpers/MockedMediaApi/helpers.d.ts +23 -0
- package/dist/types-ts4.5/test-helpers/MockedMediaApi/index.d.ts +3 -0
- package/dist/types-ts4.5/test-helpers/index.d.ts +2 -0
- package/package.json +3 -3
- package/tmp/api-report-tmp.d.ts +0 -1199
|
@@ -12,11 +12,6 @@ const hashingFunction = async blob => {
|
|
|
12
12
|
const hasher = await createHasher();
|
|
13
13
|
return hasher.hash(blob);
|
|
14
14
|
};
|
|
15
|
-
const createProbingFunction = (store, deferredUploadId, collectionName, traceContext) => async chunks => {
|
|
16
|
-
const response = await store.probeChunks(hashedChunks(chunks), await deferredUploadId, collectionName, traceContext);
|
|
17
|
-
const results = response.data.results;
|
|
18
|
-
return Object.values(results).map(result => result.exists);
|
|
19
|
-
};
|
|
20
15
|
const createUploadingFunction = (store, deferredUploadId, collectionName, traceContext) => async chunk => {
|
|
21
16
|
return await store.uploadChunk(chunk.hash, chunk.blob, await deferredUploadId, chunk.partNumber, collectionName, traceContext);
|
|
22
17
|
};
|
|
@@ -89,11 +84,9 @@ export const uploadFile = (file, store, uploadableFileUpfrontIds, callbacks, tra
|
|
|
89
84
|
const chunkinatorObservable = chunkinator(content, {
|
|
90
85
|
hashingFunction,
|
|
91
86
|
hashingConcurrency: 5,
|
|
92
|
-
probingBatchSize: 100,
|
|
93
87
|
chunkSize,
|
|
94
88
|
uploadingConcurrency: 3,
|
|
95
89
|
uploadingFunction: createUploadingFunction(store, deferredUploadId, collection, traceContext),
|
|
96
|
-
probingFunction: createProbingFunction(store, deferredUploadId, collection, traceContext),
|
|
97
90
|
processingBatchSize: PROCESSING_BATCH_SIZE,
|
|
98
91
|
processingFunction: createProcessingFunction(store, deferredUploadId, collection, traceContext)
|
|
99
92
|
}, {
|
|
@@ -147,28 +147,6 @@ export var MediaStore = /*#__PURE__*/function () {
|
|
|
147
147
|
}
|
|
148
148
|
return uploadChunk;
|
|
149
149
|
}()
|
|
150
|
-
}, {
|
|
151
|
-
key: "probeChunks",
|
|
152
|
-
value: function probeChunks(chunks, uploadId, collectionName, traceContext) {
|
|
153
|
-
var metadata = {
|
|
154
|
-
method: 'POST',
|
|
155
|
-
endpoint: '/chunk/probe'
|
|
156
|
-
};
|
|
157
|
-
var options = _objectSpread(_objectSpread({}, metadata), {}, {
|
|
158
|
-
params: {
|
|
159
|
-
uploadId: uploadId
|
|
160
|
-
},
|
|
161
|
-
authContext: {
|
|
162
|
-
collectionName: collectionName
|
|
163
|
-
},
|
|
164
|
-
headers: jsonHeaders,
|
|
165
|
-
body: JSON.stringify({
|
|
166
|
-
chunks: chunks
|
|
167
|
-
}),
|
|
168
|
-
traceContext: traceContext
|
|
169
|
-
});
|
|
170
|
-
return this.request("/chunk/probe", options).then(createMapResponseToJson(metadata));
|
|
171
|
-
}
|
|
172
150
|
}, {
|
|
173
151
|
key: "createFileFromUpload",
|
|
174
152
|
value: function createFileFromUpload(body) {
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import { getMediaFile, normaliseInput } from './helpers';
|
|
4
|
+
var getMediaApi = function getMediaApi(_ref) {
|
|
5
|
+
var getFileItem = _ref.getFileItem;
|
|
6
|
+
return {
|
|
7
|
+
// --------------------------------------------------------
|
|
8
|
+
// UPLOAD ENDPOINTS - None is supported
|
|
9
|
+
// --------------------------------------------------------
|
|
10
|
+
|
|
11
|
+
touchFiles: function () {
|
|
12
|
+
var _touchFiles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref2) {
|
|
13
|
+
var descriptors;
|
|
14
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
15
|
+
while (1) switch (_context.prev = _context.next) {
|
|
16
|
+
case 0:
|
|
17
|
+
descriptors = _ref2.descriptors;
|
|
18
|
+
throw new Error('500 - MockedMediaApi.touchFiles: method not implemented');
|
|
19
|
+
case 2:
|
|
20
|
+
case "end":
|
|
21
|
+
return _context.stop();
|
|
22
|
+
}
|
|
23
|
+
}, _callee);
|
|
24
|
+
}));
|
|
25
|
+
function touchFiles(_x) {
|
|
26
|
+
return _touchFiles.apply(this, arguments);
|
|
27
|
+
}
|
|
28
|
+
return touchFiles;
|
|
29
|
+
}(),
|
|
30
|
+
uploadChunk: function () {
|
|
31
|
+
var _uploadChunk = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(_etag, _blob, uploadId) {
|
|
32
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
33
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
34
|
+
case 0:
|
|
35
|
+
throw new Error('500 - MockedMediaApi.uploadChunk: method not implemented');
|
|
36
|
+
case 1:
|
|
37
|
+
case "end":
|
|
38
|
+
return _context2.stop();
|
|
39
|
+
}
|
|
40
|
+
}, _callee2);
|
|
41
|
+
}));
|
|
42
|
+
function uploadChunk(_x2, _x3, _x4) {
|
|
43
|
+
return _uploadChunk.apply(this, arguments);
|
|
44
|
+
}
|
|
45
|
+
return uploadChunk;
|
|
46
|
+
}(),
|
|
47
|
+
appendChunksToUpload: function () {
|
|
48
|
+
var _appendChunksToUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
|
|
49
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
50
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
51
|
+
case 0:
|
|
52
|
+
throw new Error('500 - MockedMediaApi.appendChunksToUpload: method not implemented');
|
|
53
|
+
case 1:
|
|
54
|
+
case "end":
|
|
55
|
+
return _context3.stop();
|
|
56
|
+
}
|
|
57
|
+
}, _callee3);
|
|
58
|
+
}));
|
|
59
|
+
function appendChunksToUpload() {
|
|
60
|
+
return _appendChunksToUpload.apply(this, arguments);
|
|
61
|
+
}
|
|
62
|
+
return appendChunksToUpload;
|
|
63
|
+
}(),
|
|
64
|
+
createFileFromUpload: function () {
|
|
65
|
+
var _createFileFromUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(_ref3, _ref4) {
|
|
66
|
+
var uploadId, collection;
|
|
67
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
68
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
69
|
+
case 0:
|
|
70
|
+
uploadId = _ref3.uploadId;
|
|
71
|
+
collection = _ref4.collection;
|
|
72
|
+
throw new Error('500 - MockedMediaApi.createFileFromUpload: method not implemented');
|
|
73
|
+
case 3:
|
|
74
|
+
case "end":
|
|
75
|
+
return _context4.stop();
|
|
76
|
+
}
|
|
77
|
+
}, _callee4);
|
|
78
|
+
}));
|
|
79
|
+
function createFileFromUpload(_x5, _x6) {
|
|
80
|
+
return _createFileFromUpload.apply(this, arguments);
|
|
81
|
+
}
|
|
82
|
+
return createFileFromUpload;
|
|
83
|
+
}(),
|
|
84
|
+
// Used by Media Picker as a fallback for conflicted file Ids
|
|
85
|
+
createUpload: function () {
|
|
86
|
+
var _createUpload = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
|
|
87
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
88
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
89
|
+
case 0:
|
|
90
|
+
throw new Error('500 - MockedMediaApi.createUpload: method not implemented');
|
|
91
|
+
case 1:
|
|
92
|
+
case "end":
|
|
93
|
+
return _context5.stop();
|
|
94
|
+
}
|
|
95
|
+
}, _callee5);
|
|
96
|
+
}));
|
|
97
|
+
function createUpload() {
|
|
98
|
+
return _createUpload.apply(this, arguments);
|
|
99
|
+
}
|
|
100
|
+
return createUpload;
|
|
101
|
+
}(),
|
|
102
|
+
// For File size limits
|
|
103
|
+
getRejectedResponseFromDescriptor: function getRejectedResponseFromDescriptor() {
|
|
104
|
+
throw new Error('500 - MockedMediaApi.getRejectedResponseFromDescriptor: method not implemented');
|
|
105
|
+
},
|
|
106
|
+
// --------------------------------------------------------
|
|
107
|
+
// METADATA ENDPOINTS
|
|
108
|
+
// --------------------------------------------------------
|
|
109
|
+
|
|
110
|
+
getFile: function () {
|
|
111
|
+
var _getFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(fileId) {
|
|
112
|
+
var fileItem;
|
|
113
|
+
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
114
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
115
|
+
case 0:
|
|
116
|
+
fileItem = getFileItem(fileId);
|
|
117
|
+
if (fileItem) {
|
|
118
|
+
_context6.next = 3;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
throw new Error('404 - MockedMediaApi.getFile: file not found');
|
|
122
|
+
case 3:
|
|
123
|
+
return _context6.abrupt("return", {
|
|
124
|
+
data: getMediaFile(fileItem)
|
|
125
|
+
});
|
|
126
|
+
case 4:
|
|
127
|
+
case "end":
|
|
128
|
+
return _context6.stop();
|
|
129
|
+
}
|
|
130
|
+
}, _callee6);
|
|
131
|
+
}));
|
|
132
|
+
function getFile(_x7) {
|
|
133
|
+
return _getFile.apply(this, arguments);
|
|
134
|
+
}
|
|
135
|
+
return getFile;
|
|
136
|
+
}(),
|
|
137
|
+
getItems: function () {
|
|
138
|
+
var _getItems = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(ids) {
|
|
139
|
+
var items;
|
|
140
|
+
return _regeneratorRuntime.wrap(function _callee7$(_context7) {
|
|
141
|
+
while (1) switch (_context7.prev = _context7.next) {
|
|
142
|
+
case 0:
|
|
143
|
+
items = ids.map(function (id) {
|
|
144
|
+
return getFileItem(id);
|
|
145
|
+
}).filter(function (fileState) {
|
|
146
|
+
return !!fileState;
|
|
147
|
+
});
|
|
148
|
+
return _context7.abrupt("return", {
|
|
149
|
+
data: {
|
|
150
|
+
items: items
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
case 2:
|
|
154
|
+
case "end":
|
|
155
|
+
return _context7.stop();
|
|
156
|
+
}
|
|
157
|
+
}, _callee7);
|
|
158
|
+
}));
|
|
159
|
+
function getItems(_x8) {
|
|
160
|
+
return _getItems.apply(this, arguments);
|
|
161
|
+
}
|
|
162
|
+
return getItems;
|
|
163
|
+
}(),
|
|
164
|
+
// TODO
|
|
165
|
+
getImageMetadata: function () {
|
|
166
|
+
var _getImageMetadata = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee8() {
|
|
167
|
+
return _regeneratorRuntime.wrap(function _callee8$(_context8) {
|
|
168
|
+
while (1) switch (_context8.prev = _context8.next) {
|
|
169
|
+
case 0:
|
|
170
|
+
throw new Error('500 - MockedMediaApi.getImageMetadata: method not implemented');
|
|
171
|
+
case 1:
|
|
172
|
+
case "end":
|
|
173
|
+
return _context8.stop();
|
|
174
|
+
}
|
|
175
|
+
}, _callee8);
|
|
176
|
+
}));
|
|
177
|
+
function getImageMetadata() {
|
|
178
|
+
return _getImageMetadata.apply(this, arguments);
|
|
179
|
+
}
|
|
180
|
+
return getImageMetadata;
|
|
181
|
+
}(),
|
|
182
|
+
// --------------------------------------------------------
|
|
183
|
+
// URL ENDPOINTS
|
|
184
|
+
// --------------------------------------------------------
|
|
185
|
+
|
|
186
|
+
// TODO
|
|
187
|
+
getFileImageURL: function () {
|
|
188
|
+
var _getFileImageURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee9() {
|
|
189
|
+
return _regeneratorRuntime.wrap(function _callee9$(_context9) {
|
|
190
|
+
while (1) switch (_context9.prev = _context9.next) {
|
|
191
|
+
case 0:
|
|
192
|
+
throw new Error('500 - MockedMediaApi.getFileImageURL: method not implemented');
|
|
193
|
+
case 1:
|
|
194
|
+
case "end":
|
|
195
|
+
return _context9.stop();
|
|
196
|
+
}
|
|
197
|
+
}, _callee9);
|
|
198
|
+
}));
|
|
199
|
+
function getFileImageURL() {
|
|
200
|
+
return _getFileImageURL.apply(this, arguments);
|
|
201
|
+
}
|
|
202
|
+
return getFileImageURL;
|
|
203
|
+
}(),
|
|
204
|
+
// TODO
|
|
205
|
+
getFileImageURLSync: function getFileImageURLSync() {
|
|
206
|
+
throw new Error('500 - MockedMediaApi.getFileImageURLSync: method not implemented');
|
|
207
|
+
},
|
|
208
|
+
getFileBinaryURL: function () {
|
|
209
|
+
var _getFileBinaryURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee10(id) {
|
|
210
|
+
var fileItem;
|
|
211
|
+
return _regeneratorRuntime.wrap(function _callee10$(_context10) {
|
|
212
|
+
while (1) switch (_context10.prev = _context10.next) {
|
|
213
|
+
case 0:
|
|
214
|
+
fileItem = getFileItem(id);
|
|
215
|
+
if (fileItem) {
|
|
216
|
+
_context10.next = 3;
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
throw new Error('404 - MockedMediaApi.getFileBinaryURL: file not found');
|
|
220
|
+
case 3:
|
|
221
|
+
if (!(fileItem.details.size === 0)) {
|
|
222
|
+
_context10.next = 5;
|
|
223
|
+
break;
|
|
224
|
+
}
|
|
225
|
+
throw new Error('404 - MockedMediaApi.getFileBinaryURL: file is empty');
|
|
226
|
+
case 5:
|
|
227
|
+
return _context10.abrupt("return", "/file/".concat(id, "/binary"));
|
|
228
|
+
case 6:
|
|
229
|
+
case "end":
|
|
230
|
+
return _context10.stop();
|
|
231
|
+
}
|
|
232
|
+
}, _callee10);
|
|
233
|
+
}));
|
|
234
|
+
function getFileBinaryURL(_x9) {
|
|
235
|
+
return _getFileBinaryURL.apply(this, arguments);
|
|
236
|
+
}
|
|
237
|
+
return getFileBinaryURL;
|
|
238
|
+
}(),
|
|
239
|
+
getArtifactURL: function () {
|
|
240
|
+
var _getArtifactURL = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee11(artifacts, artifactName) {
|
|
241
|
+
var _artifacts$artifactNa;
|
|
242
|
+
var artifactUrl;
|
|
243
|
+
return _regeneratorRuntime.wrap(function _callee11$(_context11) {
|
|
244
|
+
while (1) switch (_context11.prev = _context11.next) {
|
|
245
|
+
case 0:
|
|
246
|
+
artifactUrl = (_artifacts$artifactNa = artifacts[artifactName]) === null || _artifacts$artifactNa === void 0 ? void 0 : _artifacts$artifactNa.url;
|
|
247
|
+
if (artifactUrl) {
|
|
248
|
+
_context11.next = 3;
|
|
249
|
+
break;
|
|
250
|
+
}
|
|
251
|
+
throw new Error("404 - MockedMediaApi.getArtifactURL: artifact ".concat(artifactName, " not found"));
|
|
252
|
+
case 3:
|
|
253
|
+
return _context11.abrupt("return", artifactUrl);
|
|
254
|
+
case 4:
|
|
255
|
+
case "end":
|
|
256
|
+
return _context11.stop();
|
|
257
|
+
}
|
|
258
|
+
}, _callee11);
|
|
259
|
+
}));
|
|
260
|
+
function getArtifactURL(_x10, _x11) {
|
|
261
|
+
return _getArtifactURL.apply(this, arguments);
|
|
262
|
+
}
|
|
263
|
+
return getArtifactURL;
|
|
264
|
+
}(),
|
|
265
|
+
// --------------------------------------------------------
|
|
266
|
+
// BINARY ENDPOINTS
|
|
267
|
+
// --------------------------------------------------------
|
|
268
|
+
getImage: function () {
|
|
269
|
+
var _getImage = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee12(fileId) {
|
|
270
|
+
var fileItem;
|
|
271
|
+
return _regeneratorRuntime.wrap(function _callee12$(_context12) {
|
|
272
|
+
while (1) switch (_context12.prev = _context12.next) {
|
|
273
|
+
case 0:
|
|
274
|
+
fileItem = getFileItem(fileId);
|
|
275
|
+
if (fileItem) {
|
|
276
|
+
_context12.next = 3;
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
throw new Error('404 - MockedMediaApi.getImage: file not found');
|
|
280
|
+
case 3:
|
|
281
|
+
if (fileItem.details.representations.image) {
|
|
282
|
+
_context12.next = 5;
|
|
283
|
+
break;
|
|
284
|
+
}
|
|
285
|
+
throw new Error('404 - MockedMediaApi.getImage: image not found');
|
|
286
|
+
case 5:
|
|
287
|
+
return _context12.abrupt("return", new Blob());
|
|
288
|
+
case 6:
|
|
289
|
+
case "end":
|
|
290
|
+
return _context12.stop();
|
|
291
|
+
}
|
|
292
|
+
}, _callee12);
|
|
293
|
+
}));
|
|
294
|
+
function getImage(_x12) {
|
|
295
|
+
return _getImage.apply(this, arguments);
|
|
296
|
+
}
|
|
297
|
+
return getImage;
|
|
298
|
+
}(),
|
|
299
|
+
// --------------------------------------------------------
|
|
300
|
+
// OTHER ENDPOINTS
|
|
301
|
+
// --------------------------------------------------------
|
|
302
|
+
|
|
303
|
+
// TODO
|
|
304
|
+
copyFileWithToken: function () {
|
|
305
|
+
var _copyFileWithToken = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee13(body) {
|
|
306
|
+
var fileId, fileItem;
|
|
307
|
+
return _regeneratorRuntime.wrap(function _callee13$(_context13) {
|
|
308
|
+
while (1) switch (_context13.prev = _context13.next) {
|
|
309
|
+
case 0:
|
|
310
|
+
fileId = body.sourceFile.id;
|
|
311
|
+
fileItem = getFileItem(fileId);
|
|
312
|
+
if (fileItem) {
|
|
313
|
+
_context13.next = 4;
|
|
314
|
+
break;
|
|
315
|
+
}
|
|
316
|
+
throw new Error('404 - MockedMediaApi.copyFileWithToken: file not found');
|
|
317
|
+
case 4:
|
|
318
|
+
return _context13.abrupt("return", {
|
|
319
|
+
data: getMediaFile(fileItem)
|
|
320
|
+
});
|
|
321
|
+
case 5:
|
|
322
|
+
case "end":
|
|
323
|
+
return _context13.stop();
|
|
324
|
+
}
|
|
325
|
+
}, _callee13);
|
|
326
|
+
}));
|
|
327
|
+
function copyFileWithToken(_x13) {
|
|
328
|
+
return _copyFileWithToken.apply(this, arguments);
|
|
329
|
+
}
|
|
330
|
+
return copyFileWithToken;
|
|
331
|
+
}(),
|
|
332
|
+
// TODO
|
|
333
|
+
removeCollectionFile: function () {
|
|
334
|
+
var _removeCollectionFile = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee14() {
|
|
335
|
+
return _regeneratorRuntime.wrap(function _callee14$(_context14) {
|
|
336
|
+
while (1) switch (_context14.prev = _context14.next) {
|
|
337
|
+
case 0:
|
|
338
|
+
case "end":
|
|
339
|
+
return _context14.stop();
|
|
340
|
+
}
|
|
341
|
+
}, _callee14);
|
|
342
|
+
}));
|
|
343
|
+
function removeCollectionFile() {
|
|
344
|
+
return _removeCollectionFile.apply(this, arguments);
|
|
345
|
+
}
|
|
346
|
+
return removeCollectionFile;
|
|
347
|
+
}(),
|
|
348
|
+
// --------------------------------------------------------
|
|
349
|
+
// OTHER ENDPOINTS
|
|
350
|
+
// --------------------------------------------------------
|
|
351
|
+
request: function () {
|
|
352
|
+
var _request = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee15() {
|
|
353
|
+
return _regeneratorRuntime.wrap(function _callee15$(_context15) {
|
|
354
|
+
while (1) switch (_context15.prev = _context15.next) {
|
|
355
|
+
case 0:
|
|
356
|
+
return _context15.abrupt("return", new Response());
|
|
357
|
+
case 1:
|
|
358
|
+
case "end":
|
|
359
|
+
return _context15.stop();
|
|
360
|
+
}
|
|
361
|
+
}, _callee15);
|
|
362
|
+
}));
|
|
363
|
+
function request() {
|
|
364
|
+
return _request.apply(this, arguments);
|
|
365
|
+
}
|
|
366
|
+
return request;
|
|
367
|
+
}(),
|
|
368
|
+
resolveAuth: function () {
|
|
369
|
+
var _resolveAuth = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee16() {
|
|
370
|
+
return _regeneratorRuntime.wrap(function _callee16$(_context16) {
|
|
371
|
+
while (1) switch (_context16.prev = _context16.next) {
|
|
372
|
+
case 0:
|
|
373
|
+
return _context16.abrupt("return", {
|
|
374
|
+
asapIssuer: '',
|
|
375
|
+
token: '',
|
|
376
|
+
baseUrl: ''
|
|
377
|
+
});
|
|
378
|
+
case 1:
|
|
379
|
+
case "end":
|
|
380
|
+
return _context16.stop();
|
|
381
|
+
}
|
|
382
|
+
}, _callee16);
|
|
383
|
+
}));
|
|
384
|
+
function resolveAuth() {
|
|
385
|
+
return _resolveAuth.apply(this, arguments);
|
|
386
|
+
}
|
|
387
|
+
return resolveAuth;
|
|
388
|
+
}(),
|
|
389
|
+
resolveInitialAuth: function resolveInitialAuth() {
|
|
390
|
+
return {
|
|
391
|
+
asapIssuer: '',
|
|
392
|
+
token: '',
|
|
393
|
+
baseUrl: ''
|
|
394
|
+
};
|
|
395
|
+
}
|
|
396
|
+
};
|
|
397
|
+
};
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Mocked Media API
|
|
401
|
+
*/
|
|
402
|
+
export var createMockedMediaApi = function createMockedMediaApi(initialFileItems) {
|
|
403
|
+
var storedFileItems = new Map();
|
|
404
|
+
var getFileItem = function getFileItem(fileId) {
|
|
405
|
+
return storedFileItems.get(fileId);
|
|
406
|
+
};
|
|
407
|
+
var setFileItems = function setFileItems(fileItems) {
|
|
408
|
+
var normalised = normaliseInput(fileItems);
|
|
409
|
+
normalised.forEach(function (fileItem) {
|
|
410
|
+
return storedFileItems.set(fileItem.id, fileItem);
|
|
411
|
+
});
|
|
412
|
+
};
|
|
413
|
+
if (initialFileItems) {
|
|
414
|
+
setFileItems(initialFileItems);
|
|
415
|
+
}
|
|
416
|
+
var mediaApi = getMediaApi({
|
|
417
|
+
setFileItems: setFileItems,
|
|
418
|
+
getFileItem: getFileItem
|
|
419
|
+
});
|
|
420
|
+
return {
|
|
421
|
+
setFileItems: setFileItems,
|
|
422
|
+
getFileItem: getFileItem,
|
|
423
|
+
mediaApi: mediaApi
|
|
424
|
+
};
|
|
425
|
+
};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
4
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
5
|
+
import uuid from 'uuid/v4';
|
|
6
|
+
// --------------------------------------------------------
|
|
7
|
+
// Factory Utils
|
|
8
|
+
// --------------------------------------------------------
|
|
9
|
+
export var normaliseInput = function normaliseInput(input) {
|
|
10
|
+
return !input ? [] : input instanceof Array ? input : [input];
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// --------------------------------------------------------
|
|
14
|
+
// Utils for the main class
|
|
15
|
+
// --------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
export var getMediaFile = function getMediaFile(fileItem) {
|
|
18
|
+
return _objectSpread({
|
|
19
|
+
id: fileItem.id
|
|
20
|
+
}, fileItem.details);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// --------------------------------------------------------
|
|
24
|
+
// Utils for creating file descriptors for tests
|
|
25
|
+
// --------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
export var createEmptyFileItem = function createEmptyFileItem(id, collection) {
|
|
28
|
+
var emptyFileItem = {
|
|
29
|
+
type: 'file',
|
|
30
|
+
id: id,
|
|
31
|
+
details: {
|
|
32
|
+
mediaType: 'unknown',
|
|
33
|
+
mimeType: 'binary/octet-stream',
|
|
34
|
+
name: '',
|
|
35
|
+
size: 0,
|
|
36
|
+
processingStatus: 'pending',
|
|
37
|
+
artifacts: {},
|
|
38
|
+
representations: {},
|
|
39
|
+
createdAt: 1699488941974
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
if (collection) {
|
|
43
|
+
emptyFileItem.collection = collection;
|
|
44
|
+
}
|
|
45
|
+
return emptyFileItem;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Simulates the processing of the file by updating the processing status of the artifacts by a percentage
|
|
50
|
+
* Percent must be between 0 and 1
|
|
51
|
+
*/
|
|
52
|
+
export var createProcessingFileItem = function createProcessingFileItem(fileItem, percent) {
|
|
53
|
+
if (percent < 0 || percent > 1) {
|
|
54
|
+
throw new Error('Error createProcessingFileItem: percent must be between 0 and 1');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* This behaviour has to be confirmed
|
|
59
|
+
* Artifacts show up immediately after processed or they have a
|
|
60
|
+
* "processing time"?
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
if (percent === 1) {
|
|
64
|
+
return fileItem;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// No artifacts for 0% processing
|
|
68
|
+
if (percent === 0) {
|
|
69
|
+
return _objectSpread(_objectSpread({}, fileItem), {}, {
|
|
70
|
+
details: _objectSpread(_objectSpread({}, fileItem.details), {}, {
|
|
71
|
+
processingStatus: 'pending',
|
|
72
|
+
artifacts: {},
|
|
73
|
+
// The preview will only be ready at 100% -> TODO verify against backend
|
|
74
|
+
representations: {}
|
|
75
|
+
})
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
var artifactsKeys = Object.keys(fileItem.details.artifacts);
|
|
79
|
+
var artifactsEntries = Object.entries(_objectSpread({}, fileItem.details.artifacts));
|
|
80
|
+
|
|
81
|
+
// Get a % of the total artifacts to be set as processed
|
|
82
|
+
var processedArtifactKeys = artifactsKeys.slice(0, Math.ceil(artifactsKeys.length * percent));
|
|
83
|
+
var processedArtifactEntries = artifactsEntries.map(function (_ref) {
|
|
84
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
85
|
+
key = _ref2[0],
|
|
86
|
+
artifact = _ref2[1];
|
|
87
|
+
return [key, _objectSpread(_objectSpread({}, artifact), {}, {
|
|
88
|
+
processingStatus: processedArtifactKeys.includes(key) ? 'succeeded' : 'pending'
|
|
89
|
+
})];
|
|
90
|
+
});
|
|
91
|
+
var artifactsProcessingPercent = Object.fromEntries(processedArtifactEntries);
|
|
92
|
+
return _objectSpread(_objectSpread({}, fileItem), {}, {
|
|
93
|
+
details: _objectSpread(_objectSpread({}, fileItem.details), {}, {
|
|
94
|
+
processingStatus: 'pending',
|
|
95
|
+
artifacts: artifactsProcessingPercent,
|
|
96
|
+
// The preview will only be ready at 100% -> TODO verify against backend
|
|
97
|
+
representations: {}
|
|
98
|
+
})
|
|
99
|
+
});
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Makes a copy of the provided file item with a random file id
|
|
104
|
+
* */
|
|
105
|
+
export var copy = function copy(fileItem) {
|
|
106
|
+
return JSON.parse(JSON.stringify(fileItem).replace(new RegExp(fileItem.id, 'g'), uuid()));
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Extracts the file identifier from the provided file item
|
|
110
|
+
*/
|
|
111
|
+
export var getIdentifier = function getIdentifier(fileItem) {
|
|
112
|
+
return {
|
|
113
|
+
mediaItemType: 'file',
|
|
114
|
+
id: fileItem.id,
|
|
115
|
+
collectionName: fileItem.collection
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
export var createFileState = function createFileState(_ref3) {
|
|
119
|
+
var id = _ref3.id,
|
|
120
|
+
_ref3$details = _ref3.details,
|
|
121
|
+
name = _ref3$details.name,
|
|
122
|
+
size = _ref3$details.size,
|
|
123
|
+
mediaType = _ref3$details.mediaType,
|
|
124
|
+
mimeType = _ref3$details.mimeType,
|
|
125
|
+
createdAt = _ref3$details.createdAt,
|
|
126
|
+
processingStatus = _ref3$details.processingStatus,
|
|
127
|
+
artifacts = _ref3$details.artifacts,
|
|
128
|
+
representations = _ref3$details.representations;
|
|
129
|
+
return {
|
|
130
|
+
status: processingStatus === 'succeeded' ? 'processed' : 'processing',
|
|
131
|
+
id: id,
|
|
132
|
+
name: name,
|
|
133
|
+
size: size,
|
|
134
|
+
mediaType: mediaType,
|
|
135
|
+
mimeType: mimeType,
|
|
136
|
+
createdAt: createdAt,
|
|
137
|
+
artifacts: artifacts,
|
|
138
|
+
representations: representations
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
export var createUploadingFileState = function createUploadingFileState(_ref4, progress) {
|
|
142
|
+
var id = _ref4.id,
|
|
143
|
+
_ref4$details = _ref4.details,
|
|
144
|
+
name = _ref4$details.name,
|
|
145
|
+
size = _ref4$details.size,
|
|
146
|
+
mediaType = _ref4$details.mediaType,
|
|
147
|
+
mimeType = _ref4$details.mimeType,
|
|
148
|
+
createdAt = _ref4$details.createdAt;
|
|
149
|
+
return {
|
|
150
|
+
status: 'uploading',
|
|
151
|
+
progress: progress,
|
|
152
|
+
id: id,
|
|
153
|
+
name: name,
|
|
154
|
+
size: size,
|
|
155
|
+
mediaType: mediaType,
|
|
156
|
+
mimeType: mimeType,
|
|
157
|
+
createdAt: createdAt,
|
|
158
|
+
preview: {
|
|
159
|
+
value: new Blob(['some-content'], {
|
|
160
|
+
type: mimeType
|
|
161
|
+
})
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
export var createErrorFileState = function createErrorFileState(_ref5) {
|
|
166
|
+
var id = _ref5.id;
|
|
167
|
+
return {
|
|
168
|
+
status: 'error',
|
|
169
|
+
id: id,
|
|
170
|
+
reason: 'a random error',
|
|
171
|
+
message: 'a random error message',
|
|
172
|
+
details: {
|
|
173
|
+
some: 'mocked error detail'
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
};
|
|
@@ -4,4 +4,5 @@ export { collectionNames, defaultCollectionName, defaultMediaPickerCollectionNam
|
|
|
4
4
|
export { animatedFileId, archiveFileId, atlassianLogoUrl, audioFileDetails, audioFileId, audioNoCoverFileId, bigDocFileId, docFileDetails, docFileId, emptyImageFileId, errorFileId, externalImageIdentifier, externalSmallImageIdentifier, externaBrokenlIdentifier, genericDataURI, genericFileDetails, genericFileId, gifFileId, imageFileDetails, imageFileId, largeImageFileId, largePdfFileId, noMetadataFileId, passwordProtectedPdfFileId, smallImageFileId, unknownFileDetails, unknownFileId, verticalImageFileId, videoFileDetails, videoFileId, videoHorizontalFileId, videoLargeFileId, videoProcessingFailedId, videoSquareFileId, wideImageFileId, zipFileId, zipFileWithNestedFolderId, zipItemLargeInnerFileId, zipItemMultipleFoldersAtRootId, zipJiraArchiveFileId, zipEncryptedFileId, codeFileId, emailFileId, emailUnsupportedFileId, vrVideoDetails } from './exampleMediaItems';
|
|
5
5
|
export var authProviderBaseURL = 'https://media.dev.atl-paas.net';
|
|
6
6
|
export { mediaPickerAuthProvider, defaultMediaPickerAuthProvider } from './mediaPickerAuthProvider';
|
|
7
|
-
export { fakeMediaClient } from './fakeMediaClient';
|
|
7
|
+
export { fakeMediaClient } from './fakeMediaClient';
|
|
8
|
+
export { createMockedMediaApi, copy, getIdentifier, createProcessingFileItem, createEmptyFileItem, createUploadingFileState, createFileState, createErrorFileState } from './MockedMediaApi';
|